8

This is what I have so far:

for i in *.mp4; do ffprobe -show_format -i "%i"

// get duration, then need to somehow subtract 30 seconds, and marry these two commands

ffmpeg -ss 0 -i "$i" -t %duration% "${i%.mp4}-cut.mp4

I thought it would be simple, ugh.. why you no have -endtrim switch, ffmpeg? or does it? Maybe another command line one like this can?

1
  • If you have found a solution to your question, please post it as an answer.
    – Ambo100
    Apr 21, 2014 at 19:38

3 Answers 3

6

Post on behalf of the OP who solved the problem themselves:

_trim.bat:

@echo off
for %%i in (*.mp4) do (
call _trim2.bat "%%i"
)

_trim2.bat:

@echo off
for /f "tokens=*" %%a in ('_ffprobe -show_format -i %1 ^| find "duration"') do set _duration=%%a
set _duration=%_duration:~9%
for /f "delims=. tokens=1*" %%b in ('echo %_duration%') do set /a "_durS=%%b"
for /f "delims=. tokens=2*" %%c in ('echo %_duration%') do set "_durMS=%%c"
rem following line is seconds to cut
set /a "_durS-=30"
set "_newduration=%_durS%.%_durMS%"
set "_output=%~n1"
md _fixed
_ffmpeg -ss 0 -i %1 -t %_newduration% -c copy "_fixed\%_output%.mp4"

the processed filed will be put in .\_fixed\samename.mp4 and will all be 30 seconds shorter.

2
  • More than 8 years later, and it still work like a charm. Thank you so much, Sir. At least for me as the first time try to use batch file, I'd be glad if there is an explanation what it do. Such as what does tokens=* .... %_duration:~9% mean. (Need to google about that). The only thing I can understand is assumed the total video duration is 50secs... so my guess the _durMS value is 50, while the _durS value is -30. That makes _newduration ---> -30.50 = 20 secs which will be the output result. Thank you once again, Sir slhck.
    – karma
    Jul 6, 2022 at 20:47
  • 1
    @karma I only posted the solution on behalf of the original person asking the question. I have no experience with Windows batch scripts. durS is seconds and durMS is milliseconds. Then, 30 seconds are subtracted from durS to arrive at the new duration. durMS is kept as-is.
    – slhck
    Jul 7, 2022 at 7:29
0

I had to use this same exact method for some of files I have.

When I execute _trim2.bat it comes up with errors that Windows doesn't recognize _ffprobe and _ffmpeg (which of course it doesn't cause of underscores).

When I try to execute without underscores it gives an error for ffprobe and ffmpeg as following, respectively:

Missing argument for option 'i'
Unrecognized option '15.'.(duration is 15)
3
  • I am not sure whether this is an answer, or a follow-up issue. Aug 20, 2020 at 2:47
  • It is a follow up question.I wasn't able to make a comment
    – hacker red
    Aug 20, 2020 at 10:40
  • You should ask your own question, using the button at the top of the page and link back to this question using the URL. Aug 20, 2020 at 10:42
0

I hope this helps guys... Probably too late for the above scenario but who ever will search... good day

2
  • As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
    – Community Bot
    Apr 14, 2022 at 12:17
  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. - From Review
    – Toto
    Apr 14, 2022 at 13:37

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .