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 Answer
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.
-
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 toavconv -i input.webm
.– DiggerJul 9, 2016 at 2:15 -
-
@v010dya
bash: let: A=: syntax error: operand expected (error token is "=")
– voicesSep 28, 2016 at 4:12