ffmpeg 将 MXF 视频的多个 (N) 单声道音频通道合并到 MP4 视频的多个 (M) 立体声通道

ffmpeg merge multiple (N) mono audio channels of a MXF video to multiple (M) stereo channels of MP4 video

我有一个包含 16 个音频单声道流的 MXF 文件,我需要将其重新编码为一个 mp4 文件,其中包含 2<=n<=16 个通道合并输入流,例如在输出通道 1 上输入通道 1 和 2,在输出通道 2 上输入通道 9 和 10。这项工作将使用 ffmpeg 完成。我阅读了文档并发现 amerge 和 amix 过滤器会很好,但它们只输出一个通道。这个问题有解决办法吗?

谢谢, 劳拉

在 mxf 文件中找到 ffprobe 的输出:

{ "streams":[ { "index":0, "codec_name":"mpeg2video", "codec_long_name":"MPEG-2 video", "profile":"4:2:2", "codec_type":"video", "codec_time_base":"1/25", "codec_tag_string":"[0][0][0][0]", "codec_tag":"0x0000", "width":1920, "height":1080, "coded_width":0, "coded_height":0, "has_b_frames":1, "sample_aspect_ratio":"1:1", "display_aspect_ratio":"16:9", "pix_fmt":"yuv422p", "level":2, "color_range":"tv", "color_space":"bt709", "color_transfer":"bt709", "color_primaries":"bt709", "chroma_location":"topleft", "field_order":"tt", "refs":1, "r_frame_rate":"25/1", "avg_frame_rate":"25/1", "time_base":"1/25", "start_pts":0, "start_time":"0.000000", "duration_ts":448, "duration":"17.920000", "bit_rate":"50000000", "disposition":{ "default":0, "dub":0, "original":0, "comment":0, "lyrics":0, "karaoke":0, "forced":0, "hearing_impaired":0, "visual_impaired":0, "clean_effects":0, "attached_pic":0, "timed_thumbnails":0 }, "tags":{ "file_package_umid":"0x060A2B340101010501010D2313000000968F75C6B5B34D649967EEDD0076B989" } }, { "index":1, "codec_name":"pcm_s24le", "codec_long_name":"PCM signed 24-bit little-endian", "codec_type":"audio", "codec_time_base":"1/48000", "codec_tag_string":"[0][0][0][0]", "codec_tag":"0x0000", "sample_fmt":"s32", "sample_rate":"48000", "channels":1, "bits_per_sample":24, "r_frame_rate":"0/0", "avg_frame_rate":"0/0", "time_base":"1/48000", "start_pts":0, "start_time":"0.000000", "duration_ts":860160, "duration":"17.920000", "bit_rate":"1152000", "bits_per_raw_sample":"24", "disposition":{ "default":0, "dub":0, "original":0, "comment":0, "lyrics":0, "karaoke":0, "forced":0, "hearing_impaired":0, "visual_impaired":0, "clean_effects":0, "attached_pic":0, "timed_thumbnails":0 }, "tags":{ "file_package_umid":"0x060A2B340101010501010D2313000000968F75C6B5B34D649967EEDD0076B989" } }, { "index":2, "codec_name":"pcm_s24le", "codec_long_name":"PCM signed 24-bit little-endian", "codec_type":"audio", "codec_time_base":"1/48000", "codec_tag_string":"[0][0][0][0]", "codec_tag":"0x0000", "sample_fmt":"s32", "sample_rate":"48000", "channels":1, "bits_per_sample":24, "r_frame_rate":"0/0", "avg_frame_rate":"0/0", "time_base":"1/48000", "start_pts":0, "start_time":"0.000000", "duration_ts":860160, "duration":"17.920000", "bit_rate":"1152000", "bits_per_raw_sample":"24", "disposition":{ "default":0, "dub":0, "original":0, "comment":0, "lyrics":0, "karaoke":0, "forced":0, "hearing_impaired":0, "visual_impaired":0, "clean_effects":0, "attached_pic":0, "timed_thumbnails":0 }, "tags":{ "file_package_umid":"0x060A2B340101010501010D2313000000968F75C6B5B34D649967EEDD0076B989" } }, { "index":3, "codec_name":"pcm_s24le", "codec_long_name":"PCM signed 24-bit little-endian", "codec_type":"audio", "codec_time_base":"1/48000", "codec_tag_string":"[0][0][0][0]", "codec_tag":"0x0000", "sample_fmt":"s32", "sample_rate":"48000", "channels":1, "bits_per_sample":24, "r_frame_rate":"0/0", "avg_frame_rate":"0/0", "time_base":"1/48000", "start_pts":0, "start_time":"0.000000", "duration_ts":860160, "duration":"17.920000", "bit_rate":"1152000", "bits_per_raw_sample":"24", "disposition":{ "default":0, "dub":0, "original":0, "comment":0, "lyrics":0, "karaoke":0, "forced":0, "hearing_impaired":0, "visual_impaired":0, "clean_effects":0, "attached_pic":0, "timed_thumbnails":0 }, "tags":{ "file_package_umid":"0x060A2B340101010501010D2313000000968F75C6B5B34D649967EEDD0076B989" } }, { "index":4, "codec_name":"pcm_s24le", "codec_long_name":"PCM signed 24-bit little-endian", "codec_type":"audio", "codec_time_base":"1/48000", "codec_tag_string":"[0][0][0][0]", "codec_tag":"0x0000", "sample_fmt":"s32", "sample_rate":"48000", "channels":1, "bits_per_sample":24, "r_frame_rate":"0/0", "avg_frame_rate":"0/0", "time_base":"1/48000", "start_pts":0, "start_time":"0.000000", "duration_ts":860160, "duration":"17.920000", "bit_rate":"1152000", "bits_per_raw_sample":"24", "disposition":{ "default":0, "dub":0, "original":0, "comment":0, "lyrics":0, "karaoke":0, "forced":0, "hearing_impaired":0, "visual_impaired":0, "clean_effects":0, "attached_pic":0, "timed_thumbnails":0 }, "tags":{ "file_package_umid":"0x060A2B340101010501010D2313000000968F75C6B5B34D649967EEDD0076B989" } }, { "index":5, "codec_name":"pcm_s24le", "codec_long_name":"PCM signed 24-bit little-endian", "codec_type":"audio", "codec_time_base":"1/48000", "codec_tag_string":"[0][0][0][0]", "codec_tag":"0x0000", "sample_fmt":"s32", "sample_rate":"48000", "channels":1, "bits_per_sample":24, "r_frame_rate":"0/0", "avg_frame_rate":"0/0", "time_base":"1/48000", "start_pts":0, "start_time":"0.000000", "duration_ts":860160, "duration":"17.920000", "bit_rate":"1152000", "bits_per_raw_sample":"24", "disposition":{ "default":0, "dub":0, "original":0, "comment":0, "lyrics":0, "karaoke":0, "forced":0, "hearing_impaired":0, "visual_impaired":0, "clean_effects":0, "attached_pic":0, "timed_thumbnails":0 }, "tags":{ "file_package_umid":"0x060A2B340101010501010D2313000000968F75C6B5B34D649967EEDD0076B989" } }, { "index":6, "codec_name":"pcm_s24le", "codec_long_name":"PCM signed 24-bit little-endian", "codec_type":"audio", "codec_time_base":"1/48000", "codec_tag_string":"[0][0][0][0]", "codec_tag":"0x0000", "sample_fmt":"s32", "sample_rate":"48000", "channels":1, "bits_per_sample":24, "r_frame_rate":"0/0", "avg_frame_rate":"0/0", "time_base":"1/48000", "start_pts":0, "start_time":"0.000000", "duration_ts":860160, "duration":"17.920000", "bit_rate":"1152000", "bits_per_raw_sample":"24", "disposition":{ "default":0, "dub":0, "original":0, "comment":0, "lyrics":0, "karaoke":0, "forced":0, "hearing_impaired":0, "visual_impaired":0, "clean_effects":0, "attached_pic":0, "timed_thumbnails":0 }, "tags":{ "file_package_umid":"0x060A2B340101010501010D2313000000968F75C6B5B34D649967EEDD0076B989" } }, { "index":7, "codec_name":"pcm_s24le", "codec_long_name":"PCM signed 24-bit little-endian", "codec_type":"audio", "codec_time_base":"1/48000", "codec_tag_string":"[0][0][0][0]", "codec_tag":"0x0000", "sample_fmt":"s32", "sample_rate":"48000", "channels":1, "bits_per_sample":24, "r_frame_rate":"0/0", "avg_frame_rate":"0/0", "time_base":"1/48000", "start_pts":0, "start_time":"0.000000", "duration_ts":860160, "duration":"17.920000", "bit_rate":"1152000", "bits_per_raw_sample":"24", "disposition":{ "default":0, "dub":0, "original":0, "comment":0, "lyrics":0, "karaoke":0, "forced":0, "hearing_impaired":0, "visual_impaired":0, "clean_effects":0, "attached_pic":0, "timed_thumbnails":0 }, "tags":{ "file_package_umid":"0x060A2B340101010501010D2313000000968F75C6B5B34D649967EEDD0076B989" } }, { "index":8, "codec_name":"pcm_s24le", "codec_long_name":"PCM signed 24-bit little-endian", "codec_type":"audio", "codec_time_base":"1/48000", "codec_tag_string":"[0][0][0][0]", "codec_tag":"0x0000", "sample_fmt":"s32", "sample_rate":"48000", "channels":1, "bits_per_sample":24, "r_frame_rate":"0/0", "avg_frame_rate":"0/0", "time_base":"1/48000", "start_pts":0, "start_time":"0.000000", "duration_ts":860160, "duration":"17.920000", "bit_rate":"1152000", "bits_per_raw_sample":"24", "disposition":{ "default":0, "dub":0, "original":0, "comment":0, "lyrics":0, "karaoke":0, "forced":0, "hearing_impaired":0, "visual_impaired":0, "clean_effects":0, "attached_pic":0, "timed_thumbnails":0 }, "tags":{ "file_package_umid":"0x060A2B340101010501010D2313000000968F75C6B5B34D649967EEDD0076B989" } } ], "format":{ "filename":"/media-caches/video-essence/VIDEO/MXF-XDCAM_HD422@50Mbps1080i25_16Ch/941.mxf", "nb_streams":9, "nb_programs":0, "format_name":"mxf", "format_long_name":"MXF (Material eXchange Format)", "start_time":"0.000000", "duration":"17.920000", "size":"135028296", "bit_rate":"60280489", "probe_score":100, "tags":{ "uid":"0a9ef41a-36b4-4066-a8a3-b95f62299b6c", "generation_uid":"e134647e-fea1-4673-91c1-afa277d13c00", "company_name":"Sony", "product_name":"MPC", "product_version":"v1.0", "application_platform":"Sony MXF Development Kit (Win32)", "product_uid":"060e2b34-0401-0103-0e06-0120027f0200", "modification_date":"2012-09-17T11:56:20.000000Z", "material_package_umid":"0x060A2B340101010501010D231300000081C32F48A63347D4890F55D3ADC25B99", "timecode":"00:35:30:08" } } }

