VideoHelp Forum




+ Reply to Thread
Page 1 of 2
1 2 LastLast
Results 1 to 30 of 35
  1. 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.
    Quote Quote  
  2. I'm a MEGA Super Moderator Baldrick's Avatar
    Join Date
    Aug 2000
    Location
    Sweden
    Search Comp PM
    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.
    Quote Quote  
  3. I'm a MEGA Super Moderator Baldrick's Avatar
    Join Date
    Aug 2000
    Location
    Sweden
    Search Comp PM
    I guess it's the

    Code:
    Frame rate mode : Variable
    Frame rate : 60.000 fps
    that cause the problems. But I have no idea how to fix them. I guess you don't want to reconvert everything.
    Quote Quote  
  4. 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.
    Quote Quote  
  5. I'm a MEGA Super Moderator Baldrick's Avatar
    Join Date
    Aug 2000
    Location
    Sweden
    Search Comp PM
    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).
    Quote Quote  
  6. 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?
    Image Attached Files
    Quote Quote  
  7. I'm a MEGA Super Moderator Baldrick's Avatar
    Join Date
    Aug 2000
    Location
    Sweden
    Search Comp PM
    You must reconvert if you want to cut exactly(not on every keyframes) with ffmpeg.

    Maybe if you could batch replace the timestamp after you edited the files.
    Last edited by Baldrick; 8th Mar 2016 at 11:48.
    Quote Quote  
  8. You must reconvert if you want to cut on keyframes with ffmpeg.
    Didn't you mix up something there? Normally ffmpeg should only cut on key frames unless you re-encode not the other way around.
    users currently on my ignore list: deadrats, Stears555, marcorocchini
    Quote Quote  
  9. I'm a MEGA Super Moderator Baldrick's Avatar
    Join Date
    Aug 2000
    Location
    Sweden
    Search Comp PM
    Originally Posted by Selur View Post
    You must reconvert if you want to cut on keyframes with ffmpeg.
    Didn't you mix up something there? Normally ffmpeg should only cut on key frames unless you re-encode not the other way around.
    Ooops. Yep. You must reconvert if you want to cut anywhere/exact.
    Quote Quote  
  10. 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.
    Quote Quote  
  11. 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.
    Quote Quote  
  12. Member
    Join Date
    Aug 2014
    Location
    India
    Search Comp PM
    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
    You can then use touch which can use a reference file viz. the full video to write timestamps of the exported segment.
    Quote Quote  
  13. There is an AV length mismatch in the ffmpeg version ; the video is longer than the audio. So there needs to be an offset.

    What was the command line used in tencoder to cut files ? Are you sure ffmpeg was used? IIRC it can also use Mencoder
    Quote Quote  
  14. @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.
    Quote Quote  
  15. 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 GOP
    Last edited by poisondeathray; 10th Mar 2016 at 00:14.
    Quote Quote  
  16. Just tried trimming a file with the newest ffmpeg release and got the same result.

    I'll upload the Tencoder log.
    Image Attached Files
    Quote Quote  
  17. Member
    Join Date
    Aug 2014
    Location
    India
    Search Comp PM
    Originally Posted by sfuller73 View Post
    @mulvya: Took a look at Touch, but I have no idea how to use it. Doesn't appear to do batch rewriting.
    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"
     )
    My scripting is a bit rusty, but this should work.
    Quote Quote  
  18. 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.mkv
    Last edited by hello_hello; 10th Mar 2016 at 09:27.
    Quote Quote  
  19. 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
    Quote Quote  
  20. Member
    Join Date
    Aug 2014
    Location
    India
    Search Comp PM
    Originally Posted by hello_hello View Post
    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.mkv
    Use

    Code:
    ffmpeg -i "E:\test.mkv" -c:v copy -c:a copy -f segment -segment_times 00:01:40 -segment_wrap 1 -reset_timestamps 1 out%03d.mkv
    Quote Quote  
  21. @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
    code seems to work. As does Touch. I'm able to trim individual files (without noticeable sync problems) and then adjust their timestamps.

    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.
    Quote Quote  
  22. Are your paths correct ?

    Write pause at the end of the .bat to see the error message
    Quote Quote  
  23. 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.
    Quote Quote  
  24. Originally Posted by sfuller73 View Post
    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.

    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
    Quote Quote  
  25. 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.
    Quote Quote  
  26. timestamp ? Did you really mean DTS, PTS or date created ?

    Date created / date modified is wrong unless I include --
    Quote Quote  
  27. 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.
    Quote Quote  
  28. Sorry, I meant Date Created. Removing the -- worked for me. Trimmed files have the original date created.
    Quote Quote  
  29. Originally Posted by sfuller73 View Post
    Sorry, I meant Date Created. Removing the -- worked for me. Trimmed files have the original date created.
    Did you mean date created as in file attributes through Windows ? How are you reading "Date Created" ?

    That's interesting, I get the exact opposite. Removing -- gives the current date/time, not the original file date/time

    What version of touch , what OS ?
    Quote Quote  
  30. 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.
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!