This is an old revision of the document!
Table of Contents
FFmpeg
Use
Some examples I use.
Converting
Most of the time I just use—
ffmpeg -i input.ext output.ext
—and it usually works fine leaving it to just use defaults.
Multiple
For doing a whole directory I use this one-liner I got from Stack Exchange.
for i in *.ext; do ffmpeg -i "$i" "${i%.*}.ext"; done
You can use the wildcard *
in the file extension to, so if you've got a mix of .mkv and .mp4 files from Youtube you can do. say:
for i in *.m*; do ffmpeg -i "$i" "${i%.*}.ogv"; done
If you want to put the new videos into a subdirectory, first create it, then simply add it to the output part:
for i in *.ext; do ffmpeg -i "$i" "directory/${i%.*}.ext"; done
Editing
Concatenation
The main thing I use FFmpeg for is just stitching videos together. I make a list of the files inside a text document, each line looks like this:—
file '[file location]'
—then point FFmpeg at that and give the command and it runs through them all. Nice and easy.
ffmpeg -f concat -safe 0 -i "inputfile.txt" -c copy "inputfile.ext"
※ Todo: use bash to generate the file list
Remove Audio
Add -an
to your command.
Rotation
Rotate 90°.
ffmpeg -i inputfile.ext -vf "transpose=1" outputfile.ext
Trimming
You can pretty easily make a video file smaller. The only caveat is that if you don't want to re-encode you're limited by where keyframes are placed.
ffmpeg -i inputfile.ext -ss HH:MM:SS -to HH:MM:SS -c copy outputfile.ext
-ss
is the point you want it to start-to
is the point you want it to end-t
is the length you want it to run from the start time- Instead of using the format
HH:MM:SS
you can just give a number of seconds.- You can also add milliseconds to either of those formats.
- Leaving out the
-ss
or-to
|t
will use the file's existing start or end time. - If you leave out the
-c copy
it will re-encode the video
Lowering the file size
Slow, but compresses better:
-preset veryslow
Bitrate
Dimensions
Scales 50%
ffmpeg -i "inputfile.ext" -vf "scale=iw/2:ih/2" "outputfile.ext"
Scales to set pixel dimensions (replace 'width' and 'height'):
ffmpeg -i "inputfile.ext" -vf scale=width:height "outputfile".ext