如何在FFMPEG中设置视频的持续时间?

时间:2011-08-01 09:28:23

标签: ffmpeg

如何限制给定视频的视频时长。例如,如果我们上传一个不超过5分钟的视频,我需要FFMPEG中的元数据。您可以找到答案。

3 个答案:

答案 0 :(得分:37)

使用-t选项指定时间限制:

`-t duration'
    Restrict the transcoded/captured video sequence to the duration specified in seconds. hh:mm:ss[.xxx] syntax is also supported. 

http://www.ffmpeg.org/ffmpeg.html

答案 1 :(得分:0)

一个例子;

ffmpeg -f lavfi -i color=s=1920x1080 -loop 1 -i "input.png" -filter_complex "[1:v]scale=1920:-2[fg]; [0:v][fg]overlay=y=-'t*h*0.02'[v]" -map "[v]" -t 00:00:03 output.mp4

将最大时间设置为3秒。请注意,-t必须位于输出文件之前,如果您在此命令的开头设置它,即ffmpeg -t ....将不起作用。

答案 2 :(得分:0)

只是为了更详细的使用和示例而进一步阐述。

按照 FFMpeg Docs 中的规定


  • -t duration (输入/输出)

    • 当用作输入选项(在 -i 之前)时,
      • 限制从输入文件读取数据的持续时间。
      • 例如ffmpeg -t 5 -i input.mp3 testAsInput.mp3
        • 将在 5 秒后自动停止写入
    • 当用作输出选项时(在输出网址之前),
      • 在其持续时间达到持续时间后停止写入输出。
      • 例如ffmpeg -i input.mp3 -t 5 testAsOutput.mp3
        • 将在 5 秒后自动停止写入
    • 实际上,在这个用例中,结果是相同的。有关更广泛的用例,请参见下文。
  • -to position (输入/输出)

    • 停止在位置写入输出或读取输入。
    • 例如同上,但用 to 代替 t
  • durationposition 必须是持续时间规范,如 ffmpeg-utils(1) manual.

    中所指定
    • [-][HH:]MM:SS[.m...][-]S+[.m...][s|ms|us]
  • -to-t 互斥,-t 优先。


使用多个输入作为输入选项的示例

注意:-f pulse -i 1 是我的系统音频,-f pulse -i 2 是我的麦克风输入

假设我想不确定地同时录制我的麦克风和扬声器。(直到我用 Ctrl+C 强制停止)

ffmpeg \
-f pulse -i 1 \
-f pulse -i 2 \
-filter_complex "amix=inputs=2" \
testmix.mp3
  • 现在让我们想象一下,我只想录制系统音频的前 5 秒,并始终录制我的麦克风,直到我用 Ctrl+终止该进程>C).
ffmpeg \
-t 5 -f pulse -i 1 \
-f pulse -i 2 \
-filter_complex "amix=inputs=2:duration=longest" \
testmix.mp3

注意::duration=longest amix 选项无论如何都是默认的,所以真的不需要明确指定

  • 现在假设我想要与上述相同的内容,但将录制时间限制为 10 秒。以下示例将满足该要求:
ffmpeg \
-t 5 -f pulse -i 1 \
-t 10 -f pulse -i 2 \
-filter_complex "amix=inputs=2:duration=longest" \
testmix.mp3
ffmpeg \
-t 5 -f pulse -i 1 \
-f pulse -i 2 \
-filter_complex "amix=inputs=2:duration=longest" \
-t 10 testmix.mp3

注意:关于开始position搜索/寻求this answer,我做了一些调查,可能也有兴趣。

相关问题