9

Do VLC or FFmpeg (or AVconv) have any feature to force the duration of a video to a certain number of seconds?

Let's say I have a... 5 minutes .mp4 video (without audio). Is there a way to have any of the aforementioned tools "expanding" the video to a longer duration? The video comes from a Power Point slideshow, but it's too short (running too fast, to say so). The idea would be automatically inserting frames so it reaches an specified duration. It looks like something pretty doable (erm... for a total newbie in video encoding/transcoding as I am): A 5 minutes video, at 30fps means I have 9000 frames... To make it be 10 times longer, get the first "real" frame, copy it ten times, then get the second "real" frame, copy it ten times... and so on.

I'm using Ubuntu 12.04, but I can install/compile any required software, if needed. So far, I have VLC, AVConv and FFmpeg (FFmpeg in an specific folder, so it won't conflict with AVConv)

Thank you in advance.

3
  • 1
    Please, in the future, ask questions about FFmpeg CLI on Super User. I've voted to migrate it there.
    – slhck
    Feb 9, 2013 at 10:24
  • Ah, sorry about that. I was actually wondering if stack overflow was the right place to ask this, and since I saw the "ffmpeg" and "vlc" tags I thought it would be ok, but thanks for clarifying.
    – Savir
    Feb 9, 2013 at 16:39
  • SO usually just deals with the FFmpeg API questions, e.g. when using it with some kind of programming language—or with PHP, as many people seem to do. I don't know why your question wasn't migrated, sorry about that.
    – slhck
    Feb 9, 2013 at 16:50

1 Answer 1

19

Use the setpts video filter in ffmpeg. Simple examples:

  • Slow (half speed): setpts=PTS*2 or setpts=PTS/0.5
  • Fast (2x): setpts=PTS/2 or setpts=PTS*0.5

10x speed increase for video

ffmpeg -i input.mp4 -filter_complex "setpts=PTS/10" output.mp4

10x speed increase for both audio and video

For audio use the atempo, rubberband, or asetrate audio filters.

ffmpeg -i input.mp4 -filter_complex "[0:v]setpts=PTS/10[v];[0:a]atempo=10[a]" -map "[v]" -map "[a]" output.mp4

Matching video to audio duration

In this example audio.wav duration is 30 seconds and video.mp4 is 90 seconds.

  1. Get the duration of the audio and video files:

     ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 audio.wav
     ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 video.mp4
    
  2. Use the setpts video filter to adjust the duration of the video to match the audio duration.

     ffmpeg -i video.mp4 -i audio.wav -filter_complex "[0:v]setpts=PTS*30/90[v]" -map "[v]" -map 1:a -shortest output.mp4
    

Fit video into specific time

In this example the input is 120 seconds. Desired output is 30 seconds:

  1. Get the duration of the input file:

    ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 input.mp4
    
  2. Use setpts and atempo (or rubberband) filters:

    ffmpeg -i input.mp4 -filter_complex "setpts=PTS/(120/30);atempo=120/30" output.mp4
    
2
  • The question asks for a 10X slow down of the video, and this answer describes a 10X speed up. atempo has a range of 0.5-100, so speeding up 10x is no issue, yet slowing down 10x is. It would be nice to see an additional answer, or update.
    – a.t.
    Jul 28, 2022 at 5:48
  • doesnt answer the question and the commands given can't be used for the inverse. You receive and out of range error.
    – Airfield20
    Jun 6, 2023 at 4:04

Not the answer you're looking for? Browse other questions tagged or ask your own question.