如何使用FFmpeg合并具有不同流顺序的多个视频文件?

时间:2019-02-01 17:06:02

标签: audio video ffmpeg concatenation

我有3个视频文件,其中包含以下信息:

Input #0, mpegts, from '01.ts':
  Duration: 00:00:06.08, start: 0.000000, bitrate: 931 kb/s
  Program 1
    Stream #0:0[0x101]: Audio: aac (LC) ([15][0][0][0] / 0x000F), 48000 Hz, stereo, fltp, 65 kb/s
    Stream #0:1[0x102]: Video: h264 (High) ([27][0][0][0] / 0x001B), yuv420p(progressive), 852x480 [SAR 640:639 DAR 16:9], 25 fps, 25 tbr, 90k tbn, 50 tbc


Input #0, mpegts, from '02.ts':
  Duration: 00:00:06.06, start: 6.016000, bitrate: 872 kb/s
    Stream #0:0[0x102]: Video: h264 (High), yuv420p(progressive), 852x480 [SAR 640:639 DAR 16:9], 25 fps, 25 tbr, 90k tbn, 50 tbc
    Stream #0:1[0x101]: Audio: aac (LC), 48000 Hz, stereo, fltp, 66 kb/s


Input #0, mpegts, from '03.ts':
  Duration: 00:00:06.07, start: 12.010667, bitrate: 822 kb/s
    Stream #0:0[0x102]: Video: h264 (High), yuv420p(progressive), 852x480 [SAR 640:639 DAR 16:9], 25 fps, 25 tbr, 90k tbn, 50 tbc
    Stream #0:1[0x101]: Audio: aac (LC), 48000 Hz, stereo, fltp, 69 kb/s

它们中的大多数相同,但是不知何故01.ts与其他两个具有不同的流顺序。我的问题是,如何吸引他们?我试图将它们放在txt文件中,然后配置成concat:

-f concat -safe 0 -i video_file.txt -c copy -bsf:a aac_adtstoasc output.mp4

但是它不起作用。错误消息是:

Error parsing ADTS frame header!
Error applying bitstream filters to an output packet for stream #0:1.

如果我有数百个可能具有不同流顺序的视频文件怎么办?

编辑

aergistal's answer是正确的,但是我还有另一个问题:在另一组视频中,流ID不同,如下所示:

Input #0, mpegts, from 'another1.ts':
  Duration: 00:00:08.04, start: 17.401333, bitrate: 284 kb/s
  Program 1
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
    Stream #0:0[0x100]: Video: h264 (Constrained Baseline) ([27][0][0][0] / 0x001B), yuv420p(progressive), 352x288 [SAR 16:11 DAR 16:9], 25 fps, 25 tbr, 90k tbn, 50 tbc
    Stream #0:1[0x101]: Audio: aac (LC) ([15][0][0][0] / 0x000F), 48000 Hz, stereo, fltp, 124 kb/s


Input #0, mpegts, from 'another2.ts':
  Duration: 00:00:08.04, start: 33.401333, bitrate: 300 kb/s
  Program 1
    Metadata:
      service_name    : Service01
      service_provider: FFmpeg
    Stream #0:0[0x100]: Video: h264 (Constrained Baseline) ([27][0][0][0] / 0x001B), yuv420p(progressive), 352x288 [SAR 16:11 DAR 16:9], 25 fps, 25 tbr, 90k tbn, 50 tbc
    Stream #0:1[0x101]: Audio: aac (LC) ([15][0][0][0] / 0x000F), 48000 Hz, stereo, fltp, 145 kb/s

有没有一种方法可以自动设置exact_stream_id而不是每次都进行检查?

1 个答案:

答案 0 :(得分:2)

concat demuxer有一个exact_stream_id可能会有所帮助。对于连续列表(video_file.txt),请使用PID和以下格式:

file 01.ts
stream
exact_stream_id 0x102
stream
exact_stream_id 0x101

file 02.ts
stream
exact_stream_id 0x102
stream
exact_stream_id 0x101

file 03.ts
stream
exact_stream_id 0x102
stream
exact_stream_id 0x101