代码是用换行符组织的。 \ 在 Unix shell.

中换行
ffmpeg -i "in.mxf" \
-filter_complex "\
[a:0][a:1]amerge=inputs=2[ch1ch2];\
[a:8][a:9]amerge=inputs=2[ch9ch10]" \
-map 'v:0' \
-map '[ch1ch2]' \
-map '[ch9ch10]' \
-c:v copy \
-c:a aac -b:a 128k -ar 48000 -ac 2 \
"out.mp4"
  1. 输入
  2. filter_complex (使用 " 而不是 '。如果我使用 shell 换行符 \ 我得到一个错误单引号 ')
  3. 使用 amerge 过滤器和 select
    • 第一个音频流a:0
    • 第二个音频流 a:1,
    • 合并它们并
    • 将其存储在输出板中ch1ch2 (你可以给它起任何名字)
  4. 使用另一个 amerge 过滤器和 select
    • 第 9 个音频流 a:8
    • 第 10 个音频流 a:9,
    • 合并它们并
    • 将其存储在输出垫中ch9ch10
  5. 地图视频流(如果省略,则输出没有视频)
  6. 将 pad ch1ch2 映射到第一个音频流
  7. 映射垫ch9ch10到第二个音频流
  8. 复制视频流(如果您省略,您的视频将被重新编码)
  9. 使用 aac 编码所有音频流
  10. 输出

此处输出只有 2 个映射的音频通道。

如果你想保留一些剩余的频道,你必须映射它们。 您甚至可以在第 7 行之后添加 -map 0 以将所有流堆叠在合并后的流之下。 (当然你最终会得到 2+16 个音频流。)

您可以添加更多 amerge 个过滤器。用 ; 分隔它们 您还可以将 3 个音频流与 [a:0][a:1][a:2]amerge=inputs=3[ch1ch2ch3] 合并。 使用

命名音频通道

-metadata:s:a:0 title="channel 1 and 2"

这对测试很有用,因为您可以在 VLC 中看到名称。