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, 04:23   #1  |  Link
Cyber Akuma
Registered User
 
Cyber Akuma's Avatar
 
Join Date: May 2002
Posts: 167
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, 05:14   #2  |  Link
manolito
Registered User
 
manolito's Avatar
 
Join Date: Sep 2003
Location: Berlin, Germany
Posts: 3,078
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, 23:14   #3  |  Link
Cyber Akuma
Registered User
 
Cyber Akuma's Avatar
 
Join Date: May 2002
Posts: 167
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, 01:49   #4  |  Link
manolito
Registered User
 
manolito's Avatar
 
Join Date: Sep 2003
Location: Berlin, Germany
Posts: 3,078
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, 16:15   #5  |  Link
Taurus
Registered User
 
Taurus's Avatar
 
Join Date: Mar 2002
Location: Krautland
Posts: 903
@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 16:16. Reason: grammar
Taurus is offline   Reply With Quote
Old 8th December 2018, 02:11   #6  |  Link
manolito
Registered User
 
manolito's Avatar
 
Join Date: Sep 2003
Location: Berlin, Germany
Posts: 3,078
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, 03:55   #7  |  Link
kuchikirukia
Registered User
 
Join Date: Oct 2014
Posts: 476
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, 01:12   #8  |  Link
Cyber Akuma
Registered User
 
Cyber Akuma's Avatar
 
Join Date: May 2002
Posts: 167
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, 04:44   #9  |  Link
poisondeathray
Registered User
 
Join Date: Sep 2007
Posts: 5,345
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, 19:12   #10  |  Link
Cyber Akuma
Registered User
 
Cyber Akuma's Avatar
 
Join Date: May 2002
Posts: 167
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, 19:47   #11  |  Link
manolito
Registered User
 
manolito's Avatar
 
Join Date: Sep 2003
Location: Berlin, Germany
Posts: 3,078
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 26th January 2019, 00:02   #12  |  Link
Cyber Akuma
Registered User
 
Cyber Akuma's Avatar
 
Join Date: May 2002
Posts: 167
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: 3,078
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
Old 30th June 2020, 21:16   #14  |  Link
Cyber Akuma
Registered User
 
Cyber Akuma's Avatar
 
Join Date: May 2002
Posts: 167
Just noticed your reply.

I tried using the latest ffmpeg, nope, still stuck at 0%

I also realized I could open the console, and saw this happen when VidCutter pretty much freezes at 0%:

https://i.imgur.com/0hvBW2b.png

First of all.... why is it using frontslashes? Windows/Dos uses backslashes... and it appears to just flat out be erroring out in it's python code and not realizing this, keeping it stuck.
__________________
"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 July 2020, 15:26   #15  |  Link
manolito
Registered User
 
manolito's Avatar
 
Join Date: Sep 2003
Location: Berlin, Germany
Posts: 3,078
I had not used VidCutter for a while, so I updated it to use the latest FFmpeg version 4.3 (static 32-bit version). I use the 32-bit version of VidCutter.

Tried it with some longer HD files. Video codec was AVC, container either MKV, MP4 or TS. The TS file did not work at all, it would hang at 0%. But both the MP4 and also the MKV files worked like a charm. So I really regret that VidCutter development seems to be dead, it does have potential...

Last edited by manolito; 1st July 2020 at 15:51.
manolito is offline   Reply With Quote
Old 6th July 2020, 03:06   #16  |  Link
Cyber Akuma
Registered User
 
Cyber Akuma's Avatar
 
Join Date: May 2002
Posts: 167
Seems to be utterly broken for me. Were you using SmartCut by any chance? It works for me with SmartCut off.... but the whole reason I am using it instead of other software is BECAUSE of the SmartCut feature.

I tried it on Windows. I tried the version of ffmpeg it came with, and my own.

I tried toggling every combination of settings on and off.

I then tried it in Linux. Also toggling every setting on and off.

Exact same phyton script error happened every time (the one I posted a screenshot of) when SmartCut was on. Regardless of other settings, regardless of OS.
__________________
"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 6th July 2020, 15:31   #17  |  Link
manolito
Registered User
 
manolito's Avatar
 
Join Date: Sep 2003
Location: Berlin, Germany
Posts: 3,078
Really weird...

Of course I use SMART cutting mode. Could it be that you are not really using a current FFmpeg version? Because VidCutter extracts the built-in FFmpeg at every program start to the user Temp folder (C:\Users\xxxxx\AppData\Local\Temp\_MEI54722\Bin in my case) and uses this version unless you changed the location in the settings. My settings window looks like this:

manolito is offline   Reply With Quote
Old 6th July 2020, 20:30   #18  |  Link
Cyber Akuma
Registered User
 
Cyber Akuma's Avatar
 
Join Date: May 2002
Posts: 167
I don't think it has anything to do with FFMPEG, that error message seems to indicate that there is an error in the Phython script itself.

Are you using the latest version of VidCutter by any chance?

And what versions of ffmpeg and mprobe are you using? And type?
__________________
"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 6th July 2020, 22:41   #19  |  Link
manolito
Registered User
 
manolito's Avatar
 
Join Date: Sep 2003
Location: Berlin, Germany
Posts: 3,078
I use the very latest VidCutter 6.0 version 32-bit.

For FFmpeg and FFprobe I use the latest GIT version 4.3 32-bit static. You have to be careful with current Zeranoe Point Releases. For a while all the Point Releases were the LGPL versions which did not include libx264 and libx265. I believe that this has been fixed now, but it would not hurt to check your FFmpeg version if "Enable gpl" is in this build.

If you also use a different MediaInfo version, please make sure that you do not use anything newer than version 18.5.
manolito is offline   Reply With Quote
Old 15th September 2020, 13:48   #20  |  Link
manolito
Registered User
 
manolito's Avatar
 
Join Date: Sep 2003
Location: Berlin, Germany
Posts: 3,078
Just the other day I needed to make some frame accurate cuts in an AVC/AAC HD video clip, and this time I gave VidCutter a thorough test. Result: Not useable for frame accurate cutting.

I did find the reason for the crashes, though. The first and the last video sections are problematic. If either the first section starts at frame 0 of the source clip AND / OR the last section ends at the last source frame then it is guaranteed that you will get a crash. To avoid crashes the first section has to start at a certain distance from the source start, and the last section needs to end a good deal before the last source frame.

This problem would be manageable, but the other problem is that VidCutter in frame accurate mode tends to ruin the audio. My sources all have AAC audio, and after cutting with VidCutter I get clicks and audible distortion in the resulting file. This only happens in frame accurate cutting mode, and I think it is an FFmpeg issue. It also has nothing to do with different FFmpeg versions.

No wonder that the author has abandoned his software, getting frame accurate cutting to work seems to be an impossible task...

I have completely switched to Smart Cutter. It is not cheap, the user interface looks a little retro (which I like), but the results are flawless.
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 12:47.


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