I have tried looking up a solution but all of them involve copying, say 10 seconds from 00:00:00 of the video instead of removing enough of the video starting from the end to leave only 10 seconds remaining. I have a bunch of videos that I needs exactly 18 seconds removed from the end but the total duration varies from videos to video. Is this not possible to automate using ffmpeg or some other program?

  • The command ffmpeg -i VideoFile 2>&1|grep Duration, will give the length of the video, and you can do some arithmetic on the result to subtract 18 seconds to work out the length you need (a lot easier in bash than cmd!).
    – AFH
    Dec 22, 2017 at 22:22
  • I will try this out as well. Thanks! Does bash allow looping?
    – Icarus
    Dec 22, 2017 at 22:30
  • Yes, of course: for and while are the basic loop commands, with variants select and until.
    – AFH
    Dec 23, 2017 at 12:57
  • @AFH Using ffprobe is better for getting duration than ffmpeg, because the output from ffmpeg was not designed or intended for machine parsing.
    – llogan
    Dec 23, 2017 at 19:00

1 Answer 1


See Using ffmpeg to cut up video for answers on how to use ffmpeg to cut videos, with the -ss and -t flags.

To get you video duration you can use: ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 video.mp4 as seen on http://superuser.com/questions/650291/ddg#945604

So by combining both things you could do -t $(( $(ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 video.mp4 |cut -d\. -f1) - 18 )) to have a duration equal to the previous one minus 18 seconds.

  • I will try this out. I didn't know ffprobe was a thing. Will ffprobe return time in HH:mm:ss.xxx format. I believe in the post you linked the answer mentions that time format is important.
    – Icarus
    Dec 22, 2017 at 22:22
  • ffprobe is very useful and can do many things. Called like written it gives the duration as 1234.56 (seconds) from which thecut retains only the integer part in order to remove 18. If you use HH:MM:SS the computation will be more complex. But indeed, try the results of your chopped video before removing original as it could be more or less what you want depending on a lot of stuff, including the encoding and format of original file. Dec 22, 2017 at 22:33
  • ffmpeg command accept timestamps both as HH:MM:SS.sssss format and as SSSSSS.ss format, so you are free to use the one most suited to the task at hand. And note that you probably could do the same thing, but different syntax, with mplayer/mencoder, among other choices. Dec 22, 2017 at 22:45
  • I will give this a shot and report back. Thanks!
    – Icarus
    Dec 22, 2017 at 22:47
  • 1
    Like the questioner, I didn't know about ffprobe, so thanks for that. Note that you can retain the sub-second resolution with -t $(bc <<< $(ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 Kon-Tiki.mp4)-18) (or the equivalent using calc). As an aside, if you don't specify output formatting then the outputs of ffprobe and ffmpeg -i are virtually identical, with both outputs on stderr.
    – AFH
    Dec 23, 2017 at 14:01

You must log in to answer this question.

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