npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ffmpeg-simplified

v1.1.1

Published

A wrapper around ffmpeg to achieve tasks via simple APIs.

Downloads

382

Readme

wakatime Node.js CI GitHub License GitHub Release codecov Size typescript npm npm GitHub issues GitHub stars

Code Smells Coverage Lines of Code Quality Gate Status Bugs Reliability Rating Security Rating Technical Debt Maintainability Rating Vulnerabilities

ffmpeg-simplified

ffmpeg-simplified is a simple wrapper around ffmpeg designed to simplify common audio and video processing tasks through easy-to-use APIs.

Installation

To install ffmpeg-simplified, use npm or yarn:

npm install ffmpeg-simplified
# or
yarn add ffmpeg-simplified
# or
pnpm i ffmpeg-simplified

Requirements

Node.js >= 20.0.0

Ensure you have ffmpeg installed. If not, you can use the ffmpeg-static package, which is already included as a dependency.

Usage

The SDK provides several functions to interact with the turath.io API. Below are the main functions that you can use:

Importing the SDK

import {
  sliceAndMerge,
  slice,
  mergeSlices,
  splitFileOnSilences,
  replaceAudio,
  formatMedia,
  detectSilences,
  getMediaDuration,
} from "ffmpeg-simplified";

detectSilences

Detects silences in an audio file based on specified threshold and duration.

const silences = await detectSilences("audio.mp3", {
  silenceDuration: 0.5,
  silenceThreshold: -50,
});

Parameters:

  • filePath (string): Path to the input audio file.
  • options (SilenceDetectionOptions): Silence detection options.

Returns:

  • Promise<TimeRange[]>: Array of time ranges where silence was detected.

formatMedia

Preprocesses a media file with options like noise reduction and format conversion.

await formatMedia("input.wav", "./output", {
  noiseReduction: {
    highpass: 200,
    lowpass: 3000,
    dialogueEnhance: true,
  },
});

Parameters:

  • input (Readable | string): Input stream or file path.
  • outputDir (string): Directory where the processed file will be saved.
  • options (PreprocessOptions, optional): Preprocessing options.
  • callbacks (PreprocessingCallbacks, optional): Callback functions for progress tracking.

Returns:

  • Promise: Path to the processed media file.

getMediaDuration

Retrieves the duration of a media file in seconds.

const duration = await getMediaDuration("video.mp4");
console.log(`Duration: ${duration} seconds`);

Parameters:

  • filePath (string): Path to the media file.

Returns:

Promise: Duration of the media file in seconds.

mergeSlices

Merges multiple media files into a single file.

await mergeSlices(["slice1.mp4", "slice2.mp4"], "mergedOutput.mp4");

Parameters:

  • inputFiles (string[]): Array of media file paths to merge.
  • outputFile (string): Path where the merged file will be saved.

Returns:

  • Promise: Path to the merged output file.

replaceAudio

Replaces the audio track of a video file with a new audio file.

await replaceAudio("video.mp4", "newAudio.mp3", "outputVideo.mp4");

Parameters:

  • videoFile (string): Path to the input video file.
  • audioFile (string): Path to the new audio file.
  • outputFile (string): Path where the output video will be saved.

Returns:

Promise: Path to the output video file.

slice

Slices a media file into multiple parts based on specified time ranges.

const slices = await slice("input.mp4", {
  ranges: [
    { start: 0, end: 60 },
    { start: 120, end: 180 },
  ],
  outputFolder: "./slices",
});

console.log(slices); // ["./slices/input_0.mp4", "./slices/input_1.mp4"]

Parameters:

  • file (string): Path to the input media file.
  • options (SliceOptions): Options containing the time ranges and output folder.

Returns:

  • Promise<string[]>: Array of paths to the sliced files.

sliceAndMerge

Slices a media file based on specified time ranges and merges the slices into a single file.

await sliceAndMerge("input.mp4", "output.mp4", {
  ranges: [
    { start: 0, end: 60 },
    { start: 120, end: 180 },
  ],
});

Parameters:

  • inputFile (string): Path to the input media file.
  • outputFile (string): Path where the output file will be saved.
  • options (SliceAndMergeOptions): Options containing the time ranges.

Returns:

  • Promise: Path to the merged output file.

splitFileOnSilences

Splits an audio file into chunks based on silence detection.

const chunks = await splitFileOnSilences("audio.mp3", "./chunks", {
  chunkDuration: 60,
  silenceDetection: {
    silenceDuration: 0.5,
    silenceThreshold: -50,
  },
});

Parameters:

  • filePath (string): Path to the input audio file.
  • outputDir (string): Directory where the chunks will be saved.
  • options (SplitOptions, optional): Split options.
  • callbacks (SplitOnSilenceCallbacks, optional): Callback functions for progress tracking.

Returns:

  • Promise<AudioChunk[]>: Array of audio chunks with file names and time ranges.

Contributing

If you'd like to contribute to the SDK, feel free to fork the repository and submit a pull request. Contributions are welcome!

License

This SDK is licensed under the MIT License.