Ffmpeg incantations

From Infiniwiki

Revision as of 00:05, 17 November 2020 by Andy (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

Contents

Change container

ffmpeg -i input.mkv -c:v copy -c:a copy output.mp4

Keep resolution, lower bitrate

ffmpeg -i input.mp4 -c:v libx264 -crf 20 -c:a copy output.mp4

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

Change resolution, lower bitrate

ffmpeg -i input.mp4 -c:v 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 -crf 18 -g 30 -bf 2 -profile:v high -pix_fmt yuv420p -movflags faststart -c:a aac -b:a 384k -profile:a aac_low output.mp4

Also enables fast start (moov atom at start).

Merge multiple audio tracks into a single track

ffmpeg -i input.mp4 -c:v copy -c:a aac -filter_complex "[0:a:0][0:a:1]amerge=inputs=2[a]" -map "0:v:0" -map "[a]" output.mp4
Personal tools