2

Is it possible to lossless clip out the video file (MPEG-4/H.264) that result chunks will be equivalent to the same of raw footage? I want to reduce size of the source (raw) material by cutting off the unnecessary, but desire to have remaining clips in the same quality as initial video.

3 Answers 3

3

Yes, it is generally possible, but with a few limitations. h.264 uses what is known as a group of pictures. A group of pictures groups multiple frames together in a way that allows for further compression, but the entire group of pictures has to be decoded together. As such, it is only possible to cut a video stream in between groups of pictures. This is often around 15 frames, but length can vary based on encoding options that were used.

As long as you are ok breaking it on a group of pictures, you can cut up the video to your hearts content and still use the same data stream. At the end of the day, most video formats consist of some metadata that describes how the video is laid out and how it syncs with the audio. It then contains one or more streams of video and one or more streams of audio. When played back, this metadata is read and then the streams are used for playback.

Splitting the file simply means extracting part of the stream, broken up on a group of pictures, pulling out the relevant audio and then piecing the data back together in a new container that has metadata that corresponds to it. As long as you break it at the points it is designed to break, then it ends up being two normal, otherwise unaltered streams. There are numerous tools that can do this for you, including tools like FFMPEG, though I unfortunately do not have the exact command to perform the split as my FFMPEG skills are decidedly weaker than many others on here (though one of them will likely soon be able to post with the command line you need.)

7

This is possible with the FFmpeg command ffmpeg -i input.mp4 -ss 0 -c copy -t 60 output.mp4. This would cut the video from the beginning -ss 0 to second 60 -t 60.

Be aware that -ss is and offset which -t is based upon. So -ss 10 and -t 60 would result in cutting to second 70 and removing the first 10. You can use the -to option to cut at a fixed time unrelated to -ss.

I'm not exactly sure how ffmpeg will handle GOPs but I think it will cut at the nearest GOP at the specified time.

Relevant question on SU: https://superuser.com/questions/138331/using-ffmpeg-to-cut-up-video

2
  • 1
    This will not cut accurately. It will look for the nearest iFrame and cut at that point. The only way to cut losslessly with FFmpeg is to use some lightweight encoding like the following (very slow) method: ffmpeg -ss 00:00:03.123 -i input.mp4 -t 10 -c:v libx264 -c:a aac -strict experimental out.mp4 Aug 17, 2018 at 21:04
  • The question was in regard to the encoding, as in lossless picture quality. When you re-encode the output you are able to cut more accurately but not without a loss in frame information.
    – timonsku
    Aug 18, 2018 at 22:21
0

Also, these days you can use this nice crossplatform GUI tool LosslessCut (with FFmpeg under the hood).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.