Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Video Encoding > MPEG-4 AVC / H.264

Reply
 
Thread Tools Search this Thread Display Modes
Old 18th April 2018, 17:01   #1  |  Link
Wowfunhappy
Registered User
 
Join Date: Sep 2013
Posts: 22
Cut beginning of h264 video with minimal re-encoding?

Ffmpeg makes it super easy to losslessly cut off the end of an existing h264 stream: you just use -codec copy alongside -t or -to to specify how long you want the clip to be.

Cutting off the beginning of a stream with -ss, however, does not work so well. I always end up with a corrupted second or two of video at the beginning of the resulting clip.

I understand why this is—h264 frames cannot exist independently, as they rely on information from previous frames. As a result, some frames will always have to be re-encoded—but I should be able to avoid re-encoding everything, right?

How can I cut a portion from the beginning of an h264 stream while re-encoding only the minimum number of frames required? I would prefer to do this via ffmpeg, if possible

Thanks!
Wowfunhappy is offline   Reply With Quote
Old 18th April 2018, 22:15   #2  |  Link
sneaker_ger
Registered User
 
Join Date: Dec 2002
Posts: 5,565
According to the documentation ffmpeg is supposed to seek to keyframes so corruption isn't supposed to happen. Try latest version and if that doesn't work make a bug report. But maybe that is a limitation with OpenGOP style encodings. I do not know. ffmpeg doesn't support automatic "smart" encoding where only the affected GOP is re-encoded and the rest is copied.

There are other softwares for that: SolveigMM Video Splitter, VideoReDo, Selur's "MKV Cutter" and probably a hand full of others I forgot about.
sneaker_ger is offline   Reply With Quote
Old 20th April 2018, 15:58   #3  |  Link
Wowfunhappy
Registered User
 
Join Date: Sep 2013
Posts: 22
Thanks for that link. I'd seen it before but a very long time ago. Reading through, I might I misinterpreted my problem:

Quote:
Using -ss as input option together with -c:v copy might not be accurate since ffmpeg is forced to only use/split on i-frames. Though it will—if possible—adjust the start time of the stream to a negative value to compensate for that. Basically, if you specify "second 157" and there is no key frame until second 159, it will include two seconds of audio (with no video) at the start, then will start from the first key frame. So be careful when splitting and doing codec copy.
I think this is working correctly. When I cut the video, players output a couple seconds of audio with no video before the video comes in. I interpreted this as "the video stream is corrupted."

Is there a way to tell ffmpeg to not include audio only at the beginning?
Wowfunhappy is offline   Reply With Quote
Old 20th April 2018, 16:17   #4  |  Link
ChaosKing
Registered User
 
Join Date: Dec 2005
Location: Germany
Posts: 1,795
If you want a GUI for cutting use http://avidemux.sourceforge.net/
You can jump to next keyframe (IDR) and cut without re-encoding.
__________________
AVSRepoGUI // VSRepoGUI - Package Manager for AviSynth // VapourSynth
VapourSynth Portable FATPACK || VapourSynth Database
ChaosKing is offline   Reply With Quote
Old 23rd April 2018, 06:45   #5  |  Link
kuchikirukia
Registered User
 
Join Date: Oct 2014
Posts: 476
Just use mkvtoolnix GUI. It cuts cleanly on keyframes.
kuchikirukia is offline   Reply With Quote
Old 23rd April 2018, 14:19   #6  |  Link
manolito
Registered User
 
manolito's Avatar
 
Join Date: Sep 2003
Location: Berlin, Germany
Posts: 3,078
If key frame accuracy is not enough, there are not many free choices. Solveig and VideoRedo are commercial. The only free offerings for frame accurate cutting I have found are MKVCutter by Selur and the current versions of VidCutter. I have not tested them, but they sure look promising...

Cheers
manolito
manolito is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 23:43.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.