3 ms·
Does this do anything clever to enable actual frame perfect cutting, or is it just splitting on keyframes like avidemux or `ffmpeg -i input.mp4 -ss "START_TIME"
by thot_experiment 3y ago
Does this do anything clever to enable actual frame perfect cutting, or is it just splitting on keyframes like avidemux or `ffmpeg -i input.mp4 -ss "START_TIME" -to "END_TIME" -c:v copy output.mp4`?
- izacus 3y agoThere's nothing "clever" you can do to losslessly cut outside the keyframe boundaries. Since reencoding is required, loss of quality for at least the cut GOP is a given.
- thot_experiment 3y agoI'm not sure about that, naively you could turn the entire cut GOP into i-frames couldn't you? I'm not super familiar with the nitty gritty of h264/h265 but intuitively I think you wouldn't even need to turn everything in the GOP into i-frames. You could trace out the inter-frame topology of the GOP and then replace only the "orphan" frames with i-frames, then the remaining p and b-frames would retain the necessary reference data for decoding. I would love it if someone who knows more about this than I do would confirm/deny since this is something I've been curious about for a long time now. (Though I would also love a tool for near-lossless cutting that just re-encodes the cut GOP, please link such a thing if it exists)
- ShadowBanThis01 3y ago"naively you could turn the entire cut GOP into i-frames couldn't you" Yes, but then you'd have to render the result into a truly uncompressed format and it would have to stay in that format perpetually. If you wanted to deliver in another lossy format, you'd actually lose quality across the entire file instead of just the one GOP. What I'm curious about is whether you can cut in the middle of GOPs, recompress the afflicted ones, and then concatenate the stream back together without recompressing all GOPs. If the file specifies a 12-frame GOP, cutting any GOPs is going to break that cadence. So can you have, say, a few thousand 12-frame GOPs... then an 8-frame GOP... then go back to 12-frame GOPs? Update: Did some research and you can have "adaptive" GOPs of varying lengths: https://docs.aws.amazon.com/mediaconvert/latest/ug/gop-structure.html https://docs.aws.amazon.com/mediaconvert/latest/ug/gop-struc...
- thot_experiment 3y agoYeah there's no issue there, most codecs support variable bitrates and variable iframe-pacing, and ffmpeg will happily concat such files. Also, there's no need to render into an "uncompressed format" the i-frames are still compressed, and even in the naive case you'd only need small number of i-frames because you only need to replace any orphans in the cut GOP after which you can just go back to normal decoding.
- izacus 3y agoYeah, you can absolutely reencode just the GOP where the cut happens and IIRC quite a few tools support that.
- eviks 3y agoIndeed, was wondering whether there is a clever tool like that, i-frames is a simple idea, and then you could potentiality did something smarter like your tracing idea
- synarchefriend 3y agoI believe the SmartCut feature reencodes just the frames needed to reach the closest keyframe.
- pkkm 3y agoYou can toggle it between snapping your selection to the nearest keyframe and reencoding the frames between your selection and the nearest keyframe.