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

旧街凉风 提交于 2020-03-16 06:02:24

问题


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.


回答1:


Use the setpts video filter in ffmpeg.

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

Example: 10x speed increase for video

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

Example: 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

  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
    

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

  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
    


来源:https://stackoverflow.com/questions/14782077/expand-extend-a-video-to-an-specific-duration

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!