ffmpeg-video trim from the end of the video

5,068

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.

Share:
5,068

Related videos on Youtube

user241329
Author by

user241329

Updated on September 18, 2022

Comments

  • user241329
    user241329 almost 2 years

    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.

  • Digger
    Digger almost 8 years
    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.
  • voices
    voices over 7 years
    @v010dya What does let do? What is a *.webm?
  • voices
    voices over 7 years
    @v010dya bash: let: A=: syntax error: operand expected (error token is "=")