我正在尝试使用 ffmpeg 将视频片段连接到一些黑屏。要做到这一点,我首先生成一个空白的10秒视频(没有音轨):
$ ffmpeg -f lavfi -i color=black:s=320x240:r=1 -f lavfi -i anullsrc -t 10 -vcodec libvpx -an blank.mkv
然后我在 input.txt 文件(下面的内容)中创建了最简单的场景,以便有三秒黑屏,然后是一些视频(没有音轨):
file 'blank.mkv'
duration 3
file 'video_example.mkv'
最后,运行以下ffmpeg命令来连接该输入文件的内容:
$ ffmpeg -f concat -i input.txt -codec:v copy -codec:a copy output.mkv
我遇到的问题是duration 3
未被考虑,因此最终视频仍然有十秒的黑帧(而不是三帧),然后是我的视频。此外,在文件中使用duration x
时,还会显示“输出流0:0 ...”中的非单调DTS消息。如果我删除持续时间警告已经消失,并且也会获得10秒黑屏首先输出。
ffmpeg concat命令的完整输出:
$ ffmpeg -hide_banner -f concat -i input.txt -codec:v copy -codec:a copy output.mkv
Input #0, concat, from 'input.txt':
Duration: N/A, start: 0.000000, bitrate: N/A
Stream #0:0: Video: vp8, yuv420p(progressive), 320x240, SAR 1:1 DAR 4:3, 1 fps, 1 tbr, 1k tbn, 1k tbc
Metadata:
ENCODER : Lavc57.107.100 libvpx
DURATION : 00:00:10.000000000
File 'output.mkv' already exists. Overwrite ? [y/N] y
Output #0, matroska, to 'output.mkv':
Metadata:
encoder : Lavf57.83.100
Stream #0:0: Video: vp8 (VP80 / 0x30385056), yuv420p(progressive), 320x240 [SAR 1:1 DAR 4:3], q=2-31, 1 fps, 1 tbr, 1k tbn, 1k tbc
Metadata:
ENCODER : Lavc57.107.100 libvpx
DURATION : 00:00:10.000000000
Stream mapping:
Stream #0:0 -> #0:0 (copy)
Press [q] to stop, [?] for help
[concat @ 000000000031a440] DTS 3000 < 9000 out of order
[matroska @ 0000000000328420] Non-monotonous DTS in output stream 0:0; previous: 9000, current: 3000; changing to 9000. This may result in incorrect timestamps in the output file.
[matroska @ 0000000000328420] Non-monotonous DTS in output stream 0:0; previous: 9000, current: 4001; changing to 9000. This may result in incorrect timestamps in the output file.
[matroska @ 0000000000328420] Non-monotonous DTS in output stream 0:0; previous: 9000, current: 4998; changing to 9000. This may result in incorrect timestamps in the output file.
[matroska @ 0000000000328420] Non-monotonous DTS in output stream 0:0; previous: 9000, current: 6004; changing to 9000. This may result in incorrect timestamps in the output file.
[matroska @ 0000000000328420] Non-monotonous DTS in output stream 0:0; previous: 9000, current: 7002; changing to 9000. This may result in incorrect timestamps in the output file.
[matroska @ 0000000000328420] Non-monotonous DTS in output stream 0:0; previous: 9000, current: 8005; changing to 9000. This may result in incorrect timestamps in the output file.
frame= 5794 fps=0.0 q=-1.0 Lsize= 7109kB time=01:37:09.70 bitrate= 10.0kbits/s speed=5.16e+004x
video:7043kB audio:0kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.926229%
知道我做错了什么吗?警告似乎暗示了这个问题。
其他可能有用的信息:
$ ffprobe -hide_banner blank.mkv
Input #0, matroska,webm, from 'blank.mkv':
Metadata:
ENCODER : Lavf57.83.100
Duration: 00:00:10.00, start: 0.000000, bitrate: 1 kb/s
Stream #0:0: Video: vp8, yuv420p(progressive), 320x240, SAR 1:1 DAR 4:3, 1 fps, 1 tbr, 1k tbn, 1k tbc (default)
Metadata:
ENCODER : Lavc57.107.100 libvpx
DURATION : 00:00:10.000000000
$ ffprobe -hide_banner video_example.mkv
Input #0, matroska,webm, from 'video_example.mkv':
Metadata:
encoder : GStreamer matroskamux version 1.8.1.1
creation_time : 2018-05-04T17:57:04.000000Z
Duration: 01:37:08.70, start: 15434.269000, bitrate: 9 kb/s
Stream #0:0(eng): Video: vp8, yuv420p(progressive), 320x240, SAR 1:1 DAR 4:3, 1 fps, 1 tbr, 1k tbn, 1k tbc (default)
Metadata:
title : Video
$ ffmpeg -v
ffmpeg version 3.4.2 Copyright (c) 2000-2018 the FFmpeg developers
built with gcc 7.3.0 (GCC)
答案 0 :(得分:1)
对于视频和音频文件,必须使用inpoint / outpoint。
file 'blank.mkv'
outpoint 3
file 'video_example.mkv'
duration
对单张图片非常有用,例如制作幻灯片时,或原始音频/视频流,其中ffmpeg无法可靠地发现媒体持续时间。