[ffmpeg] An idea to mix re-encoding with copy to get a fast and precise cut

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

[ffmpeg] An idea to mix re-encoding with copy to get a fast and precise cut

Mohammed Hamdy
Hi,

I have an idea to make ffmpeg do a fast and precise cut, by re-ncoding just shorts parts around the cut points, and copy the rest of the desired segment  without re-encoding. I wish it can be done. Details:



suppose I want to generate a new video that doesn't contain the chuck starts at t1 to t2. I want ffmpeg to do this to divide the segment (t1, t2) to 3 parts:

  1.  a part (t1-x, t1+y), which is a complete encoded block that should be re-encoded to be able to copy the part (t1, y) precisely.
  2.  a part (t2-z, t3+w), which is a complete encoded block that should be re-encoded to be able to copy the part (z, t2) precisely.
  3.  a middle part (y, z) which contains complete encoded blocks, where it can be copied as is.

Then join the 3 parts resulted from the above steps. Note that the first two parts are expected to be small (and one of them or both can be zero length), so, the re-encoding process will be fast. This will make us able to have exact cuts with slightly slower operation but still super faster than re-encoding the full video. It can be even faster if we can do multiple cuts with one command, so we traverse the frames once.

So, can I do that today with ffmpeg? Or, can ffmpeg support it soon?

_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: [ffmpeg] An idea to mix re-encoding with copy to get a fast and precise cut

Mark Filipak
On 07/25/2020 06:08 PM, Mohammed Hamdy wrote:
> Hi,
>
> I have an idea to make ffmpeg do a fast and precise cut, by re-ncoding just shorts parts around the cut points, and copy the rest of the desired segment  without re-encoding. I wish it can be done. Details:
>
> suppose I want to generate a new video that doesn't contain the chuck starts at t1 to t2. I want ffmpeg to do this to divide the segment (t1, t2) to 3 parts:
>
>    1.  a part (t1-x, t1+y), which is a complete encoded block that should be re-encoded to be able to copy the part (t1, y) precisely.

It's impossible to re-encode precisely. There's always some loss. But perhaps you don't mean
"re-encode", eh? Perhaps you mean to copy the packets without decoding. That's theoretically
possible if tl-x and tl+y are precisely at key frames and there are no predictive frames that cross
the boundary (though they could be dropped) and there has been no prior editing that already has
damaged B-frame & P-frame references (which does happen, even in commercially mastered material).

>    2.  a part (t2-z, t3+w), which is a complete encoded block that should be re-encoded to be able to copy the part (z, t2) precisely.
>    3.  a middle part (y, z) which contains complete encoded blocks, where it can be copied as is.
>
> Then join the 3 parts resulted from the above steps. Note that the first two parts are expected to be small (and one of them or both can be zero length), so, the re-encoding process will be fast. This will make us able to have exact cuts with slightly slower operation but still super faster than re-encoding the full video. It can be even faster if we can do multiple cuts with one command, so we traverse the frames once.
>
> So, can I do that today with ffmpeg? Or, can ffmpeg support it soon?

Not likely, but I'm just another Bozo on this bus.
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".