3

I am using ffmpeg to cut a video accurately at a given time to another time. I know, we can simply re-encode it, but will lose the quality. Also, I do not want to use copy option because of key frames issue (i.e, the video won't be cutt accurately). These are the commands that I used.

ffmpeg -ss 55 -i input.mp4 -t 00:03:06 -vcodec copy -acodec copy out.mp4 
ffmpeg -ss 55 -i input.mp4 -t 00:03:06 out.avi
mdasari
  • 423
  • 4
  • 11
  • Please see this answer instead. https://stackoverflow.com/questions/18444194/cutting-the-videos-based-on-start-and-end-time-using-ffmpeg – bdutta74 Aug 13 '18 at 12:21

1 Answers1

3

It's impossible. Either you have to re-encode the video, or include the keyframes needed for other frames which reference them.

If you do not want to lose quality, you could output to a lossless file (e.g., YUV, HuffYUV, FFV1, …) or continue working visually losslessly (e.g., ProRes, DNxHD, high-quality H.264 / H.265, …).

slhck
  • 36,575
  • 28
  • 148
  • 201
  • Thanks slhck, I guess you are right, re-encoding is necessary at least to lossless file YUV. I hope it won't it be an issue to cut a YUV file accurately at a given time. Although, it takes too much time for encoding and decoding, its not a bad idea because there is no other choice. – mdasari Jun 10 '17 at 21:02
  • 1
    Is it just impossible with ffmpeg or in theory also? I would have thought, that by making every frame a keyframe you should not lose quality and still cut exactly where you want. Can you please tell if this is true, at least in theory? Alas, when I try with "ffmpeg -i video.MP4 -to 00:00:20.000 -g 1 cutVideo.MP4" the quality seems worse, at least in VLC. I also tried "ffmpeg -i video.MP4 -ss 00:00:15.440 -to 00:00:30.440 -crf 0 losslessVideo.MP4" but that looks even worse. – user1323995 Oct 17 '19 at 07:17
  • 2
    @user1323995 Even in theory it is impossible. When you "make a frame a keyframe" you have to re-encode it. The only way to do that without quality loss is to use a lossless codec. `-crf 0` should work, and it should not look worse in any way. If you have a problem there please post a new question on [SU]. Note that there is a way to include the required frames in the output and not display them, but not all players support this. – slhck Oct 17 '19 at 07:59