将视频扩展(扩展)到特定的持续时间 [英] Expand (extend) a video to an specific duration
问题描述
执行 VLC 或 AVconv )具有强制持续时间的任何功能一段视频到一定秒数?
Do VLC or FFmpeg (or AVconv) have any feature to force the duration of a video to a certain number of seconds?
假设我有一个5分钟的.mp4视频(无音频).有没有一种方法可以使上述工具将"视频扩展到更长的时间?该视频来自Power Point幻灯片,但太短了(可以说运行得太快了).这个想法将自动插入帧,使其达到指定的持续时间.看起来好像很可行(嗯……对于我来说,是视频编码/转码的新手):5分钟的视频,以30fps的速度表示我有9000帧...要使其长10倍,请第一个真实"框架,将其复制十次,然后获取第二个真实"框架,将其复制十次,依此类推.
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.
我正在使用Ubuntu 12.04,但是如果需要,我可以安装/编译任何必需的软件.到目前为止,我有VLC,AVConv和FFmpeg(FFmpeg位于特定文件夹中,因此不会与AVConv冲突)
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)
谢谢.
推荐答案
使用 setpts ffmpeg
中的视频过滤器.简单的例子:
Use the setpts video filter in ffmpeg
. Simple examples:
- 慢速(半速):
setpts=PTS*2
或setpts=PTS/0.5
- 快速(2x):
setpts=PTS/2
或setpts=PTS*0.5
- Slow (half speed):
setpts=PTS*2
orsetpts=PTS/0.5
- Fast (2x):
setpts=PTS/2
orsetpts=PTS*0.5
ffmpeg -i input.mp4 -filter_complex "setpts=PTS/10" output.mp4
音频和视频的速度提高10倍
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
将视频与音频持续时间匹配
在此示例中,audio.wav
持续时间为30秒,video.mp4
持续时间为90秒.
Matching video to audio duration
In this example audio.wav
duration is 30 seconds and video.mp4
is 90 seconds.
-
获取持续时间音频和视频文件:
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
使用 setpts 视频过滤器来调整视频以匹配音频时长.
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
将视频调整为特定时间
在此示例中,输入为120秒.所需的输出是30秒:
Fit video into specific time
In this example the input is 120 seconds. Desired output is 30 seconds:
-
获取持续时间输入文件:
ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 input.mp4
Use setpts and atempo (or rubberband) filters:
ffmpeg -i input.mp4 -filter_complex "setpts=PTS/(120/30);atempo=120/30" output.mp4
这篇关于将视频扩展(扩展)到特定的持续时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!