* [FFmpeg-devel] [FEATURE] Cut a video (-ss) with timings non-aligned on keyframes, with minimal re-encoding
@ 2025-07-20 21:54 basj
2025-07-21 18:39 ` Michael Niedermayer
0 siblings, 1 reply; 7+ messages in thread
From: basj @ 2025-07-20 21:54 UTC (permalink / raw)
To: ffmpeg-devel
Hi,
Out of curiosity, has there been any progress since 1 year about this topic?
Really, millions of CPU-hours are probably wasted to reencode already-perfectly-encoded content, just for cutting purposes. For example, is there a way to cut a AVI or MKV H264 video with a specific starting point and specific length, with minimal re-encoding?
When using: "ffmpeg -ss 120 -t 60 -i input.mp4 -c copy output.mp4", the result is often choppy or non-smooth in the first seconds, because the cut point doesn't necessarily coincide with a keyframe, at least on some players.
We could reencode just the beginning until the next keyframe, and then use copy codec for the rest of the video, and then concatenate, but nobody does this, it's unnecessarily complex (and I'm not even sure it works).
20 Aug 2024, 22:34, michael@niedermayer.cc wrote:
> Such signalling can be added to existing containers with little effort.
> Iam also happy to help to add it to nut
Can you explain with a little bit more details how it would work? Thanks in advance!
All the best.
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [FFmpeg-devel] [FEATURE] Cut a video (-ss) with timings non-aligned on keyframes, with minimal re-encoding
2025-07-20 21:54 [FFmpeg-devel] [FEATURE] Cut a video (-ss) with timings non-aligned on keyframes, with minimal re-encoding basj
@ 2025-07-21 18:39 ` Michael Niedermayer
0 siblings, 0 replies; 7+ messages in thread
From: Michael Niedermayer @ 2025-07-21 18:39 UTC (permalink / raw)
To: FFmpeg development discussions and patches
[-- Attachment #1.1: Type: text/plain, Size: 1818 bytes --]
Hi
On Sun, Jul 20, 2025 at 09:54:09PM +0000, basj@gget.it wrote:
> Hi,
>
> Out of curiosity, has there been any progress since 1 year about this topic?
>
> Really, millions of CPU-hours are probably wasted to reencode already-perfectly-encoded content, just for cutting purposes. For example, is there a way to cut a AVI or MKV H264 video with a specific starting point and specific length, with minimal re-encoding?
>
> When using: "ffmpeg -ss 120 -t 60 -i input.mp4 -c copy output.mp4",
> the result is often choppy or non-smooth in the first seconds,
clean patch welcome
> because the cut point doesn't necessarily coincide with a keyframe, at least on some players.
>
> We could reencode just the beginning until the next keyframe, and then use copy codec for the rest of the video, and then concatenate, but nobody does this, it's unnecessarily complex (and I'm not even sure it works).
theres some recent talk about edit lists, maybe what you describe is
another use case of proper edit list rendering
>
> 20 Aug 2024, 22:34, michael@niedermayer.cc wrote:
>
> > Such signalling can be added to existing containers with little effort.
> > Iam also happy to help to add it to nut
>
> Can you explain with a little bit more details how it would work? Thanks in advance!
Its a year since that mail you reply to, but
IIRC that just refered to that any data you want to attach you can attach in
nut. To frames, to streams, to any timespans and so on.
thx
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Breaking DRM is a little like attempting to break through a door even
though the window is wide open and the only thing in the house is a bunch
of things you dont want and which you would get tomorrow for free anyway
[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 195 bytes --]
[-- Attachment #2: Type: text/plain, Size: 251 bytes --]
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [FFmpeg-devel] [FEATURE] Cut a video (-ss) with timings non-aligned on keyframes, with minimal re-encoding
2024-08-14 10:05 basj
@ 2024-08-14 11:42 ` Zhao Zhili
0 siblings, 0 replies; 7+ messages in thread
From: Zhao Zhili @ 2024-08-14 11:42 UTC (permalink / raw)
To: FFmpeg development discussions and patches
> On Aug 14, 2024, at 18:05, basj@gget.it wrote:
>
>
>>> Do you think it would be worth developing a command-line option so that exact cutting with minimal re-encoding would be easier?
>>
>> How do you plan to figure out the options needed to be passed to each
>> and every encoder, so that it'll produce compatible output to enable the
>> necessary concatenation of old and new encoded data?
>>
>> That's by far the biggest roadblock I see with this.
>
> I see. You're right, then this technique is probably a dead-end...
>
> More generally, which is the recommanded way to cut a video with a specific starting point and specific length, with minimal re-encoding?
> Millions of hours of CPU-time are probably wasted to reencode already-perfectly-encoded content, just for cutting ;)
Only do remux without transcoding, and let mp4 muxer use editlist to strip the timeline from IDR to the requested start time.
The preroll at the beginning can be slow when playback, but seeking also has the same preroll
Other choice is use multiple groups of SPS/PPS in mp4 sample description. We have that support in mp4 demuxer, but not
in muxer. It’s standard in specification but not widely supported. So if we add support to muxer and it works with our own
demuxer, it’s not surprise to experience a lot of compatibility issues with other software.
>
> Are there already promising dev attempts in the direction of a feature able to cut with minimal re-encoding?
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 7+ messages in thread
* [FFmpeg-devel] [FEATURE] Cut a video (-ss) with timings non-aligned on keyframes, with minimal re-encoding
@ 2024-08-14 10:05 basj
2024-08-14 11:42 ` Zhao Zhili
0 siblings, 1 reply; 7+ messages in thread
From: basj @ 2024-08-14 10:05 UTC (permalink / raw)
To: ffmpeg-devel
> > Do you think it would be worth developing a command-line option so that exact cutting with minimal re-encoding would be easier?
>
> How do you plan to figure out the options needed to be passed to each
> and every encoder, so that it'll produce compatible output to enable the
> necessary concatenation of old and new encoded data?
>
> That's by far the biggest roadblock I see with this.
I see. You're right, then this technique is probably a dead-end...
More generally, which is the recommanded way to cut a video with a specific starting point and specific length, with minimal re-encoding?
Millions of hours of CPU-time are probably wasted to reencode already-perfectly-encoded content, just for cutting ;)
Are there already promising dev attempts in the direction of a feature able to cut with minimal re-encoding?
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [FFmpeg-devel] [FEATURE] Cut a video (-ss) with timings non-aligned on keyframes, with minimal re-encoding
2024-08-13 7:35 basj
@ 2024-08-13 8:55 ` Timo Rothenpieler
0 siblings, 0 replies; 7+ messages in thread
From: Timo Rothenpieler @ 2024-08-13 8:55 UTC (permalink / raw)
To: ffmpeg-devel
On 13.08.2024 09:35, basj@gget.it wrote:
>
> A little bump, does anyone have an idea about this?
>
> Do you think it would be worth developing a command-line option so that exact cutting with minimal re-encoding would be easier?
How do you plan to figure out the options needed to be passed to each
and every encoder, so that it'll produce compatible output to enable the
necessary concatenation of old and new encoded data?
That's by far the biggest roadblock I see with this.
> Linked: https://superuser.com/questions/1850814/cut-a-video-with-ffmpeg-with-no-or-minimal-reencoding
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
> To unsubscribe, visit link above, or email
> ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 7+ messages in thread
* [FFmpeg-devel] [FEATURE] Cut a video (-ss) with timings non-aligned on keyframes, with minimal re-encoding
@ 2024-08-13 7:35 basj
2024-08-13 8:55 ` Timo Rothenpieler
0 siblings, 1 reply; 7+ messages in thread
From: basj @ 2024-08-13 7:35 UTC (permalink / raw)
To: ffmpeg-devel
A little bump, does anyone have an idea about this?
Do you think it would be worth developing a command-line option so that exact cutting with minimal re-encoding would be easier?
Linked: https://superuser.com/questions/1850814/cut-a-video-with-ffmpeg-with-no-or-minimal-reencoding
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 7+ messages in thread
* [FFmpeg-devel] [FEATURE] Cut a video (-ss) with timings non-aligned on keyframes, with minimal re-encoding
@ 2024-08-05 19:45 basj
0 siblings, 0 replies; 7+ messages in thread
From: basj @ 2024-08-05 19:45 UTC (permalink / raw)
To: ffmpeg-devel
Hi,
Before trying to develop a new feature, and diving in the code base, I wanted to know if it currently exists, or is already in a work-in-progress task:
When cutting a video with no re-encoding:
ffmpeg -ss 120 -t 60 -i input.mp4 -c copy output.mp4
the result is often choppy or non-smooth in the first seconds, because the cut point doesn't necessarily coincide with a keyframe, at least on some players (such as Media Player Classic, etc.).
Some more complex solutions involve reencoding just the beginning until the next keyframe, and then use copy codec for the rest of the video, and then concatenating, all of this requiring multiple calls of ffmpeg.
Is there a feature already in development that would allow to do this in one single pass of ffmpeg, without multiple calls and concatenation?
Something like:
ffmpeg -ss 120 -t 60 -i input.mp4 -c copy -reencodebeforekeyframe output.mp4
Thanks,
Basj
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 7+ messages in thread
end of thread, other threads:[~2025-07-21 18:39 UTC | newest]
Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-07-20 21:54 [FFmpeg-devel] [FEATURE] Cut a video (-ss) with timings non-aligned on keyframes, with minimal re-encoding basj
2025-07-21 18:39 ` Michael Niedermayer
-- strict thread matches above, loose matches on Subject: below --
2024-08-14 10:05 basj
2024-08-14 11:42 ` Zhao Zhili
2024-08-13 7:35 basj
2024-08-13 8:55 ` Timo Rothenpieler
2024-08-05 19:45 basj
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git