VideoHelp Forum

Our website is made possible by displaying online advertisements to our visitors. Consider supporting us by disable your adblocker or Try ConvertXtoDVD and convert all your movies to DVD. Free trial ! :)
+ Reply to Thread
Results 1 to 1 of 1
Thread
  1. Member Budman1's Avatar
    Join Date
    Jul 2012
    Location
    NORTHWEST ILLINOIS, USA
    Search Comp PM
    Recently I had a request for a batch file that would trim a certain length (3 minutes in this case) from a folder of videos were of varying lengths but always have the last 3 minutes cut off. (Removing credits???) Anyway I altered a script originally from an unknown author on Stack Overflow and created a batch file and tested on several files. Although this is an unusual need, it is difficult if movies are of unknown and different lengths and maybe it will help others who need it.

    I used MediaInfoCLI.exe and MediaInfo.dll in the folder with the videos to pull the duration in time format and ran that following .BAT file from that folder. If the file is unexpectedly less than 3 minutes, the CMD window throws an error and does not copy the file but continues on for the rest of the files. All videos are copied with codec copy and have OUT appended to the name so the originals are never overwritten, but it is always a good idea to use copies before you edit...

    Code:
    @echo off
    setlocal enabledelayedexpansion
    for %%z in (*.mp4,*.flv) do (
    mediainfo --Inform=General;%%Duration/String3%%:\r\n %%z > Duration.txt
    echo video %%z
    setlocal enabledelayedexpansion
    
    rem Get start time:
    set TrmTime="00:03:00.000"
    for /F "tokens=1-4 delims=:.," %%a in (!TrmTime!) do (
    set /A "start=((((%%a*3600)+%%b*60)+%%c)*1000)+%%d" 
    echo start !start!
    )
    
    rem Any process here...
    
    rem Get end time:
    for /F "tokens=1-4 delims=:.," %%a in ('findstr /I ":" "Duration.txt"') do (
    set /A "end=((((%%a*3600)+%%b*60)+%%c)*1000)+%%d" 
    echo end !end! 
    )
    
    rem Get elapsed time:
    set /A "elapsed=end-start"
    echo elapsed !elapsed!
    
    Rem Show_elapsed_time:
    set /A "hh=elapsed/(60*60*1000)"
    set /A "rest=!elapsed! %%(60*60*1000)"
    set /A "mm=!rest! /(60*1000)"
    set /A "rest=!elapsed! %%(60*1000)"
    set /A "ss=!rest!/1000"
    set /A "cc=!rest! %%1000"
    
    echo !hh!:!mm!:!ss!.!cc!
    set "time=!hh!:!mm!:!ss!.!cc!"
    echo time !time!
    
    ffmpeg -i %%z -to !time! -c copy out%%~nxz
    )
    Last edited by Budman1; 7th Apr 2018 at 01:22. Reason: Give credit for original script
    Quote Quote  



Similar Threads