ffmpeg过滤器复杂错误使用覆盖过滤器刻录字幕

问题描述

我尝试在使用ffmpeg重叠式滤镜的视频上刻录基于图像的dvb字幕。但是我失败了,因为使用复杂的筛选器。

这是我的命令行。

./ffmpeg -y -hwaccel cuda -hwaccel_output_format cuda -hwaccel_device 0 \
-i input.ts \
-filter_complex "[v:0][s:3]overlay[overlay];[overlay]hwupload_cuda[base];[base]scale_npp=1920:1080[v1];[base]scale_npp=1920:1080[v2];[base]scale_npp=1280:720[v3];[base]scale_npp=720:480[v4];[base]scale_npp=480:360[v5]" \
-map "[v1]" -map 0:a -c:v hevc_nvenc -b:v 6000000 -maxrate 7000000 -bufsize 12000000 -g 15 -c:a libfdk_aac -ar 48000 -ac 2 -pkt_size 128000 -f mpegts test_1.ts \
-map "[v2]" -map 0:a -c:v h264_nvenc -an -b:v 4000000 -maxrate 5000000 -bufsize 8000000 -g 15 -f mpegts test_2.ts \
-map "[v3]" -map 0:a -c:v h264_nvenc -an -b:v 2500000 -maxrate 3500000 -bufsize 5000000 -g 15 -f mpegts test_3.ts \
-map "[v4]" -map 0:a -c:v h264_nvenc -an -b:v 1500000 -maxrate 2500000 -bufsize 3000000 -g 15 -f mpegts test_4.ts \
-map "[v5]" -map 0:a -c:v h264_nvenc -an -b:v 800000 -maxrate 1800000 -bufsize 2000000 -g 15 -f mpegts test_5.ts

但是我失败了。这是错误消息。

Input #0,mpegts,from 'input.ts':
Duration: N/A,start: 22881.964411,bitrate: N/A
  Program 1 
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
    Stream #0:0[0x100](eng): Audio: ac3 ([129][0][0][0] / 0x0081),48000 Hz,5.1(side),fltp,384 kb/s
    Stream #0:1[0x101](ind): Audio: ac3 ([129][0][0][0] / 0x0081),stereo,192 kb/s
    Stream #0:2[0x102](zho): Audio: ac3 ([129][0][0][0] / 0x0081),192 kb/s
    Stream #0:3[0x103](kho): Audio: ac3 ([129][0][0][0] / 0x0081),192 kb/s
    Stream #0:4[0x104]: Video: h264 (High),1 reference frame ([27][0][0][0] / 0x001B),yuv420p(top first,left),1920x1080 (1920x1088) [SAR 1:1 DAR 16:9],25 fps,50 tbr,90k tbn,50 tbc
    Stream #0:5[0x105](CHI): Subtitle: dvb_subtitle ([6][0][0][0] / 0x0006)
    Stream #0:6[0x106](CHS): Subtitle: dvb_subtitle ([6][0][0][0] / 0x0006)
    Stream #0:7[0x107](IND): Subtitle: dvb_subtitle ([6][0][0][0] / 0x0006)
    Stream #0:8[0x108](THA): Subtitle: dvb_subtitle ([6][0][0][0] / 0x0006)
    Stream #0:9[0x109](MAN): Subtitle: dvb_subtitle ([6][0][0][0] / 0x0006)
    Stream #0:10[0x10a](MON): Subtitle: dvb_subtitle ([6][0][0][0] / 0x0006)
    Stream #0:11[0x10b](BUR): Subtitle: dvb_subtitle ([6][0][0][0] / 0x0006)
    Stream #0:12[0x10c](ENG): Subtitle: dvb_subtitle ([6][0][0][0] / 0x0006)
    [mpegts @ 0x47cbd00] Invalid stream specifier: base.
    Last message repeated 17 times
    Stream specifier 'base' in filtergraph description [v:0][s:3]overlay[overlay];[overlay]hwupload_cuda[base];[base]scale_npp=1920:1080[v1];[base]scale_npp=1920:1080[v2];[base]scale_npp=1280:720[v3];[base]scale_npp=720:480[v4];[base]scale_npp=480:360[v5] matches no streams.

我的计划是这样。

enter image description here

如何使用这种结构的复合滤镜ffmpeg在视频上刻录字幕?

解决方法

您不能重复使用过滤链的输出。您可以使用split / asplit过滤器来复制要多次使用的过滤器输出。

简化示例:

ffmpeg -i input.ts -i logo.png \
-filter_complex "[0][1]overlay,split=outputs=3[s1][s2][s3];[s1]scale=-2:1080[1080];[s2]scale=-2:720[720];[s3]scale=-2:360[360]" \
-map "[1080]" -map 0:a 1080.ts \
-map "[720]"  -map 0:a 720.ts \
-map "[360]"  -map 0:a 360.ts