This post describes how to use Ffmpeg directly in browser, and use native commands. Ffmpeg loads web assembly script in browser, and gives APIs that we can consume.
FFmpeg is a free and open-source software project consisting of a large suite of libraries and programs for handling video, audio, and other multimedia files and streams.
# Use npm
npm install @ffmpeg/ffmpeg
# Use yarn
yarn add @ffmpeg/ffmpeg
or you can use CDN directly, read more on https://ffmpegwasm.github.io/#demo
const { createFFmpeg, fetchFile } = FFmpeg
const ffmpeg = createFFmpeg({ log: true })
await ffmpeg.load()
// ffmpeg.FS(method, ...args)
// Write file using below command
ffmpeg.FS('writeFile', 'test.mp4', await fetchFile(this.video))
// Read file (already available in FS memory)
ffmpeg.FS('readFile', 'out.gif')
await ffmpeg.run(
'-i',
'test.mp4',
'-t',
'5',
'-ss',
'5',
'-f',
'gif',
'out.gif'
)
// -t ==> total time of gif
// -ss ⇒ starting seconds or offset
Read more on ffmpeg commands on https://ffmpeg.org/ffmpeg.html
I found ffmpeg-wasm was really helpful, I have explored just one use case, that's like exploring tip of iceberg. I will try out more use cases and keep updating in my GitHub repo. https://github.com/ssghait007/ffmpeg-wasm-poc