Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Expand (extend) a video to an specific duration [closed]

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.

like image 702
BorrajaX Avatar asked Feb 08 '13 22:02

BorrajaX


Video Answer


1 Answers

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
    
like image 70
llogan Avatar answered Sep 28 '22 09:09

llogan