FFmpeg Notes

FFmpeg commands

Join multiple video files having same codec and resolution into a single file.

Use a txt file with the list of input files in this format

list.txt

file 'file_1.mp4'
file 'file_2.mp4'
file 'file_3.mp4'
ffmpeg -safe 0 -f concat -i list.txt -c copy out.mp4

Trim Video files (time format HH:MM:SS.ZZZZ)

There are basically two ways to describe your cut. The order of flags matter

  1. Define your start time and the time after that to cut, like start at 5 seconds and cut till next 10 seconds of video
# the out.mp4 will be a 10 sec video which starts at 5 secs from input video and ends at 15 sec.

ffmpeg -ss 05 -t 10 -i input.mp4 -c copy out.mp4
  1. Define your start time and end time, like start at 5 seconds and cut at 10 seconds of video
# the out.mp4 will be a 5 sec video which starts at 5 secs from input video and ends at 10 sec.

ffmpeg -ss 05 -to 10 -i input.mp4 -c copy out.mp4

Video file into image sequence

ffmpeg -i input.mp4 -r 30 -f image2 out%03d.jpg
  • -r it sets the rate here 30 frames per second will be extracted
  • -f sets the correct format

Combine image sequence into video file

ffmpeg -i image%03d.jpg -r 30 -start_number 1 -vframes 300 -c:v libx264 -crf 25 out.mp4
  • -r sets the framerate of video
  • -start_number sets the starting number of the image if you want to start from image 100 in your sequence then set it to 100
  • -vframes sets the total frame of video here it sets to 300, with framerate of 30 we get a 10 seconds clip out of it