VideoHelp Forum




+ Reply to Thread
Results 1 to 3 of 3
  1. Member
    Join Date
    Mar 2022
    Location
    Sweden
    Search Comp PM
    I have recorded some videos with the same length of 40 seconds. I have old videos with the same name but the length varies between 28-38 seconds. I want the new videos to be cut to the same length as the old ones. The new and old has the same names. It's only the end of the video that has to be cut. Is it possible with a script using ffmpeg?

    Anyone could please provide script for doing this?


    I'd have to get the length of the old video then cut the new video with same name to the same length as the old. Currently I use this script for cutting a video to 30 seconds.

    @echo off
    for %%a in ("*.mp4") do ffmpeg -ss 0 -to 30 -i "%%a" "converted\%%~na.mp4"

    Need to replace 30 seconds with a parameter.
    Thanks
    Quote Quote  
  2. Member Budman1's Avatar
    Join Date
    Jul 2012
    Location
    NORTHWEST ILLINOIS, USA
    Search Comp PM
    I will assume the are in different directories since they are the same name. You can probably use ffprobe to get the original videos length and pipe it to a duration.txt file. Then set the file contents as a variable and use in your copy/cut line.
    Quote Quote  
  3. You can get the length of a video into an environment variable with ffprobe and the following:

    Code:
    ffprobe.exe -v quiet -show_entries stream=duration -of default=noprint_wrappers=1:nokey=1 -select_streams v:0 %1 >duration.txt
    set /p duration=<duration.txt
    del duration.txt
    You can then use ffmpeg to cut to that duration with "-ss 0 -to %duration%":

    Code:
    ffmpeg -i input.mp4 -ss 0 -to %duration% output.mp4
    Quote Quote  



Similar Threads

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