VideoHelp Forum
+ Reply to Thread
Page 3 of 4
FirstFirst 1 2 3 4 LastLast
Results 61 to 90 of 108
Thread
  1. I modified butterw's batch file a bit:

    Code:
    echo off
    
    md out
    for %%f in (*.mp4) do (
        echo fname: "%%f"
        echo .
        ffmpeg -i "%%f" -t 3600 -c copy -y tmp1.mp4
        ffmpeg -ss 3600 -i "%%f" -c copy -avoid_negative_ts auto -y tmp2.mp4
    
        echo file 'tmp1.mp4' > concat.txt
        REM echo file 'inter.mp4' >> concat.txt
        echo file './inter/inter.mp4' >> concat.txt
        echo file 'tmp2.mp4' >> concat.txt
    
        ffmpeg -safe 0 -f concat -i concat.txt -c copy -movflags faststart "./out/%%~nf_out.mp4"
    
        del tmp1.mp4
        del tmp2.mp4
        del concat.txt
    )
    
    REM Press any key to continue . . .
    pause
    Put the inter.mp4 clip in a subfolder called inter. That keeps the for loop from trying to process it as one of your source videos. The results will be in a subfolder called out.
    Quote Quote  
  2. Whenever you want to create a batch file:
    - The correct approach is always to get it working for a single-file first,
    - making it work for a folder of files isn't difficult in a second step.

    Ultimately though, I don't know how robust the result is going to be. People have been struggling with this command-line for years.
    a possible issue would be: Part1, Part2 and inter all play OK. but when you combine them it only plays OK up to Part1.
    This could be caused by incorrect timestamps or incompatible video encoding settings.

    Avidemux works pretty good, hopefully a few extra commands can be added to improve it.
    Last edited by butterw; 15th Jan 2021 at 08:46.
    Quote Quote  
  3. It might help to generate new time codes on the final output.
    Quote Quote  
  4. Testing from a single mp4 (x264+aac) source file:
    - works if the inter.mp4 segment is generated using ffmpeg with, ex:
    ffmpeg -ss 1000 -i "%%f" t 100 -c copy -avoid_negative_ts make_zero -y inter.mp4

    - did not work if inter.mp4 was saved with Avidemux. Presumably -avoid_negative_ts make_zero is missing.
    at concat:
    [mp4 @ 000002d00644e3c0] Non-monotonous DTS in output stream 0:0; previous: 2575307, current: 2540365; changing to 2575308. This may result in incorrect timestamps in the output file.
    >> and indeed the file doesn't play correctly beyond tmp1.

    @jraju:
    1) Rename inter.mp4 saved with avidemux to inter0.mp4
    2) Run the following from command line in the folder:
    Code:
    ffmpeg -i inter0.mp4 -c copy -avoid_negative_ts make_zero inter.mp4
    3) concat should now work as expected

    with: ffmpeg -safe 0 -f concat -i concat.txt
    It's possible to put inter.mp4, tmp1.mp4 and tmp2.mp4 in the out subfolder, which solves the *.mp4 detection problem.
    Last edited by butterw; 15th Jan 2021 at 17:47. Reason: -avoid_negative_ts make_zero seems to work better than auto
    Quote Quote  
  5. The following v0.2 ffmpeg .bat script will create ./out/filename_out.mp4 files such as:
    Part1_60min | inter.mp4 | Part2
    Part2 will start at the keyframe before 60min (there will be overlap of a few seconds between Part1 and Part2).
    - first create a subdirectory named out which will contain the output and temporary files
    - in this subdir name the intermission file to be inserted, inter.mp4 it must be created with ffmpeg, or at least have corrected timestamps (see previous post).

    In the folder containing the mp4 files to process:
    - Create a file named concat.txt with the following content:
    Code:
    file 'out/tmp1.mp4'
    file 'out/inter.mp4' 
    file 'out/tmp2.mp4'
    - place and run the ffm_insert.bat script from this folder.
    ffmpeg.exe will need to be available in the folder, or the PATH.

    ffm_insert.bat: v0.2
    Code:
    echo off
    
    REM for %%f in ("*.mp4") do (
    for %%f in ("kbs001.mp4") do (
    	echo fname: %%f
    	echo.
    
    ffmpeg -hide_banner -i %%f -t 01:00:00 -c copy -y "./out/tmp1.mp4"
    echo.
    REM ffmpeg -hide_banner -ss 00:09:50 -i %%f -t 100 -c copy -avoid_negative_ts make_zero "./out/inter.mp4"
    ffmpeg -hide_banner -ss 01:00:00 -i %%f -c copy -avoid_negative_ts make_zero -y "./out/tmp2.mp4"
    echo.
    
    REM echo file 'out/tmp1.mp4' > concat.txt
    REM echo file 'out/inter.mp4' >> concat.txt
    REM echo file 'out/tmp2.mp4' >> concat.txt
    
    echo "./out/%%~nf_out.mp4"
    ffmpeg -safe 0 -hide_banner -f concat -i concat.txt -c copy -movflags faststart -y "./out/%%~nf_out.mp4"
    )
    
    REM Press any key to continue . . .
    pause
    The script will initially process only the file kbs001.mp4, but this can easily be changed to process all .mp4 file in folder.
    Last edited by butterw; 15th Jan 2021 at 17:43.
    Quote Quote  
  6. Member jraju's Avatar
    Join Date
    Mar 2013
    Location
    India
    Search Comp PM
    hi, butterw,
    I have changed the inter.mp4 with ffmpeg command line.
    Temperorary files are created , is it not
    So, what i did was to copy the revised bat and run.
    inter.mp4 is in the ffmpeg folder and not in out folder
    temp files are created automatically I suppose,
    will run and report back
    Hi, jagabo, thank you for your tips also
    while copying the inner.mp4 to the output folder and processing the same,
    i get so many time stamp errors
    what is time stamp errors, is it duration errors
    Last edited by jraju; 15th Jan 2021 at 22:56.
    Quote Quote  
  7. Member jraju's Avatar
    Join Date
    Mar 2013
    Location
    India
    Search Comp PM
    Hi, moreover, the processed output , run smoohly upto part one. Then it stops playing video.
    Plays the audio of inner.mp4, not video
    Then play continues
    This is when i place the inner.mp4 in out folder
    I think that , the following works out correctlyl . have to test on the next file before exatending to the folder
    I just use this formula to create the inter.mp4
    ffmpeg -ss [start] -i in.mp4 -t [duration] -c copy out.mp4
    By using this formula to cut the first few minutes of the video and renaming it to inter.mp4 and placing it in out folder.
    then i ran the script. no timestamp or any other errors.
    the process finished very quick and i have tested the video and audio, it is very good.
    Hi, butterw,
    how do i extend to a folder. Expecting your script for all the fiiles in a folder
    I also checked the size of the inter.mp4 created by ffmpeg is slightly different from the avidemux.
    Thanks for all the help butt and jaga
    Last edited by jraju; 15th Jan 2021 at 23:54.
    Quote Quote  
  8. Member jraju's Avatar
    Join Date
    Mar 2013
    Location
    India
    Search Comp PM
    Ok, how can i be sure that it does not miss any seconds of video while doing this process.
    What I mean, is , if suppose, part2 starts with a bit of part one while muxing the second part , not to miss any bit of second of video.
    In other words, if i will see some seconds of scene in second part, it will be good instead of loosing anyframe
    I know that the video stops at exact in an hour , may be in the middle of conversation.
    could you kindly say something on this
    Quote Quote  
  9. Originally Posted by jraju View Post
    how do i extend to a folder. Expecting your script for all the fiiles in a folder
    change this part of the script:
    Code:
    REM for %%f in ("*.mp4") do (
    for %%f in ("kbs001.mp4") do (
    to apply to only file kbs002.mp4:
    Code:
    REM for %%f in ("*.mp4") do (
    for %%f in ("kbs002.mp4") do (
    to apply to all .mp4 files in folder:
    Code:
    for %%f in ("*.mp4") do (
    REM for %%f in ("kbs001.mp4") do (
    Quote Quote  
  10. My script creates and then overwrites temporary files out/tmp1.mp4 and out/tmp2.mp4 for each new file.

    Timestamp errors mean you will likely get a glitch when joining. The file may or may not be playable beyond the joining point or there might just be a small glitch at the joining point.
    I'm using -avoid_negative_ts make_zero to try to correct the timestamps and from my limited testing this seems to work.

    My script inserts at one hour (which may occur mid-conversation), one benefit of manually using avidemux instead would be that you can control precisely when the insert happens.
    The overlap between part1 and part2 is caused by how ffmpeg works (part1 cuts at one hour, part2 starts on the keyframe before 1 hour). It's possible to select a larger overlap by changing the -ss parameter of the tmp2.mp4 line of the script:
    Code:
    ffmpeg -hide_banner -ss 00:59:30 -i %%f -c copy -avoid_negative_ts make_zero -y "./out/tmp2.mp4"
    Quote Quote  
  11. Member jraju's Avatar
    Join Date
    Mar 2013
    Location
    India
    Search Comp PM
    thanks butterw. for the explanation of time stamp
    i heard that ffmpeg would work on even non key frame, on editing unlilke other utility
    taken from stackoverflow
    With the mp4 container it is possible to cut at a non-keyframe without re-encoding using an edit list. In other words, if the closest keyframe before 3s is at 0s then it will copy the video starting at 0s and use an edit list to tell the player to start playing 3 seconds in.
    and so I think this will work find if i just change the hide banner lilne as you suggested.
    so any mid conversation miss may be avoided
    Avidemux on the other hand only woks on key frame and manually seeing it , willl be very difficult.
    Could you say,how to find the key frames in a video
    Quote Quote  
  12. You can cut on any frame with many tools, but it requires re-encoding, there isn't any practical way around this.

    Very few players, if any, support edit-lists in a way that would be useful AFAIK.

    Ffmpeg uses time-based cutting parameters, it's not simple to cut on a precise frame with lossless cutting. The time used by ffmpeg seems to match the one displayed by virtualdub2.

    In the end (keyframe or not) you still need to know where to cut.

    The best quality result will be obtained manually in Avidemux with the method already described (seek to keyframes with the arrow keys). It shouldn't take more than 1min per file once you get the hang of it.
    Last edited by butterw; 16th Jan 2021 at 07:13.
    Quote Quote  
  13. Member jraju's Avatar
    Join Date
    Mar 2013
    Location
    India
    Search Comp PM
    Hi, thanks all for the solution and codes.
    Jagabo tips of up and downarrow fixed my correct copying . thanks once again
    Last edited by jraju; 16th Jan 2021 at 20:56.
    Quote Quote  
  14. Member jraju's Avatar
    Join Date
    Mar 2013
    Location
    India
    Search Comp PM
    hi, how can i be sure, that i copied the portion of video in the middle and copied to the keyframe by using up and down arrow, that is no video frame is missing on continuation of the second part
    Or in otherwords,
    can i use the overlap technique to copy the A and B points and have a minute or two from the part i be added to the second part without resorting to again finding another a and b parts to process the second part.
    The technique was given with the bat file by using ffmpeg bat.
    can i do this in avidemux, Hi, butterw and jagabo
    the procedure I adopted.
    open the video,use up arrow to find the first keyframe A, and move to B point, and then if alert prompt that the selected point is not on keyframe, just use down arrow to the previous keyframe to fix AB, and then select a mid point and then copy and if there is an alert again about nonkeyframe selection, just use the down arrow to the previous keyframe on the middle part and then paste it , reset AB to finally save the full video without reencoding.
    Last edited by jraju; 18th Jan 2021 at 17:28.
    Quote Quote  
  15. Why are you ruining all your files when you can get a standalone media player with a resume function for about US$35?
    Quote Quote  
  16. Member jraju's Avatar
    Join Date
    Mar 2013
    Location
    India
    Search Comp PM
    Hi, jagabo, thanks for the answer. I do not want to use a stand alone media player. The tv has inbuilt player ofcourse, with limited functionality.
    is the overlap technique possible with avidemux is the query
    Quote Quote  
  17. Originally Posted by jraju View Post
    is the overlap technique possible with avidemux is the query
    Of course. You already know how to copy a segment and paste it somewhere else. So you already know how to create an overlap.
    Quote Quote  
  18. In Avidemux either non-overlap (or overlap) are possible without re-encoding.

    I'm currently writing an Avidemux script that can insert a segment at the chosen keyframe position in the loaded video then saves (it splits without overlap).
    Not all Avidemux commands can be used in a script, but it isn't difficult to use: https://avidemux.org/smif/index.php/topic,19390.0.html
    Quote Quote  
  19. Member jraju's Avatar
    Join Date
    Mar 2013
    Location
    India
    Search Comp PM
    hI, BUTTERW,
    please say, in my following lines
    open the video,use up arrow to find the first keyframe A, and move to B point, and then if alert prompt that the selected point is not on keyframe, just use down arrow to the previous keyframe to fix AB, and then select a mid point and then copy and if there is an alert again about nonkeyframe selection, just use the down arrow to the previous keyframe on the middle part and then paste it , reset AB to finally save the full video without reencoding.
    ,,,,,,, that the video will run the second part without any frame being missed.
    if that is sure, then , I will close the thread.
    why I asked about possible overlapping ideas,
    is that no frame is getting missed while segmenting and copying and saving the new file
    because, the whole video contains keyframes and non keyframes , my doubt being if a non keyframe is pushed to previous keyframe, there may be more than one number of frames , that it may be pushed back to get in to the previous keyframe.
    Jagabo, thought, that i unncessarily prolong this thread with knowing the procedure, but this is the forum where i could get the correct answer to my satisfaction.
    May be, I lack in asking to a correct terminology
    please also say, which number of posts in the link , i could use
    Last edited by jraju; 20th Jan 2021 at 00:21.
    Quote Quote  
  20. As long as markerA (used for copy) and your insertion point are both keyframes you should be fine. If a non-keyframe has been dropped it's unlikely you would notice watching it.
    The best way to test for dropped frames would be to use a video encoded with a known number of frames and the frame number hardcoded (which your video obviously hasn't got).

    Avidemux displays a lot of warnings by default, but you can change this in the preferences to display only actual Errors.
    Quote Quote  
  21. Member jraju's Avatar
    Join Date
    Mar 2013
    Location
    India
    Search Comp PM
    Hi, butterw,
    thanks for the information. I also selected B in keyframe, as I explained by using down button if alert comes .
    The insertion point is also on keyframe.
    The best way you suggested is a good cllue.
    But, when I copy the segment, naturallly the duration, as also the frames are bound to increase. The duration is noticeable in explorer.
    But regarding the dropped frames from the original, if any, I have to count the no of frames within AB +orignial no of frames.
    There is the problem of counting AB as it varies with each episode and also it is done onavidemux process page.
    You have suggested a script link, which you say, that would copy a segment without missing of any frame. which no of post in the link gives that . in the link.
    Quote Quote  
  22. Member jraju's Avatar
    Join Date
    Mar 2013
    Location
    India
    Search Comp PM
    Hi, butterw,
    the orignal video duration is 2:02:14 or 7334 seconds,fps 25 , multiplying I get 183350 total frames
    the revised video duration 2:06:51 or 7611 seconds , fps 25 , i get, 190275,
    duration difference 4 min 37 seconds , containing 6925 at fps 25
    Is this the way, one calculate the video frames, if the fps is constant
    Is this the way to find out the segment duration and length of frames
    looks like more cumbersome calculation to know if any missing frame or dropped frame.
    Quote Quote  
  23. I'm not sure what reported information you can really trust.
    fps=25 is likely just an approximation (which may hold true in the case of your file).
    Quote Quote  
  24. Yes, if the frame rate is constant

    Code:
    FrameRate * RunningTime = NumberOfFrames.
    Note that your running times appear to be rounded (or truncated) to the nearest second. So the calculations may be off by as much as 25 frames.

    And there are other complicating issues. A video segment can start with negative time codes (not displayed frames), open GOPs can lead to extra frames that aren't displayed, etc.
    Quote Quote  
  25. @25fps one frame lasts just 0.040s.
    @60fps it's only 16.667ms.
    Quote Quote  
  26. Member jraju's Avatar
    Join Date
    Mar 2013
    Location
    India
    Search Comp PM
    I have used the ffprobe command taken from one of the thread and it shows , the frame number of the original file as 183357
    the formula is
    ffprobe -v error -count_frames -select_streams v:0 -show_entries stream=nb_read_frames video.mp4
    and the revised mp4 after adding segments is 190286
    the difference is 6929.
    is the frame using the formula would correct the count to the ms milliseconds
    but how do i find , the dropped frames
    Quote Quote  
  27. You could save the added segment on its own and count its number of frames:
    Set A, B (same frame as when you cut) > Save.
    Quote Quote  
  28. Member jraju's Avatar
    Join Date
    Mar 2013
    Location
    India
    Search Comp PM
    Hi, butterw,
    I think your latest bat file is the only way to accomplish what i want , for viewing the video frames without missing anything.
    This is because, , when i save the AB, while processing , and copying and pasting, with the next , or previous available fey frames, it misses some frames, because, when i manually went back from frame by frame, the previous keyframe , it has more number of individual frames.
    Kindly confirm, the second bat file you recommended (not going to the avidemux and copying the AB) irrespective any mid conversation auto cut thro the bat at fixed hh mm ss ms,
    the bat also gives the overlap of previous frames while it adds the second part ,. So there is no missing or dropping frames.
    Hi, butterw, please only confirm that your second bat file, would capture a few scene of the first part also, so , i will not miss anything in the viewing, though there may be sudden end of conversation in the first part.
    Manually fixing is bound to get dropped frames, which could not be manually seen.
    please confirm,
    I also asked the exact link, in which you have given the code for no loss video bat script in your given link. i saw , number of codes, and please speficy the exact code link
    Quote Quote  
  29. Member jraju's Avatar
    Join Date
    Mar 2013
    Location
    India
    Search Comp PM
    Hi, butterw, I meant your script on post 66.
    is that enough, or you have made some changes in the script link
    Quote Quote  
  30. Lossless Insert tools (h264, closed-gop)

    The latest released versions of my scripts are in this directory: https://github.com/butterw/bShaders/tree/master/test_LimitedRange
    The ffmpeg ffm_Insert.bat script provided in #65 has not be updated, it seemed to work fine.
    You can ensure you don't lose any meaningful part by specifying overlap of say 1min. The issue with it is that you have to specify the cut time (ex: 1 hour) and this cut may occur mid-conversation. If you had chapters, cutting using their timestamps would be a better option.

    I have now also released bInsert.py a script for avidemux GUI, which can automatically insert a (must be compatible) video at the chosen keyframe location. The advantage of using avidemux is that you have a preview of where the insert happens, also it is easy to select a keyframe (ensuring no-overlap). From my testing there are no lost (or added) frames.

    Having looked it into it a bit more, it may be useful to clarify how Avidemux works:
    - Actual position auto-snaps to keyframes when you use the mouse. It will play from this keyframe, when you preview.
    - You can use up/down arrows or <<, >> to seek to the previous/next keyframe.
    - In Copy mode, if markerA isn't on a keyframe it will save from the previous keyframe (like ffmpeg does)

    For testing purpose a short clip with the following characteristics may prove useful:
    - x264 closed-gop mp4, with known encoding parameters
    - constant frame rate: 25fps (or 50fps)
    - clip1: single scene, keyframe forced every 100 frames
    - clip2: scene changes, with a keyframe on each of them
    - 80s duration (@25fps = 2000frames)
    - hardcoded overlay of frame type (ex:keyframe) and timestamps
    Last edited by butterw; 23rd Jan 2021 at 05:05.
    Quote Quote  



Similar Threads

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