ffmpeg tutorial and examples
Cross-platform, powerful, fast and often the backend for many other gui driven conversion programs. It will require a little effort to install and learn how to use, but that effort is well worth it.
FFmpeg can be used to:
Make video from an image sequence.
Make an image sequence from a video.
Convert to and from many different video codecs and containers.
Compress videos for youtube.
ffmpeg Installation:
You can download the binaries from the ffmpeg page. Or you can do as I do on a mac and install ffmpeg via macports. Which is better?, I cannot say for sure. At the time of writing macports had the later version and the binaries linked to from the ffmpeg page seemed to have more compile-time options enabled.
For the most part the advanced compile-time options are not used on this site. WTF are compile-time options? Honestly don't worry about it. Installing ffmpeg via macports is a much longer and involved process, however you will find macports very useful.
The above link has everything you need, it is a long process and xcode is a requirement.
Once macports is installed open a terminal and..
sudo port install ffmpeg
This will take a while because it downloads source and builds each of the other bits of code and tools that ffmpeg requires to function. Be patient, and if you have to stop the process for any reason it is smart enough not to have to start from the beginning again.
Further reading.
Really good page on the ffmpeg wiki how it relates to production use and codecs. https://trac.ffmpeg.org/wiki/Encode/VFX
Apples official prores paper: https://www.apple.com/final-cut-pro/docs/Apple_ProRes_White_Paper.pdf
Basic tutorial.
I know how to use the command line, now show me the examples.
Using ffmpeg to make a movie from an image sequence. Really great for timelapses.
FFmpeg is very good at this task, it can also crop and rescale your footage.
Make a movie (prores) out of an image sequence ready for FCPX import:
ffmpeg -r 30 -f image2 -start_number 1 -i IMG_%04d.jpg -codec:v prores -profile:v 2
output.mov
-r 30
is the frame rate
variation on the above resizing the image to width 1920 and rotating it 180 degrees.
ffmpeg -r 30 -f image2 -start_number 2786 -i IMG_%04d.JPG -vf
hflip,vflip,scale=1920:-1 -codec:v prores -profile:v 2 bannanasky_deflickered.mov
Cropping with the -vf options.
-vf "crop=640:480:200:100"
Size 640x480, 200,100 (x,y) top left corner measured from top left of source.
More complicated.
Say our camera outputs frames of 5184x3456.
1080p is 16:9 ratio. 1920/1080 = 16/9
Height of this image to get 16:9 ratio: 5184*9/16 = 2916
So that will be (3456-2916)/2 = 270
pixels off the top and bottom.
Hence our crop settings for ffmpeg: -vf crop=5184:2916:0:270
We can also scale at the same time to 1920x1080 -vf crop=5184:2916:0:270,scale=1920:-1
ffmpeg -r 30 -f image2 -start_number 1230 -i IMG_%04d.jpg -vf crop=5184:2916:0:270,scale=1920:-1 -codec:v prores -profile:v 2 ../12mm_rio_verder_longest.mov
-t can also be used to limit the length of the outputgenerated from an image sequence. (useful to test crops and compression options). For instance just make the first two seconds and 10 frames..
ffmpeg -r 30 -f image2 -start_number 1230 -i IMG_%04d.jpg -t 0:0:2 -vf crop=5184:2916:0:270,scale=1920:-1 -codec:v prores -profile:v 2 ../12mm_rio_verder_preview.mov
other ffmpeg Examples
Create a high quality jpg image sequence from a movie.
ffmpeg -i input.mov -an -f image2 -qscale:v 2 ffmpeg_gen_%06d.jpg
Uncompressed raw video, (great for registax).
Crop in time as well if you like:
ffmpeg -ss 15 -i MVI_7467.MOV -t 10 -vf "crop=1000:640:600:164" -vcodec rawvideo -an MVI_7467_s.avi
-ss is the start time in seconds and -t is the duration.
Batch convert a bunch of *.MOV files to raw.
for i in *.MOV
do
ffmpeg -i $i \
-acodec none \
-vcodec rawvideo \
$(echo $i | sed 's/\.MOV$//').avi
done
Batch convert a bunch of *.MOV files to prores.
for i in *.MOV
do
ffmpeg -i $i \
-acodec none \
-vcodec prores -profile:v 2 \
$(echo $i | sed 's/\.MOV$//').avi
done
Compress (for youtube).
ffmpeg -i input.mov -c:v libx264 -preset slow -crf 18 -c:a copy -pix_fmt yuv420p output.mkv
Sane range for -crf
18-28, higher is higher compression.
Join video files together, concatenate.
https://trac.ffmpeg.org/wiki/Concatenate
for f in ./*.MOV; do echo "file '$f'" >> movlist.txt; done
ffmpeg -f concat -safe 0 -i movlist.txt -c copy output.MOV
more