A list of ffmpeg commands that I frequently use or that I spent a long time finding out.
Info
The below commands can be generally combined together. Video filters need to be concatenated with comma if multiple are used together, but order matters, especially if it is complex.1
Here is a list of my combined commands:
- For combining time lapse videos, downsampling them and removing duplicate frames:
Concatenate videos
Generally I concatenate videos with same resolution and codec (h264 generally), so I just following this method:2
Downsample videos
Downsampling videos (from 4K) to 1080p:3
Downsampling videos to 720p:
Drop duplicate frames
Useful to drop duplicate frames in time-lapse videos where nothing is going on.4
The tricky part is to estimate the hi & low values.
My way of figuring out the hi value is to save a screenshot of video frame using mpv or vlc. The resolution of the screenshot will be the same. I will estimate the number of pixels that are changing (generally a timestamp) and then use that for the hi value.
The low value is generally half or 1/3 of the hi value. And I keep the frac at 0.33 (or 0.25)
ffmpeg docs on hi, low and frac values:
Values for hi and lo are for 8x8 pixel blocks and represent actual pixel value differences, so a threshold of 64 corresponds to 1 unit of difference for each pixel, or the same spread out differently over the block.
A frame is a candidate for dropping if no 8x8 blocks differ by more than a threshold of hi, and if no more than frac blocks (1 meaning the whole image) differ by more than a threshold of lo.
Default value for hi is 64*12, default value for lo is 64*5, and default value for frac is 0.33.
Trim videos
Footnotes
-
https://superuser.com/questions/1435505/does-it-matter-how-you-order-your-filtergraph-in-ffmpeg ↩
-
https://stackoverflow.com/questions/7333232/how-to-concatenate-two-mp4-files-using-ffmpeg ↩
-
https://video.stackexchange.com/questions/14907/how-to-downsample-4k-to-1080p-using-ffmpeg-while-maintaining-the-quality ↩
-
https://stackoverflow.com/questions/37088517/remove-sequentially-duplicate-frames-when-using-ffmpeg/67322549#67322549 ↩