2.0.0 • Published 5 months ago

ffmpeg-simplified v2.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
5 months ago

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.

2.0.0

5 months ago

1.1.1

8 months ago

1.1.0

8 months ago

1.0.0

8 months ago