Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question
    
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. –  LordNeckbeard Feb 11 '13 at 8:12
    
I tried the -t option, but couldn't get it working for the last 3 seconds, hence the question. –  user125883 Feb 11 '13 at 16:36
add comment

1 Answer

up vote 3 down vote accepted

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}
share|improve this answer
    
Oh, thanks for clarification. –  Queeq Feb 11 '13 at 8:11
    
Thank you. Neat workaround. –  user125883 Feb 11 '13 at 16:37
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.