I have several training videos. All .MP4s.
I want to remove 3.5 seconds from the beginning and 4.5 seconds from the end of the entire folder of them...
I know of
I solved it. I don't mind helping you, but I'm not going to provide the full solution. I will, however, give you hints with the trickiest parts. I'll leave it up to you to fill in the blanks.
ffmpeg
will let you do what you want. The -ss
switch specifies the start position. -t
specifies duration. Unfortunately, there's no switch or program substitution variable that'll internally perform the needed math on the video length to trim-right. You'll have to compute that via scripting.
First you'll need the total length of the unmodified video:
for /f "tokens=2" %%x in (
'2^>^&1 ffmpeg -i "%%~fI" ^| find /i "duration"'
) do set "length=%%x"
To calculate the value for the -t
switch, you can invoke PowerShell to determine newLength = totalLength - (leftTrim + rightTrim). Here's the secret sauce:
powershell "'{0}' -f ([timespan]'%length:,=%').add([timespan]::fromseconds(-(%trim-left% + %trim-right%)))"
Once you get your target length calculated, plug it into ffmpeg
like this:
ffmpeg -i "%%~fI" -ss %trim-left% -t %target_length% -c:v copy -c:a copy "%destination-dir%\%%~nxI"