Lichendust

I'm Harley, an artist, animator and programmer.
I make all kinds of useless stuff.

ffmpeg

🌱
🎥
Scripts and snippets for cutting videos
CONTENTS

Setting Up

You should know that a lot of other programs bundle copies of ffmpeg when they're distributed, most notably ImageMagick, Blender and most video editors.

So don't do what I did and fail to check whether your actual ffmpeg installation has path priority over one of these other versions. I discovered recently to my horror that I had been using a five year old version of it thanks to an ImageMagick choco upgrade bumping its path priority above ffmpeg, which caused all kinds of head-scratchers as I tried to work out why a program I hadn't updated in six months was now refusing commands I'd been running every single day.

Making GIFs

ffmpeg -i file.mp4 -vf "fps=12,scale=680:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" out.gif

This generates relatively small GIF files but the choice of 680 for the width will naturally produce something quite large. The second value of the scale as -1 ensures the aspect ratio is preserved.

Using the trimming controls, you can also specify the section of the video you want.

ffmpeg -i file.mp4 -ss 02:05 -t 6 -vf "fps=12,scale=680:-1:flags=lanczos,split[s0][s1];[s0]palettegen[p];[s1][p]paletteuse" out.gif

This creates a GIF that starts at 2 minutes and 5 seconds and lasts 6 seconds.

Random Things

Trimming a file

-ss 00:00:05
-to 00:00:10
-t 8

The first two represent fixed time timestamps in the input video, like slicing out the footage between two markers. You can omit -ss and just use -to if you're wanting to cut the video short and vice-versa if you're just trimming air from the front. -t simply sets a length in seconds from the start time for relative trimming.

ffmpeg -i input.mp4 -ss 01:19:27 -to 02:18:51 -c copy output.mp4

Remove a chunk from the middle of video

ffmpeg -i input.mp4 -vf "select='not(between(t,9,20))', setpts=N/FRAME_RATE/TB" -af "aselect='not(between(t,9,20))', asetpts=N/SR/TB" output.mp4

The setpts/asetpts filters set the timestamps on each frame to the correct values so that playback doesn't skip.

Remove Audio

ffmpeg -i input.mp4 -c copy -an output.mp4

Copy with a new stream as the main one

ffmpeg -i input.mp4 -map 0:v:0 -map 0:a:1 -vf "scale=1920x1080" output.mp4

Set metadata field

ffmpeg -i input.mp4 -metadata title="New Title" -codec copy output.mp4

DNxHR Encoding

ffmpeg -c:v dnxhd -profile:v dnxhr_444 -pix_fmt yuv444p10le
QualityPixel EncodingBit DepthProfilePixel Format
Low Bandwidth4:2:28dnxhr_lbyuv422p
Standard4:2:28dnxhr_sqyuv422p
High4:2:28dnxhr_hqyuv422p
High4:2:210dnxhr_hqxyuv422p10le
Finishing4:4:410dnxhr_444yuv444p10le

Your profile must match your pixel format as per this table, otherwise you'll get errors.

De-interlacing DVDs

These commands de-interlace .vob files into DNxHR files (see settings above).

ffmpeg -y -hide_banner -loglevel warning -i orig/disc_c.vob -vf bwdif -c:v dnxhd -profile:v dnxhr_sq -pix_fmt yuv422p -an trans/disc_c.mov

DVD de-interlacing can use a number of different filters —

yadif      # very fast
yadif_cuda # experiment with this, because it usually doesn't work
bwdif      # seemingly better quality than yadif, though hard to perceive
nnedi      # seemingly the best, but doesn't work without additional libraries

You also need to encode the audio correctly —

ffmpeg -i input.vob -vf yadif -c:v libx264 -preset slow -crf 19 -c:a aac -b:a 256k output.mp4
WORD COUNT
539
LAST UPDATED
2025-12-27
BACKLINKS

Uses