FFMpeg Useful Commands. [Constantly Updating]
FFMpeg is primarily a transcoder. It supports practically all audio/video codecs/containers as well as elementary stream formats in the market. It provides a host of audio filters (eg: resampling, downmix channels) and video filters (eg: crop, pad, etc) to use during transcoding.
First:
ffmpeg -h
1, To convert a regular mp4 video into raw videos, such as a .yuv file.
ffmpeg -i ABC.mp4 ABC.yuv
2, To find out supported pixel formats.
ffmpeg -pix_fmts
3, To Convert a 720x480 nv12 (yuv 420 semi-planar) image to png
ffmpeg -s 176X144 -pix_fmt nv12 -i ABC.yuv -f image2 -pix_fmt rgb24 ABC.png
4, To cut the clip for certain duration[HH:MM:SS.xxx]
ffmpeg -i ABC.wmv -ss 01:01:30.0 -c copy -t 00:00:01.0 ABCout.wmv
ffmpeg -i ABC.wmv -ss 30 -c copy -t 10 ABCout.wmv
5, To convert an YUV file to BMP
ffmpeg -s 144x176 -pix_fmt yuv420p -i ABC.yuv ABC.bmp
ffmpeg -s 320x240 -pix_fmt nv12 -i ABC_nv12.yuv -s 320x240 -pix_fmt yuv420p ABC_yuv420p.yuv
6, Extracting YUV:
ffmpeg -i <inputFile> -vcodec rawvideo <output.yuv>
7, Resizing YUV:
ffmpeg -s 320x240 -i <input_320x240.yuv> -s 640x480 <output_640x480.yuv>
8, Controlling number of frames to process:
ffmpeg -vframes 100 <inputInfo> -i <inputFile> <encodeOptions> <outputFile>
Note:
-t is an output option and always needs to be specified after -i.
-to instead of -t to specify the timestamp to which you want to cut.
-ss after -i, you get more accurate seeking at the expense of a slower execution altogether.
See also:
Seeking with FFmpeg – FFmpeg List of supported containers:
ffmpeg -formats
List of supported codecs:
ffmpeg -codecs
Get codec information for a file:
ffmpeg -i <inputFile>
List of supported pixel formats:
ffmpeg -pix_fmts
Giving start offsets while processing:
ffmpeg -ss HH:MM:SS -i <input> -vcodec copy <output>
"-ss" sets offset in seconds.
"-r <val>" can be used to change the fps.
Extracting elementary streams:Identify required elementary stream format from supported formats using: ffmpeg -formats
To extract:
ffmpeg -i <input> -vcodec copy -f <format> <output.format>
Example 1: Extracting elementary H.264 from an AVI
ffmpeg -formats gives "format = h264"
ffmpeg -i input.avi -vcodec copy -vbsf h264_mp4toannexb -f h264 output.h264
Example 2: Extracting elementary MPEG4 from an AVI
ffmpeg -formats gives "format = m4v"
ffmpeg -i input.avi -vcodec copy -f m4v output.m4v
Get bmp/png/jpg for frames:
ffmpeg -ss 00:10:00 -vframes 10 -i <inputFile> output.bmp
This will dump bitmaps for ten frames from the time stamp 00:10:00 into files name output01.bmp, output02.bmp and so on....
You can get .png, .jpg, .gif similarly.
Note that lossy codecs like jpeg will involve re-encoding and loss in quality. You can add "qmax=10" or any appropriate value to control the quality.
Hack: To handle raw YUV similarly, rename all yuv to bmp. Specify -vcodec rawvideo, -s wxh and -pix_fmt yuv420p before -i filename.
Filters:
The following applies to all codecs/YUVs/elementary streams/containers as long as the resultant data is supported by the same.
Video Cropping:
Newer versions:
ffmpeg -i input_320x240.avi -vf crop=<w>:<h>:<x>:<y> output_300x220.avi
w = Output width
h = Output height
x = X co-ordinate of output image in the input image
y = Y co-ordinate of output image in the input image
Video Padding:
<RRGGBB[AA]> is in HEX. FF0000 = RED, 0000FF = BLUE, etc...
Newer versions:
ffmpeg -i input_320x240.avi -vf pad=<w>:<h>:<x>:<y>:<c> output_340x260.avi
w = Output width
h = Output height
x = X co-ordinate of input image in the output image
y = Y co-ordinate of input image in the output image
c = Padding color in <RRGGBB[AA]> format. FF0000 = RED, 0000FF = BLUE, etc...
Also see
Encoding using FFMpeg