将视频扩展(延长)到特定时长 [英] Expand (extend) a video to an specific duration

查看:43
本文介绍了将视频扩展(延长)到特定时长的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

VLCFFmpeg(或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*2setpts=PTS/0.5
  • 快速 (2x):setpts=PTS/2setpts=PTS*0.5
  • Slow (half speed): setpts=PTS*2 or setpts=PTS/0.5
  • Fast (2x): setpts=PTS/2 or setpts=PTS*0.5
ffmpeg -i input.mp4 -filter_complex "setpts=PTS/10" output.mp4

音频和视频速度提高 10 倍

对于音频,请使用 atemporubberbandasetrate 音频过滤器.

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.

  1. 获取持续时间音频和视频文件:

 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:

    1. 获取持续时间输入文件:

    ffprobe -v error -show_entries format=duration -of default=noprint_wrappers=1:nokey=1 input.mp4
    

  • 使用 setptsatempo(或 rubberband) 过滤器:

  • Use setpts and atempo (or rubberband) filters:

    ffmpeg -i input.mp4 -filter_complex "setpts=PTS/(120/30);atempo=120/30" output.mp4
    

  • 这篇关于将视频扩展(延长)到特定时长的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