Ffmpeg incantations

From Infiniwiki

Jump to: navigation, search

Contents

Keep resolution, lower bitrate

ffmpeg -i input.mp4 -vcodec libx264 -crf 20 output.mp4

CRF value can be changed - note lower CRF equals higher bitrate

Change resolution, lower bitrate

ffmpeg -i input.mp4 -vcodec libx264 -crf 20 -vf scale=-1:720 output.mp4

CRF value can be changed as before, scale is w:h, -1 = keep aspect ratio based on the other value

Merge files, no re-encode

ffmpeg -f concat -i files.txt -c copy output.mp4

files.txt format:
file 'input1.mp4'
file 'input2.mp4'

Copy part of video, no re-encode (slow seeking but accurate times)

ffmpeg -i input.mp4 -ss 00:00:30.000 -t 00:00:05.000 -c:v copy -c:a copy output.mp4

Argument order matters!

Copy part of video, no re-encode (time-inaccurate but fast seeking)

ffmpeg -ss 00:00:30.000 -i input.mp4 -t 00:00:05.000 -c:v copy -c:a copy output.mp4

Argument order matters!

Re-encode to a format supported by Vegas Pro

ffmpeg -y -i input.mkv -bf 0 -c:v libx264 -c:a aac -strict experimental -tune fastdecode -pix_fmt yuv420p -b:a 192k -ar 48000 -ac 2 output.mp4

Argument order matters!

Change playback rate

ffmpeg -y -i input.mp4 -c:v copy -an -filter:v "setpts=0.01*PTS" output.mp4

Rate change is 1/N where N is 0.01 in the example. This example thus outputs at 100x speed.

Re-encode to a sensible size/bitrate for YouTube

ffmpeg -i input.mp4 -c:v libx264 -preset slow -crf 16 -c:a copy -pix_fmt yuv420p -g 30 -movflags faststart output.mp4

Also enables fast start (moov atom at start).

Personal tools