FFmpeg 问题:encode/normalize 然后连接多个视频

FFmpeg problems: encode/normalize then concat multiples videos

我想:

我需要分两步完成操作。我阅读了很多帖子,但未能找到正确的解决方案。
这些视频来自不同的来源,因此具有不同的编码设置。

要对视频进行编码,我使用以下命令:

ffmpeg -i input.1.mp4 -vcodec libx264 -acodec aac -pix_fmt yuv420p-vf scale=1920:-2, drawtext=fontfile=./roboto.ttf: fontsize=40: text='ABC': x=(w-text_w)-w/20: y=(h-text_h)-h/20 -y export/out.1.mp4

为了连接我试过:

ffmpeg -safe 0 -f concat -i <(find ./export/ -type f -printf "file '$PWD/%p'\n" | sort) -c copy concat.out.mp4

但我有很多这样的警告,结果视频有问题:

Non-monotonous DTS in output stream 0:0; previous: 2362816, current: 1624899; changing to 2362817. This may result in incorrect timestamps in the output file.

一小部分编码视频信息:

  Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, smpte170m), 1920x1080 [SAR 1:1 DAR 16:9], 4138 kb/s, 30 fps, 30 tbr, 15360 tbn (default)
  Stream #1:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, smpte170m), 1920x1080 [SAR 1:1 DAR 16:9], 5241 kb/s, 30.04 fps, 30.04 tbr, 22500 tbn (default)
  Stream #2:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, smpte170m), 1920x1080 [SAR 1:1 DAR 16:9], 4770 kb/s, 30 fps, 30 tbr, 15360 tbn (default)
  Stream #3:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, smpte170m), 1920x1080 [SAR 1:1 DAR 16:9], 4144 kb/s, 30 fps, 30 tbr, 15360 tbn (default)
  Stream #4:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, smpte170m), 1920x1080 [SAR 1:1 DAR 16:9], 7547 kb/s, 30 fps, 30 tbr, 15360 tbn (default)
  Stream #5:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, smpte170m), 1920x1080 [SAR 1:1 DAR 16:9], 10784 kb/s, 30 fps, 30 tbr, 15360 tbn (default)
  Stream #6:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, smpte170m), 1920x1080 [SAR 1:1 DAR 16:9], 7165 kb/s, 30.04 fps, 30.04 tbr, 22500 tbn (default)
  Stream #7:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, smpte170m), 1920x1080 [SAR 1:1 DAR 16:9], 3150 kb/s, 30.04 fps, 30.04 tbr, 22500 tbn (default)
  Stream #8:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt470bg/bt470bg/smpte170m), 1920x1080 [SAR 1:1 DAR 16:9], 8996 kb/s, 30 fps, 30 tbr, 15360 tbn (default)
  Stream #9:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt470bg/bt470bg/smpte170m), 1920x1080 [SAR 1:1 DAR 16:9], 4673 kb/s, 30 fps, 30 tbr, 15360 tbn (default)
  Stream #10:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, smpte170m/bt470bg/smpte170m), 1920x1080, 3625 kb/s, 29 fps, 29 tbr, 14848 tbn (default)
  Stream #11:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, smpte170m/bt470bg/smpte170m), 1920x1080, 33163 kb/s, 29 fps, 29 tbr, 14848 tbn (default)
  Stream #12:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, smpte170m/bt470bg/smpte170m), 1920x1080 [SAR 1:1 DAR 16:9], 4624 kb/s, 29 fps, 29 tbr, 14848 tbn (default)
  Stream #13:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt470bg/bt470bg/smpte170m), 1920x1080 [SAR 1:1 DAR 16:9], 4034 kb/s, 30 fps, 30 tbr, 15360 tbn (default)
  Stream #14:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt470bg/bt470bg/smpte170m), 1920x1080 [SAR 1:1 DAR 16:9], 6519 kb/s, 30 fps, 30 tbr, 15360 tbn (default)
  Stream #15:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt470bg/bt470bg/smpte170m), 1920x1080 [SAR 1:1 DAR 16:9], 1816 kb/s, 30 fps, 30 tbr, 15360 tbn (default)

  Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 129 kb/s (default)
  Stream #1:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 129 kb/s (default)
  Stream #2:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 129 kb/s (default)
  Stream #3:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 129 kb/s (default)
  Stream #4:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
  Stream #5:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 129 kb/s (default)
  Stream #6:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
  Stream #7:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
  Stream #8:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
  Stream #9:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 129 kb/s (default)
  Stream #10:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 2 kb/s (default)
  Stream #11:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 2 kb/s (default)
  Stream #12:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, stereo, fltp, 2 kb/s (default)
  Stream #13:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 128 kb/s (default)
  Stream #14:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 129 kb/s (default)
  Stream #15:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 129 kb/s (default)

我也试过:

ffmpeg -i 091245.mp4 -i 115405.mp4 -i 160743.mp4 -i 081024.mp4 -i 172500.mp4 -i 101658.mp4 -i 115904.mp4 -i 170035.mp4 -i 004129.mp4 -i 181930.mp4 -i 092100_01.mp4 -i 132726_01.mp4 -i 153927_01~2.mp4 -i 123552.mp4 -i 075329.mp4 -i 124002.mp4 -filter_complex "[0:v] [0:a] [1:v] [1:a] [2:v] [2:a] [3:v] [3:a] [4:v] [4:a] [5:v] [5:a] [6:v] [6:a] [7:v] [7:a] [8:v] [8:a] [9:v] [9:a] [10:v] [10:a] [11:v] [11:a] [12:v] [12:a] [13:v] [13:a] [14:v] [14:a] [15:v] [15:a] concat=n=16:v=1:a=1 [v] [a]" -map "[v]" -map "[a]" concat.out.mkv

工作正常但重新编码所有视频。

是否有更好的方法来标准化第一个编码的输出视频以便能够轻松地连接它们?

属性必须相同才能与连接分离器正确连接。

  • 您的视频有不同的时基 (tbn)。
  • 您的音频具有不同的采样率。

在你的编码命令中使它们相同:

ffmpeg -i input.1.mp4 -vcodec libx264 -acodec aac -vf fps=30,scale=1920:-2, drawtext=fontfile=./roboto.ttf: fontsize=40: text='ABC': x=(w-text_w)-w/20: y=(h-text_h)-h/20,format=yuv420p -ar 48000 -y export/out.1.mp4