ffmpeg command references

Converting to TS

Convert any source video to mpeg2video/mpegts - MPEG Transport Stream

ffmpeg \
	-c:v mpeg2video -q:v 2 -pix_fmt yuv420p -r 24 \
	-c:a copy \
	-f mpegts \
	-y output.mts

Convert FLAC to MP3

ffmpeg \
	-i 02\ -\ The\ Wizard.flac \
	-c:a mp3 \
	-y ../../Wiz.mp3

Concatenate Audio/Video Media

There are many ways to get this done.

This example concatenates similar media to one, see above to convert to this format first.

ffmpeg \
	'concat:vid0.mts|vid1.mts|vid2.mts' \
	-c copy \
	-y output.mts

Cropping Video

ffmpeg \
	-i source.webm \
	-vf crop=w:h:x:y \
	-y output.webm

Rotate Video

The Transpose video filter takes care of this.

ffmpeg \
	-i source.webm \
	-vf transpose=1 \
	-y output.webm

0 = 90CounterCLockwise and Vertical Flip (default)
1 = 90Clockwise
2 = 90CounterClockwise
3 = 90Clockwise and Vertical Flip

Slicing Media

This will slice from 1:45.123 to 5:64:321, -to is the stop time of the track.

ffmpeg \
	-ss 1:45.123 \
	-to 5:64:321 \
	-i source.webm \
	-c copy \
	-y output.webm

This will slice starting at 1:45.123 for 5:64:321, -t is the duration.

ffmpeg \
	-ss 1:45.123 \
	-t 5:64:321 \
	-i source.webm \
	-c copy \
	-y output.webm

Splicing Media

Take one audio file and one video file to make a merged files.

ffmpeg \
	-i source.mts \
	-i source.wav \
	-c:v libvpx -crf 8 -qmin 0 -qmax 50 -b:v 8M -threads 2 -deadline good -cpu-used 2 \
	-c:a libvorbis -b:a 32K \
	-f webm \
	-y output.webm

Splitting Media

Here we take the source media and create an MP3 audio file.

ffmpeg \
	-i source.webm \
	-a:c mp3 \
	-vn \
	-y output.mp3

Here we take the source media and create an MP4 video file.

ffmpeg \
	-i source.webm \
	-an \
	-y output.mp4

Stretch Video

Change the playback speed

Stretch the duration of the video, it may slow down the play rate.

ffmpeg \
	-i source.webm \
	-filter:v "setpts=0.9*PTS" \
	-y output.webm

Trimming Media

This is basically the same as slicing, but the start or end time is implied to be the beginning or end respectively.

This will make the source file 1 minute, 45 seconds long, removing the tail of the file.

ffmpeg \
	-ss 0 \
	-t 1:45.000 \
	-i source.webm \
	-c copy \
	-y output.webm

This will remove the first 1 minute, 45 seconds of the file, cutting the head off.

ffmpeg \
	-ss 1:45.000 \
	-i source.webm \
	-c copy \
	-y output.webm

Generating Blank Video

The duration is 1.234s, colour is specified here in hex, adjust the size (640x480) as necessary.

ffmpeg \
	-to 1.234 \
	-filter_complex color=c=#101010:s=640x480:r=24 \
	-an \
	-c:v mpeg2video -q:v 2 -pix_fmt yuv420p -r 24 \
	-f mpegts \
	-y output.mts