I have a folder full (1000+) of two minute long AVC mp4 files (captured with ShadowPlay). I would like to batch trim them to keep only the last 20 seconds of each two minute file. The catch is that I need the timecode information (Date Created) to stay the same on the edited file. That is to say, the new edited file must have the same time stamp as the original file. I know there are standalone programs that will do that (change the time stamp) manually, but it would take too much time to edit 1000+ files manually.
I found someone with a similar question on this forum, and he was recommended Tencoder, which seemed exactly what I was looking for. Unfortunately, most of the files trimmed in Tencoder (about 80%) have a weird one second freeze when they start. This causes audio to go out of sync in video editing software.
I guess I'm wondering one of two things: Is there software that does what Tencoder does without the weird glitch, or is there a setting in Tencoder that will eliminate this freezing?
Thanks for your time.
+ Reply to Thread
Results 1 to 30 of 35
-
-
I guess you read
https://forum.videohelp.com/threads/371759-Need-help-batch-splitting-many-mp4-files
?
I would try a ffmpeg command and see if you get same problem. Just to check if it's ffmpeg problem. Or some tencoder problem(it should use ffmpeg) or something else.
Code:c:\ffmpeg\ffmpeg.exe -i "c:\video\video.mp4" -c:v copy -c:a copy -ss 00:01:40 "c:\video\videocut.mp4"
And what are the mp4 video details? Use mediainfo, open mp4, change to View->Text and copy everything.Last edited by Baldrick; 7th Mar 2016 at 02:38.
-
I guess it's the
Code:Frame rate mode : Variable Frame rate : 60.000 fps
-
No, I'd rather not convert.
I wonder why the frame rate/mode isn't a problem when trimming with other software like Solveig.
Edit add: Maybe there is software that can repair the damage after trimming?Last edited by sfuller73; 7th Mar 2016 at 03:54.
-
Could you upload/attach sample files? Both a working mp4 and trimmed damaged one.
ffmpeg can only cut lossless at keyframes so it could also be the problem. Solveigmm Video Splitter is a better cutter and can cut exactly(smart rendering/reconverts just at the cut point). -
Here are two short four second clips of the same file. One from ffmpeg, and the other from Solveig. Note the short freeze at the start of the ffmpeg clip. The third clip is the edit of both clips in Sony Vegas. The Solveig clip is in sync while the ffmpeg clip is not.
Note: I use Zoom Player, where I notice the freeze at the start of the damaged clips. In VLC, there is no freeze.
I guess there is no way to make ffmpeg cut on keyframes?
There is a ton of software out there that does accurate batch trimming but none that I can find that will keep the original timestamp, other than Tencoder. Maybe someone knows of an obscure alternative? -
-
I suspect putting -ss 00:01:40 after -i causes splitting to take place at the next keyframe. If however, the audio is being split more accurately, that'll require a small video delay. I think the way most players would handle that would be to display the first frame until the audio "catches up" which would appear to be a short freeze. If I'm right...... it's untested theory.
MediaInfo isn't showing any video delay for the ffmpeg sample, but that mightn't mean there isn't one.
Putting -ss 00:01:40 before -i should cause splitting to commence at the preceding keyframe, which might solve the problem and keep editing programs that are oblivious to video delays happy.
Or.... isn't the segment option designed to fix those sorts of problems? Some combination of
-f segment, -segment_time, or segment_start_number etc
https://www.ffmpeg.org/ffmpeg-formats.html#segment_002c-stream_005fsegment_002c-ssegment
I haven't used it myself.Last edited by hello_hello; 8th Mar 2016 at 16:59.
-
I had a bit more of a play and now I'm fairly certain it's a video delay issue. I can't find a way to check for a delay applied to an MP4 stream. MediaInfo won't display it and I've tried creating MP4s from raw streams myself (ffmpeg and MP4Box) and it still won't display them. The only way I've been able to show there's a delay is to remux an MP4 as an MKV with MKVMergeGUI and check the MKV with MediaInfo.
After remuxing the ffmpeg sample from post #6, MediaInfo shows an audio delay of -479ms. That's technically not possible as negative delays can't be used in MKVs, it's how MediaInfo displays a positive video delay.... as a negative audio delay.
I've no idea how to properly check for delays applied to MP4 streams. I never use MP4 myself. -
If you don't mind some extra A/V, you can avoid the freeze and audio sync issues when using ffmpeg, like so:
Code:c:\ffmpeg\ffmpeg.exe -ss 00:01:40 -i "c:\video\video.mp4" -c:v copy -c:a copy -avoid_negative_ts make_zero "c:\video\videocut.mp4
-
@hello_hello: As I'd be using Tencoder, I don't think I can use the -i command. At least, I can't get it to work. And you're right, the delay is not noticeable in any player. My problem is that it becomes noticeable when editing.
@mulvya: Took a look at Touch, but I have no idea how to use it. Doesn't appear to do batch rewriting.
@poisondeathray: The Tencoder command was -ss 00:01:40. It was definitely ffmpeg because Mencoder won't do direct stream copying.
Thanks to all for your help. I've learned a lot even if I haven't found a solution. Looks like the features I need don't exist in one single product. -
maybe a buggy ffmpeg build used in tencoder ? It missed an entire GOP for the video (or depending on how you look at it 1/2sec for audio) . These should be easy to cut - they are 30 frame fixed , closed GOPs, no b-frames .
It should be a piece of cake in ffmpeg (it can have problems with open GOPs, non IDR frames, which you don't have). Above I said video is longer, sorry it's actually the opposite - the resulting audio is longer (audio is "overhanging"; or video too short, depending on how you look at it - glass half empty or half full sort of thing), that is the cause of your problems. If you cut the audio to match it would work, or if it didn't miss the last GOP, or added blank video it would work too. Can you dig around for a tencoder log file, and also try using an updated ffmpeg build manually to see if the problem can be replicated ? Compressed audio cutting has finer accuracy than video (you're limited by GOP length for video), so this shouldn't be happening. ie. Even if it "missed" the first GOP that you wanted for video , it should have cut the audio at the same spot to match, not left the audio from the preceding GOPLast edited by poisondeathray; 10th Mar 2016 at 00:14.
-
No, you have to create a batch file that incorporates the ffmpeg and touch commands
Code:FOR /R "C:\Video\" %%F in (*.mp4) DO ( c:\ffmpeg\ffmpeg.exe -ss 00:01:40 -i "%%F" -c:v copy -c:a copy -avoid_negative_ts make_zero -f mp4 "c:\video\%~nFcut.mp4" c:\ffmpeg\touch.exe -r "%%F" "c:\video\%~nFcut.mp4" )
-
ffmpeg's behavior certainly seems odd.
This command line behaves as you'd expect, at least when it comes to the audio. The video is cut on the keyframe before the specified cut point (if there's not one at the cut point) and the audio is split in the same place, or just after. For the MKV with AAC audio I used for testing, the output file only ever had a positive audio delay of a few ms.
-ss 00:01:40 -i "E:\test.mkv" -y -c:v copy -c:a copy "D:\test.mkv"
This command line gets ffmpeg to cut the video on the first keyframe after the specified cut point, but it still cuts the audio at the specified cut point, which often results in a large delay being applied to the video stream. For the MKV I used for testing it was nearly 4 seconds.
-i "E:\test.mkv" -y -ss 00:01:40 -c:v copy -c:a copy "D:\test.mkv"
I managed to get the segment function to work, although I don't think it'll be useful in this case. It does seem to split the video and audio in as close to the same place as possible, but instead of there being a small positive delay to the audio to make up the difference, it applies a positive delay to the video. And I couldn't find a way to stop it writing the first segment, so I don't think there's a way to get it to create just a single MKV that's split off the end of the source.
-i "E:\test.mkv" -c:v copy -c:a copy -f segment -segment_times 00:01:40 out%03d.mkvLast edited by hello_hello; 10th Mar 2016 at 09:27.
-
Use -ss and -t as an input option (preceding the -i ) . hello_hello, you already mentioned that
Here is a random shadowplay file I cut with ffmpeg
eg. duration for video/audio respectively when used after as an output option
Duration : 29s 648ms
Duration : 30s 16ms
eg. duration for video/audio respectively when used before as an input option
Duration : 30s 121ms
Duration : 30s 123ms
If you still can't get it to work, post a sample of your input file please -
-
@poisondeathray/@mulvya:
Using mulvya's
Code:c:\ffmpeg\ffmpeg.exe -ss 00:01:40 -i "c:\video\video.mp4" -c:v copy -c:a copy -avoid_negative_ts make_zero "c:\video\videocut.mp4
When I tried mulvya's batch file, however, nothing happened. If I can get that to work with a folder full of files, I think it'll be exactly what I'm looking for. Should it have worked as is, or did I need to make adjustments?
(I saved the code in a .bat file.)
I can't thank you guys enough. I'd never written a script in my life before I posted here. -
Are your paths correct ?
Write pause at the end of the .bat to see the error message -
Yeah, the same paths I used for individual files.
Writing pause doesn't work either, no matter where I write it. I must be missing something simple.
EDIT: I guess I should add that I need to keep the trimmed file names the same as the originals. As I can't get the batch to work, I'm not sure if this is already implemented in the code.Last edited by sfuller73; 10th Mar 2016 at 15:07.
-
You're missing double %% for some arguments (.bat for windows uses double %%) , and the -- is required for windows version of touch
If you need the name the same, you need to process the output files in a separate folder e.g a subfolder (which you should be doing anyways), otherwise you're as risk of endless loops and other bad things
Here is a basic template for non recursive folders (1 folder level). I have the bat in the same folder (you need to specify paths otherwise) , and in that folder there is a subfolder called "output" . Modify the paths/folders as you see fit, for example you might have a specific directory that you want the output files in
Code:for %%a in ("*.mp4") do ( ffmpeg.exe -ss 00:01:40 -i "%%a" -c:v copy -c:a copy -avoid_negative_ts make_zero -f mp4 "output\%%~na.mp4" touch.exe -r "%%a" -- "output\%%~na.mp4" ) pause
-
Everything worked except for the timestamps. With some trial and error (I removed the "--" from the touch code), it now works perfectly.
Perhaps as importantly, this has really piqued my interest in coding.
Again, you guys have put a lot of time and effort into running your own trials and helping me with code. I still want to mess around with hello_hello's experimentation on my own.
Thanks for everything. It's greatly appreciated. -
timestamp ? Did you really mean DTS, PTS or date created ?
Date created / date modified is wrong unless I include -- -
To be clear, typically when one talks about "timestamps" they usually refers to the video timestamps . DTS is decoding time stamp , PTS is presentation time stamp
The file attributes of date, creation time, modified time etc.. those are completely different and have nothing to do with video timestamps . In the 1st post you said you wanted the (Date Created) the same
There are also other metadata such as encoded and tagged dates, which can be different from file creation/modify/access dates. Those are container specific tags
Can you clarify exactly which one(s) you're referring to ?Last edited by poisondeathray; 10th Mar 2016 at 16:14.
-
Sorry, I meant Date Created. Removing the -- worked for me. Trimmed files have the original date created.
-
-
Oh ffs, I was wrong. I had my folder column set as Date Modified, not Date Created. Either is fine for my purposes, though.
Sorry for the confusion.
Similar Threads
-
Mpeg-4 (h264 - MPEG-4 AVC) batch time-based splitting tool for Windows
By jokob in forum EditingReplies: 3Last Post: 4th May 2015, 19:26 -
Editing AVC files without re-encoding
By galapogos in forum EditingReplies: 2Last Post: 18th Oct 2014, 12:33 -
problem viewing avc files
By maximov in forum Software PlayingReplies: 10Last Post: 11th Oct 2012, 09:36 -
avidemux 2.5.6 will support h264\avc video files or not?
By Ganesh Ujwal in forum EditingReplies: 6Last Post: 14th Aug 2012, 05:11 -
Best way to batch convert xvid/avi files to mkv/x264 files?
By gaikokujinkyofusho in forum Video ConversionReplies: 1Last Post: 13th Jan 2012, 06:31