Typical FFmpeg Usage¶
Lossless Transcoding¶
ffmpeg -i <input video> -vcodec copy -acodec copy -o <output video>
ffmpeg -i <input video> -c:v copy -c:a copy -o <output video>
ffmpeg -i <input video> -c copy -o <output video>
Lossless Transformations¶
Vertically Flip Video¶
ffmpeg -i <input video> -vf vflip -c:a copy <output video>
Horizontally Flip Video¶
ffmpeg -i <input video> -vf hflip -c:a copy <output video>
Rotate Video by \(90^\circ\) Clockwise¶
ffmpeg -i <input video> -vf transpose=1 -c:a copy <output video>
Rotate Video by \(90^\circ\) Counterclockwise¶
ffmpeg -i <input video> -vf transpose=2 -c:a copy <output video>
Cropping¶
ffmpeg -i <input video> -filter:v "crop=out_w:out_h:x:y" -c:a copy -o <output video>
Extract Left Half of Video¶
ffmpeg -i <input video> -filter:v "crop=in_w/2:in_h:0:0" -c:a copy -o <output video>
Extract Right Half of Video¶
ffmpeg -i <input video> -filter:v "crop=in_w/2:in_h:in_w/2:0" -c:a copy -o <output video>
Extract Top Half of Video¶
ffmpeg -i <input video> -filter:v "crop=in_w:in_h/2:0:0" -c:a copy -o <output video>
Extract Bottom Half of Video¶
ffmpeg -i <input video> -filter:v "crop=in_w:in_h/2:0:in_h/2" -c:a copy -o <output video>
Video to OpenGL/Vulkan Compatible Raw Data¶
ffmpeg -ss <hh:mm:ss> -i <input video> -f rawvideo -pix_fmt <pixel format> -vframes <n frames to save> <output video>
ffmpeg -start_number <start with frame n> -i <input video> -f rawvideo -pix_fmt <pixel format> <output video>
I420 or IYUV¶
ffmpeg -i <input video> -f rawvideo -pix_fmt yuv420p <output video>
This format is guaranteed to work on Android and iOS. A related format is YV12, which reverses the U and V plane order.
Raw Data to Video¶
ffmpeg -f rawvideo -s <width>x<height> -pix_fmt <pixel format> -i <input video> <output video>
ffmpeg -f rawvideo -s <width>x<height> -pix_fmt <pixel format> -i <input video> -c:v <encoder> <output video>
Miscellanea¶
Image to video operations, video to image operations, concatenating videos, and video mosaics are other operations supported by FFmpeg. Desktop screen capture is also supported, but SimpleScreenRecorder is much easier to use alternative.
Stack Images Horizontally¶
convert +append <input images> <output image>
Stack Images Vertically¶
convert -append <input images> <output image>
Tile Images¶
montage -mode concatenate -tile <col>x<row> <list images> <output image>
montage -mode concatenate -tile <col>x <image prefix>*.<ext> <output image>
Change Video Bitrate¶
ffmpeg -i <input video> -vb <number>M <output video>
Change Video Frame Rate¶
ffmpeg -i <input video> -filter "minterpolate='mi_mode=mci:mc_mode=aobmc:vsbmc=1:fps=<number>'" <output video>
Speed Up/Slow Down Video¶
ffmpeg -i <input video> -vf "setpts=(1/<speed>)*PTS" <output video>
setpts only modifies the video’s metadata to adjust how long each frame is displayed.
Merge Two Videos into a Stereoscopic Video¶
ffmpeg -i top.mp4 -vf "[in] pad=iw:2*ih [top]; movie=bottom.mp4 [bottom]; [top][bottom] overlay=0:main_h/2 [out]" output_TB.mp4
ffmpeg -i left.mp4 -vf "[in] pad=2*iw:ih [left]; movie=right.mp4 [right]; [left][right] overlay=main_w/2:0 [out]" output_LR.mp4
Combine Separate Videos into One Multitrack Video¶
ffmpeg -i <input video 0> -i <input video 1> ... -c copy -map <track 0> -map <track 1> ... <output video>
Query Video Frame Information¶
ffprobe -show_frames -pretty <file>
Visualize Bitrate of a Stream Over Time¶
PlotBitrate uses the following command to query the bitrate data:
ffprobe -show_entries frame=pkt_size,pkt_pts_time <input>