ffmpeg
One of my favorite pieces of software. I always enjoy solving problems with ffmpeg, no matter how annoying they could be.
Resources
- https://trac.ffmpeg.org/wiki
- This is a good start
- https://ffmpeg.org/documentation.html
- Valuable resource once you start to get the basics of how the ffmpeg cli works.
Some Notes
Some ffmpeg options are just aliases, and thus do the same thing. I use the specific aliases in the examples either out of habit or they are easier to type. The aliases don't have to be used. A couple of examples are
-vcodec
is an alias for-codec:v
.-acodec
is an alias for-codec:a
-vf
is an alias for-filter:v
.-af
is an alias for-filter:a
However some aliases are obsolete and should not be used. An example is -vframes
, which should not be used and -frames:v
should be used instead.
Tricks
Simple way to disable audio
Disable audio with -an
. Useful for reducing file size when audio is not needed, like for setting a video wallpaper as a desktop background.
ffmpeg -i in.mp4 -c copy -an out.mp4
Resources:
Scale a Video
ffmpeg -i in.mp4 -vf "scale:-1:1080" -vcodec libx264 -acodec copy out.mp4
The -1
will automatically choose a value such that it preserves the input video aspect ratio.
Alternatively, you can use -s
as an output option, which will place the scale
filter at the end of the filtergraph. I personally prefer placing the scale
filter in manually.
ffmpeg -i in.mp4 -vcodec libx264 -acodec copy -s 1920x1080 out.mp4
References:
- https://trac.ffmpeg.org/wiki/Scaling
- https://ffmpeg.org/ffmpeg-filters.html#scale-1
- https://ffmpeg.org/ffmpeg-scaler.html#scaler_005foptions
- https://ffmpeg.org/ffmpeg.html#Video-Options
Mute sections of a video
# This mutes the audio from 0 seconds to 10 seconds and
# from 20 seconds to 30 seconds
ffmpeg -i in.mp4 \
-af "volume=0:enable='between(t, 0, 10)', volume=0:enable='between(t, 20, 30)'" \
-vcodec libx264 \
-acodec aac \
out.mp4
References: