FFmpeg HOWTO

%% ## Table of Contents
%%
%% * Generic Syntax
%% * Main Options
%% * Encoding :
%% - D10 (aka Sony IMX)
%% - DVCAM / DVCPRO25 / DVCPRO50
%% - VC-3 (aka Avid DNxHD)
%% - FFV1
%% - H.264 I-frame only in Highest Quality
%% - H.264 Long GOP
%% - MPEG-2 I-frame only in Highest Quality
%% - MPEG-2 Long GOP
%% * Muxing and Wrapping :
%% - D10 into QuickTime ( for Final Cut Pro import )
%% - MPEG-2 Program Stream
%% * Demuxing and Unwrapping :
%% - MPEG-2 Program Stream
%% * Timecode Management :
%% - MPEG-2 Start Timecode
%% * Misc :
%% - Audio Volume Modification
%% - Input Stream Selection
%% - Sub-clip Creation
%% - Make a Video File from a Single Frame

Generic Syntax #

ffmpeg [[infile options][-i infile]]... {[outfile options] outfile}...

Note : As a general rule, options are applied to the next specified file. Therefore, order is important and you can have the same option on the command line multiple times. Each occurrence is then applied to the next input or output file.

Main Options #

D10 (aka Sony IMX) Encoding #

ffmpeg -async 1 -i <input_file> -vcodec mpeg2video -r 25 -pix_fmt yuv422p -minrate 50000k -maxrate 50000k -b 50000k -intra -flags +ildct+low_delay -dc 10 -flags2 +ivlc+non_linear_q -ps 1 -qmin 1 -qmax 3 -top 1 -bufsize 2000000 -rc_init_occupancy 2000000 -rc_buf_aggressivity 0.25 -an output.m2v

Notes : #

DVCAM / DVCPRO25 / DVCPRO50 Encoding #

ffmpeg -i <input_file> -pix_fmt yuv420p output_DVCAM.dv
ffmpeg -i <input_file> -pix_fmt yuv411p output_DVCPRO25.dv
ffmpeg -i <input_file> -pix_fmt yuv422p output_DVCPRO50.dv

VC-3 (aka Avid DNxHD) Encoding #

ffmpeg -i <input_file> -vcodec dnxhd -b <bitrate> -an output.mov

Notes : #
Supported Resolutions : #
Project FormatResolutionFrame SizeBitsFPSbitrate
1080i / 59.94DNxHD 2201920 x 1080829.97185Mb
1080i / 59.94DNxHD 1451920 x 1080829.97120Mb
1080i / 50DNxHD 1851920 x 1080825185Mb
1080i / 50DNxHD 1201920 x 1080825120Mb
1080p / 25DNxHD 1851920 x 1080825185Mb
1080p / 25DNxHD 1201920 x 1080825120Mb
1080p / 25DNxHD 361920 x 108082536Mb
1080p / 24DNxHD 1751920 x 1080824185Mb
1080p / 24DNxHD 1151920 x 1080824120Mb
1080p / 24DNxHD 361920 x 108082436Mb
1080p / 23.976DNxHD 1751920 x 1080823.976185Mb
1080p / 23.976DNxHD 1151920 x 1080823.976120Mb
1080p / 23.976DNxHD 361920 x 1080823.97636Mb
1080p / 29.7DNxHD 451920 x 1080829.9736Mb
----------------------------------------------------------------

FFV1 Encoding #

ffmpeg -i <input_file> -vcodec ffv1 -an output.mov

H.264 I-frame only Highest Quality Encoding #

ffmpeg -i <input_file> -vcodec h264 -cqp 1 -intra -coder ac -an output.mp4

H.264 Long GOP Encoding #

ffmpeg -i <input_file> -vcodec h264 -b <video_bitrate> -g <gop_size> -bf 2 -b_strategy 1 -flags +loop -coder 1 -subcmp 2 -cmp 2 -trellis 2 -me hex -acodec aac -ab <audio_bitrate> output.mp4

MPEG-2 I-frame only Highest Quality Encoding #

ffmpeg -i <input_file> -vcodec mpeg2video -qscale 1 -qmin 1 -intra -an output.m2v

MPEG-2 Long GOP Encoding #

ffmpeg -i <input_file> -vcodec mpeg2video -b <video_bitrate> -g <gop_size> -bf 2 -b_strategy 1 -acodec mp2 -ab <audio_bitrate> -f vob output.mpg

D10 into QuickTime Wrapping #

ffmpeg -i <input_file> -vcodec copy -acodec pcm_s16le -vtag mx5p -vbsf imxdump output.mov

Notes : #

MPEG-2 Program Stream Muxing #

ffmpeg -genpts 1 -i ES_Video.m2v -i ES_Audio.mp2 -vcodec copy -acodec copy -f vob output.mpg

MPEG-2 Program Stream Demuxing #

ffmpeg -i input.mpg -vcodec copy -f mpeg2video ES_Video.m2v -acodec copy -f mp2 ES_Audio.mp2

Note : This also works for files containing multiple audio tracks :
ffmpeg -i input.mpg -vcodec copy -f mpeg2video ES_Video.m2v -acodec copy -f mp2 ES_Audio1.mp2 -acodec copy -f mp2 ES_Audio2.mp2

MPEG-2 Start Timecode #

ffmpeg -i <input_file> -timecode_frame_start <start_timecode> -vcodec mpeg2video -an output.m2v

Note : Start timecode is set as number of frames. For instance, if you want to start at 18:12:36:15, you will have to set -timecode_frame_start to 1638915 ( for 25 fps content ).

Audio Volume Modification #

ffmpeg -i <input_file> -vol <audio_volume> -acodec <audio_codec> <output_file>

Input Stream Selection #

ffmpeg -i input.vob -map 0:2 -acodec aac -ab <audio_bitrate> -vn output.mp4

Transcode audio stream #0:2.

Sub-clip Creation #

ffmpeg -i <input_file> -ss <timecode> -t <timecode> -vcodec copy -acodec copy <output_file>

Make a Video File from a Single Frame #

ffmpeg -loop_input -vframes <number_of_frames> -i <input_file> <output_file>

DaVinci Resolve cheatsheet #

Convert MP4 to MOV #

This is the command I use to convert a MP4 file recorded from a video camera to a MOV format of the same quality that DaVinci Resolve can import and read.

ffmpeg -i input.mp4 -vcodec dnxhd -acodec pcm_s16le -s 1920x1080 -r 30000/1001 -b:v 36M -pix_fmt yuv422p -f mov output.mov

Convert MKV to MOV with Multiple Audio Tracks #

This command seems a bit far-fetched, but if you’re on Linux like me, you’d know that recording multiple audio tracks from OBS is only supported with the MKV video format. Since DaVinci Resolve doesn’t support MVK, here’s the command I use to convert that file into a readable MOV while keeping the audio on their separated tracks.

ffmpeg -i input.mkv -map 0:0 -map 0:1 -map 0:2 -vcodec dnxhd -acodec:0 pcm_s16le -acodec:1 pcm_s16le -s 1920x1080 -r 30000/1001 -b:v 36M -pix_fmt yuv422p -f mov output.mov

Convert MOV to MP4 #

When it comes to rendering a file from DaVinci Resolve, I was forced to stick with the MOV format with some high video/audio codec settings. The rendered file is not small, but nonetheless, FFmpeg is more than capable of handling it and converting it into a slim and crisp MP4.

The settings I’m using are those recommended by YouTube for a fast upload and a almost zero processing.
If the file size is too big, you can control the quality with the -crf 1 option, changing the number up until 25, where a higher number means lower quality.

ffmpeg -i input.mov -vf yadif -codec:v libx264 -crf 1 -bf 2 -flags +cgop -pix_fmt yuv420p -codec:a aac -strict -2 -b:a 384k -r:a 48000 -movflags faststart output.mp4

Published