npm

ffmpeg-progress
TypeScript icon, indicating that this package has built-in type declarations

1.0.2 • Public • Published

ffmpeg-progress

Extract progress from ffmpeg child_process output stream

npm Package Version

Installation

npm install ffmpeg-progress

Usage Example

Get video duration:

import { scanVideo } from 'ffmpeg-progress'

console.log(await scanVideo('test/in.mp4'))
// { duration: '00:52:04.78', seconds: 3124.78 }

Convert video and monitor progress:

import { startTimer } from '@beenotung/tslib/timer'
import { convertFile, parseToSeconds } from 'ffmpeg-progress'

let timer = startTimer('estimate duration')
await convertFile({
  inFile: 'test/in.mp4',
  outFile: 'test/out.mp4',
  onDuration(duration) {
    timer.next('convert video')
    timer.setEstimateProgress(parseToSeconds(duration))
  },
  onProgress(args) {
    timer.tick(args.deltaSeconds)
  },
})
timer.end()

Typescript Types

import { ChildProcessWithoutNullStreams } from 'child_process'

export function parseToSeconds(str: string): number

export function scanVideo(file: string): Promise<ScanVideoResult>

export type ScanVideoResult = {
  duration: string
  seconds: number
}

export type ProgressArgs = {
  onData?: (chunk: Buffer) => void
  onDuration?: (duration: string) => void
  onTime?: (time: string) => void
  onProgress?: (args: OnProgressArgs) => void
}

export type OnProgressArgs = {
  deltaSeconds: number
  currentSeconds: number
  totalSeconds: number
  time: string
  duration: string
  abort: () => void
}

export function convertFile(
  args: {
    inFile: string
    outFile: string
  } & ProgressArgs,
): Promise<void>

export function attachChildProcess(
  args: {
    childProcess: ChildProcessWithoutNullStreams
  } & ProgressArgs,
): Promise<void>

License

This project is licensed with BSD-2-Clause

This is free, libre, and open-source software. It comes down to four essential freedoms [ref]:

  • The freedom to run the program as you wish, for any purpose
  • The freedom to study how the program works, and change it so it does your computing as you wish
  • The freedom to redistribute copies so you can help others
  • The freedom to distribute copies of your modified versions to others

Package Sidebar

Install

npm i ffmpeg-progress

Weekly Downloads

1

Version

1.0.2

License

BSD-2-Clause

Unpacked Size

9.31 kB

Total Files

5

Last publish

Collaborators

  • beenotung