Skip to content

Instantly share code, notes, and snippets.

@louisswarren
Last active May 26, 2021 20:52
Show Gist options
  • Select an option

  • Save louisswarren/2b05724807b5a282948677dead1f1a7d to your computer and use it in GitHub Desktop.

Select an option

Save louisswarren/2b05724807b5a282948677dead1f1a7d to your computer and use it in GitHub Desktop.
ffmpeg notes

ffmpeg notes

I often want to do something that I believe is non-trivial in ffmpeg, only to discover that it is actually very simple, if only I had known how to do it. I even end up writing wrappers to do simple things, because I keep forgetting what to do. However, this file is my new solution: simply write my own documentation for things I would occasionally like to do.

Trimming video between two timecodes

ffmpeg -ss 1:00 -to 2:00 -i input.mkv -c copy output.mkv
  • -ss 1:00 (before -i): start reading input at time 1:00
  • -to 2:00: stop reading input at time 2:00
  • -c copy use the original encoding

Trimming video to a given duration

ffmpeg -i input.mkv -t 1:00 -c copy output.mkv
  • -t 1:00: limit output duration to one minute

Concatenating (parts of) videos together

First create a file list in concat.txt. Full syntax here.

file 'input1.mkv'
	inpoint 1:00
	outpoint 2:00

file 'input2.mkv'
	inpoint 0:30
	outpoint 1:30

file 'input3.mkv'
file 'input4.mkv'

Consider inpoint and outpoint the same way as -ss and -to above. Now,

ffmpeg -f concat -safe 0 -i concat.txt -c copy output.mkv
  • -safe 0: stop the demuxer from rejecting 'unsafe' file paths. Not always necessary, obviously. See the documentation.

Cropping a video

ffmpeg -i input.mkv -filter:v "crop=width:height:x:y" -c:a copy output.mkv
  • x and y are the coordinates of the top left of the crop area
  • -c:a copy: copy the audio stream
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment