3

I have some videos of different duration.I want to cut(remove) the last 5 seconds of all videos.Can i use 'ffmpeg' in a loop to trim the videos?please help me.

1

1 Answer 1

2

This will get you the duration of your file in seconds:

let A=$(avprobe input.webm 2>&1 | grep "^ *Duration: " | sed "s/^ *Duration: \\([0-9:]*\\).*/(((\\1)/" | sed "s/0\\([0-9]\\)/\\1/g" | sed "s/:/)*60+/g")

Although avprobe does return the fractions of the seconds, bash doesn't deal with fractions. So i'm just dropping everythinging that is less than 1 second.

After that you can easily do something like this:

let A=$A-5
avconv -i input.webm -t $A -c:v copy -c:a copy output.webm

Sorry for not using ffmpeg. I've switched to avconv a while ago, i believe that the options should be the same, and if not, it should be trivial to rewrite them as needed.

After this the question is only in wrapping the whole thing in the for loop and doing all the files at once.

3
  • FYI, for my version of avconv (0.8.6-1 (Debian Squeeze)), I needed to, in the final command shown above, change the beginning string of said command to avconv -i input.webm.
    – Digger
    Jul 9, 2016 at 2:15
  • @v010dya What does let do? What is a *.webm?
    – voices
    Sep 28, 2016 at 3:04
  • @v010dya bash: let: A=: syntax error: operand expected (error token is "=")
    – voices
    Sep 28, 2016 at 4:12

You must log in to answer this question.

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