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 1st December 2018, 03:23   #1  |  Link
Cyber Akuma
Registered User
 
Cyber Akuma's Avatar
 
Join Date: May 2002
Posts: 156
Trying to cut the first few seconds of a MP4 video on a non-keyframe

So, this has been driving me nuts. I have a video that I went to cut out the first 30-40 or so seconds without re-encoding the entire thing. Issue is, the part I want to cut on is not on a keyframe, so most software I used either cuts on the keyframe before the part I want (such as Avidemux) leaving in a few moments of garbage video, or gives me a video that is just bank for the first few moments (ffmpeg) until the next keyframe.

I couldn't figure out a way to make anything read the previous seconds of the video and generate a new keyframe at the beginning of the cut, so I figured my next best bet would be to actually split the video on that keyframe, then trim the part I want from the beginning by re-encoding just the half or so segment I want, and then joining that with the rest of the video.

Issue is, I have no idea how to attempt to duplicate the settings of the second half of the video so I can join it. All attempted have just resulted in it rejecting the second half of the video to join (mp4box) or spitting out a video that after that first half second or so is just corrupted and does not play the rest (avidemux).

Does anybody have any suggestions on this? I am assuming the re-encoding route is my only option, but how would I duplicate the settings of the original video so I can re-join it?
__________________
"A train station is where a train stops. A bus station is where a bus stops. On my desk I have a workstation..." - ComradOtter
Cyber Akuma is offline   Reply With Quote
Old 1st December 2018, 04:14   #2  |  Link
manolito
Registered User
 
manolito's Avatar
 
Join Date: Sep 2003
Location: Berlin, Germany
Posts: 2,550
I had very good results using VidCutter for MP4 files. It has a "Smart Rendering" feature which means that it can cut frame accurate without reencoding the whole file.

http://forum.doom9.org/showthread.ph...72#post1855172

https://www.videohelp.com/software/VidCutter


Good luck
manolito
manolito is offline   Reply With Quote
Old 4th December 2018, 22:14   #3  |  Link
Cyber Akuma
Registered User
 
Cyber Akuma's Avatar
 
Join Date: May 2002
Posts: 156
It doesn't seem to be working. Whenever I have Smart Rendering enabled, it just gets stuck at 0% when I try to trim a clip, I see no CPU or HDD usage from VidCutter.
__________________
"A train station is where a train stops. A bus station is where a bus stops. On my desk I have a workstation..." - ComradOtter
Cyber Akuma is offline   Reply With Quote
Old 7th December 2018, 00:49   #4  |  Link
manolito
Registered User
 
manolito's Avatar
 
Join Date: Sep 2003
Location: Berlin, Germany
Posts: 2,550
Yes, VidCutter still does have many problems when Smart Rendering is enabled. Many users report that oftentimes it just gets stuck at a certain percentage of the process. It also happens here, I could not really fix it, but I found some things which improve it a little bit...

I am on Win7 - 64bit, so I first used the 64-bit version of VidCutter. But after switching to the 32-bit version I got the feeling that the 32-bit version is a bit more reliable.

Another thing which improved the behavior was to use a newer FFmpeg version instead of the embedded version. I also found that it is not necessary to use shared FFmpeg versions, the static versions work fine.

The source file format also plays a role. I had better success with MP4 containers than with MKV. And probably the most importat reason for the software to just get stuck is the duration of the input file.

So it looks like the author still has a lot of work to do, I hope that he will get it right soon...


Cheers
manolito
manolito is offline   Reply With Quote
Old 7th December 2018, 15:15   #5  |  Link
Taurus
Registered User
 
Taurus's Avatar
 
Join Date: Mar 2002
Location: Krautland
Posts: 856
@manolito
I've just tested your suggestions.
And yes, the only halfway reliable workflow is repacking all your stuff into a mp4 container.
With mkv I've got scrambled/corrupted frames all over the place.
Mts/m2ts is fine in the timeline, editing ok... but the program just hangs at decoding/encoding stage.
No CPU, no HDD, no nothing
Exchanging both versions (32/64bit) to the latest ffmpeg binairies.
But same behaviour as far as I can see.
It's a shame, such a nice gui, and exactly what I needed.
Now back to search for a new tool....

Last edited by Taurus; 7th December 2018 at 15:16. Reason: grammar
Taurus is offline   Reply With Quote
Old 8th December 2018, 01:11   #6  |  Link
manolito
Registered User
 
manolito's Avatar
 
Join Date: Sep 2003
Location: Berlin, Germany
Posts: 2,550
Quote:
Originally Posted by Cyber Akuma View Post
... so I figured my next best bet would be to actually split the video on that keyframe, then trim the part I want from the beginning by re-encoding just the half or so segment I want, and then joining that with the rest of the video.

Issue is, I have no idea how to attempt to duplicate the settings of the second half of the video so I can join it. All attempted have just resulted in it rejecting the second half of the video to join (mp4box) or spitting out a video that after that first half second or so is just corrupted and does not play the rest (avidemux).
If VidCutter does not work in your case then I think your approach indeed is your best bet. If your reencoded segment uses the same codecs and the same frame size for video then there is a good chance that you can join these parts.

I first tried with MkvToolNix. I did get a warning about different private codec parameters, but the resulting file played fine.

The other thing I tried was FFmpeg for joining the files. dmMediaConverter is an FFmpeg GUI with some very useful options, and among other things it has an option to "Merge the same". This means that the input files need to use identical codecs and frame sizes, and I also got good results with this method.

What I did notice for both methods was a very small audio dropout at the merge point. Hardly audible, but of course this can be fixed with a WAV editor...


Cheers
manolito
manolito is offline   Reply With Quote
Old 16th December 2018, 02:55   #7  |  Link
kuchikirukia
Registered User
 
Join Date: Oct 2014
Posts: 431
Quote:
Originally Posted by manolito View Post
What I did notice for both methods was a very small audio dropout at the merge point.
Mkvtoolnix is really good at cutting without audio drops.

So:
Mux to mkv
Split with mkvtoolnix on keyframe
Reencode the first segment with the same codec, trimming how you want.
Trim the audio.
Append.
kuchikirukia is offline   Reply With Quote
Old 3rd January 2019, 00:12   #8  |  Link
Cyber Akuma
Registered User
 
Cyber Akuma's Avatar
 
Join Date: May 2002
Posts: 156
Quote:
Originally Posted by manolito View Post
If VidCutter does not work in your case then I think your approach indeed is your best bet. If your reencoded segment uses the same codecs and the same frame size for video then there is a good chance that you can join these parts.
Sorry, was not getting notifications that people were replying to this topic anymore.

I tried that, but the issue was that I was not able to figure out how to make the encode I make the same as the rest of the video, so attempting to join it would fail.
__________________
"A train station is where a train stops. A bus station is where a bus stops. On my desk I have a workstation..." - ComradOtter
Cyber Akuma is offline   Reply With Quote
Old 3rd January 2019, 03:44   #9  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 3,826
If you use a different --sps-id , you can join sections with different encoding settings or when other methods fail
poisondeathray is offline   Reply With Quote
Old 15th January 2019, 18:12   #10  |  Link
Cyber Akuma
Registered User
 
Cyber Akuma's Avatar
 
Join Date: May 2002
Posts: 156
Hmm, seems VidCutter has some kind of bug or something where it fails to do a smart-render if your cut ends at or close to the end of the actual video. I tried experimenting a bit, and it would get stuck at 0% if I was trying to cut a clip that extends all the way to the end of the video even if it's not from the start of the video.

Also it seems the video it ends up spitting out is problematic. I tried it in VLC and MPC:HC, MPC plays it fine but VLC crashes....
__________________
"A train station is where a train stops. A bus station is where a bus stops. On my desk I have a workstation..." - ComradOtter
Cyber Akuma is offline   Reply With Quote
Old 15th January 2019, 18:47   #11  |  Link
manolito
Registered User
 
manolito's Avatar
 
Join Date: Sep 2003
Location: Berlin, Germany
Posts: 2,550
I don't use VidCutter all that often, but I feel that its reliability improved after replacing the built-in versions of FFmpeg and FFprobe with the latest builds from Zeranoe (works with the static builds, no need to download the shared builds). And I only use it for MP4, MKV always causes problems.


Cheers
manolito
manolito is offline   Reply With Quote
Old 25th January 2019, 23:02   #12  |  Link
Cyber Akuma
Registered User
 
Cyber Akuma's Avatar
 
Join Date: May 2002
Posts: 156
I checked, seems like I am already using the Zeranoe versions of FFmpeg and FFprobe, and the files I am working with are MP4.

But I am still having issues where VidCutter gets stuck at 0% if the end of the segment I am clipping is near the end of the video.

I have tried adjusting every setting in the app, but it just gets stuck at 0% if I attempt to create a clip with SmartCut if the endpoint is near the end of the video.
__________________
"A train station is where a train stops. A bus station is where a bus stops. On my desk I have a workstation..." - ComradOtter
Cyber Akuma is offline   Reply With Quote
Old 11th August 2019, 10:40   #13  |  Link
manolito
Registered User
 
manolito's Avatar
 
Join Date: Sep 2003
Location: Berlin, Germany
Posts: 2,550
Even though it looks like VidCutter is no longer maintained, I have the feeling that it does get better with newer FFmpeg versions...

I replaced the built-in FFmpeg and FFprobe versions with the latest stable versions 4.2 from Zeranoe (static build), and now even when using 1024p sources it does not hang any more. And this is not only true for MP4 sources, MKV sources also seem to work.

Worth another try...
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 15:11.


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