Some useful ffmpeg commands

Extracting images from a video file using ffmpeg:

Extract single frame at 10th second (ffmpeg uses HH:MM:SS:sss format) of the video:

$ ffmpeg -i input.avi -r 1 -ss 00:00:10.000 -f image2 output_%05d.png

Extract a frame every 2 seconds of the video:

$ ffmepg -i input.avi -r 0.5 -f image2 output_%05d.png

Extract all frames from the input video:

$ ffmpeg -i input.avi -f image2 output_%05d.png

To combine images into a video file (avi container with HuffYUV encoding with 30 fps for this example).
One thing to not here is ffmpeg assumes the input frame rate is 25 by default and does not put all the frames inside the output video. To overcome this, we’ve defined frame rate of the input images as 1 explicitly:

$ ffmpeg -f image2 -r 1 -i input_%05d.png -vcodec huffyuv -r 30 output.avi

HuffYUV converts to YUV4:2:0 pixel format by default. Given png images as an input, HuffYUV converts RGB into YUV4:2:0 causing some loss. It is necessary to define the pixel format using -pix_fmt for completely lossless compression. A better version of the previous command is:

$ ffmpeg -f image2 -r 1 -i input_%05d.png -vcodec huffyuv -pix_fmt bgra -r 30 output.avi

However recently I realized this is causing the colors of the input images look washed out in the output video. I couldn’t figure out what is causing this yet. Until then, it is always possible to not compress the output video:

$ ffmpeg -f image2 -r 1 -i input_%05d.png -vcodec rawvideo -pix_fmt bgra -r 30 output.avi

Main options of FFMPEG Command:

-h : Show complete help when using in command prompt.
-i : Input file name on which ffmpeg commands operates.
-y: Owerrite output file normally used in grabbing thumbnails from input source.
-t: Set the recording time in seconds. hh:mm:ss.
-fs: Limit the size of output file.
-ss: Seek to given time position in seconds. hh:mm:ss.
-title : set the title on the source.
-author: set the author information on the source.
-copyright: set the copy right information on the source.
-target : Specify target file type (“vcd”, “svcd”, “dvd”, “dv”, “dv50″, “pal-vcd”, “ntsc-svcd”, … ). All the format options (bitrate, codecs, buffer sizes) are then set automatically. You can just type:

Leave a Reply

You must be logged in to post a comment.