This is a simple FFmpeg library wrapper (requires ffmpeg
to be installed).
The core is an FFmpeg class with methods which have names similar or identical to existing library arguments. On top of that there's also validation and typing included.
If we'd want to rotate a video 90 degrees using 2 threads with the veryfast preset while also adding some metadata and we'd have FFmpeg installed and in the path
import { ffmpeg } from "https://deno.land/x/dffmpeg/mod.ts"
// you can also import the class directly and create a new
// instance of it
const process = ffmpeg()
.input("big_buck_bunny.mp4")
.threads(2)
.preset("veryfast")
.rotate(1)
.metadata({ title: "Title", author: "John Doe" })
.overwrite() // overwrite any existing output files
.output("output.mp4")
await process.run()
Remember to use methods in the same order you would use arguments when running ffmpeg from the command line! For example if you use a format method before an input method it will apply to that input if you add it after the last input it will apply to the output.
Here's a list of all currently available methods (with example inputs). If there's a method missing feel free to create an issue of a PR on GitHub-
execPath()
- Pass a custom location of the ffmpeg binaryinput()
- Add an inputoutput()
- Add an outputformat()
- Set formatvideoCodec()
- Set video codecaudioCodec()
- Set audio codecvideoBitrate()
- Set video bitrateaudioBitrate()
- Set audio bitrateframeRate()
- Set frameRatebufsize()
- Set buffer sizepreset()
- Set presetcrf()
- Set Constant Rate Factorstrict("experimental")
- Set stricterrDetect("ignore_err")
- Set error detection levelmap("1:3")
- "Designate one or more input streams as a source for the output file"threads(4)
- Set the amount of threads to usebanner()
- Show the banner (hidden by default)copy()
- Just copy the input video and audio encodingcopyVideo()
- Just copy the input video encodingcopyAudio()
- Just copy the input audio encodingrotate(2)
orrotate("clock")
- Set rotate leveltune("film")
- Set tunedeinterlace()
- DeinterlaceremoveAudio()
- Completely remove the audio trackremoveVideo()
- Extract the audio onlyoverwrite()
- Overwrite any existing output filesmetadata({ title: "Title", author: "John Doe" })
- Add metadatamaxRate("2M")
- Set a limited bitrategop(30)
- Use a 2 second Group of Pictures (framerate * 2)videoSize()
- Set video sizetimeOffset(60)
- Add a time offset (in seconds)copyCodec()
- Copy the input codecduration()
- Limit the max time durationscale(1080, 1920)
- Scale the inputshortest()
- Finish the encoding when the shortest clip ends.pixelFormat("yuv420p")
- Set a custom pixel formataudioChannels(2)
- Set a custom number of audio channelsfilterComplex("...")
- Add a custom complex filterloop()
orloop(3)
- Loop an imagestreamLoop()
- Loop the inputnativeSourceFrameRate()
- Use the native frame rate of the sourceflags("+flag_name")
- Add a flag