Lossless Video Cut with FFmpeg

About this page

Here's how I make lossless videos cuts using FFmpeg. This method can cut a video very fast... It usually goes so fast it makes you wonder if it actually worked! It's ridiculous :) This is really nice, for example, when you have a really long source video that you want to work with but you really only need a very small portion of the video and would rather not drag a huge video file into your video editing program.

Below you'll find a brief explanation of how the ffmpeg syntax works and a function I wrote to simplify things a bit.

FFmpeg command format

The basic format is: ffmpeg -i originalvideo.mp4 -ss 0:0:4 -t 0:1:10 -vcodec copy -acodec copy outputvideo.mp4

  • -ss : start time. If omitted, ffmpeg will start from the beginning
  • -t : length in H[H]:M[M]:S[S]

When performing a lossless cut, it is only possible to start on a keyframe. Whether you understand what that means or not, the important thing to remember is that the start time and length of the movie will not be exact. The length will mostly likely be a little longer than you specify.

A bash function that I wrote to make things easier for myself

function ffcutvideo() {
  if [[ $# -eq 0 ]] || [[ $# -eq 1 ]]; then
    echo 'Please specify a video file, length, and optionally a start time. If no start time is given, ffmpeg will start from the beginning. Time format is H[H]:M[M]:S[S] ie: "ffcutvideo somevideo.mp4 0:1:30 0:0:4" or "ffcutvideo somevideo.mp4 0:1:30"'
  else
    if [[ $# -eq 2 ]]; then
      ffmpeg -i "$1" -t "$2" -vcodec copy -acodec copy cut-"$1"
    else
      ffmpeg -i "$1" -ss "$3" -t "$2" -vcodec copy -acodec copy cut-"$1"
    fi
  fi
}

Internal References

External References

Article Type

General