问题
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
orsetpts=PTS/0.5
- Fast (2x):
setpts=PTS/2
orsetpts=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
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 andvideo.mp4
is 90 seconds.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