2

I have been looking at different video cutting command line tools for Linux and I can't seem to find any which supports the operation of cutting a video from the end.

For example, i have 10 videos of variable length. I need to obtain the last 3 seconds of each video.

I looked into ffmpeg and mpgtx but to no avail.

Can someone tell me the tool/command to cut the video from end position?

Any help is much appreciated.

2
  • What have you tried with ffmpeg? ffmpeg is suitable for this. Unfortunately a "last seconds" option does not exist, but you can use the -ss (time offset) and -t (duration) options to get the last 3 seconds.
    – llogan
    Commented Feb 11, 2013 at 8:12
  • I tried the -t option, but couldn't get it working for the last 3 seconds, hence the question.
    – user125883
    Commented Feb 11, 2013 at 16:36

1 Answer 1

4

Following could be not the most elegant way to do that, but it works.

Insert filename to variable for convenience:

file="yourvideo.avi"

Get length of the video -3 seconds (-3 is set in sed command – we cut ID_LENGTH= and add -3 at the end):

start=$(mplayer -identify -vo dummy -ao dummy -really-quiet "$file" 2>/dev/null | sed -n '/ID_LENGTH=/s/ID_LENGTH=\(.*\)/\1-3/p' | bc)

You can do the same thing with avprobe or ffprobe (which come with avconv or ffmpeg):

start=$(avprobe -i "$file" -show_format 2> /dev/null | sed -n '/duration=/s/duration=\(.*\)/\1-3/p' | bc)

Cut with FFmpeg (ffmpeg) or Libav (avconv) with the starting position of $start:

avconv -ss $start -t 3 -i $file -vcodec copy -acodec copy end_${file}
0

You must log in to answer this question.