[英]ffmpeg merge multiple (N) mono audio channels of a MXF video to multiple (M) stereo channels of MP4 video
I have an MXF file with 16 audio mono streams and I need to recode it in a mp4 file with 2<=n<=16 channels merging input streams, eg input channels 1 and 2 on output channel 1 and 9 and 10 on output channel 2. This job will be done with ffmpeg.我有一个带有 16 个音频单声道流的 MXF 文件,我需要将它重新编码为一个 mp4 文件,其中 2<=n<=16 个通道合并输入流,例如输出通道 1 上的输入通道 1 和 2 以及输出通道上的 9 和 10 2.这项工作将使用ffmpeg完成。 I read the documentation and found the amerge and amix filters that would be nice, but they output one channel only.
我阅读了文档,发现 amerge 和 amix 过滤器会很好,但它们只输出一个通道。 Is there any solution for this problem?
这个问题有什么解决方案吗?
Thanks, Laura谢谢,劳拉
Find below the output of ffprobe on mxf file:在 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":"0x060A2B340101010501010D2313000000968F75C6B5B34D6
{ "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,“歌词”:0,“卡拉OK”:0,“强迫”:0,“听力受损”:0,“视觉受损”:0,“clean_effects”:0,“attached_pic”:0,“timed_thumbnails”:0 } , "标签":{ "file_package_umid":"0x060A2B340101010501010D2313000000968F75C6B5B34D6 49967EEDD0076B989" } }, { "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]", "code
49967EEDD0076B989" } }, { "index":1, "codec_name":"pcm_s24le", "codec_long_name":"PCM 签名 24 位小端", "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, "原版”:0,“评论”:0,“歌词”:0,“卡拉OK”:0,“强迫”:0,“听力受损”:0,“视觉受损”:0,“clean_effects”:0,“attached_pic” :0, "timed_thumbnails":0 }, "tags":{ "file_package_umid":"0x060A2B340101010501010D2313000000968F75C6B5B34D649967EEDD00767EEDD0076name",code-cm_signed",code-cm",code-cm_4pcm_code_cm_4p_cm_4 little-endian", "codec_type":"audio", "codec_time_base":"1/48000", "codec_tag_string":"[0][0][0][0]", "code c_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", "d
c_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, “强制”:0,“听力受损”:0,“视觉受损”:0,“clean_effects”:0,“attached_pic”:0,“timed_thumbnails”:0},“标签”:{“file_package_umid”:“0x060A2B340101016090804B34010101608D7307B307B307B301608D7B3010608D70160100503010100503007030070300503010101060503050307030705030705030705050307080505050701010之间的强制”:0、“听力受损”:0、“timed_thumbnails”:0、“timed_thumbnails”:0 }, { "index":3, "codec_name":"pcm_s24le", "codec_long_name":"PCM 签名 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", " d uration_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_im
uration_ts":860160, "duration":"17.920000", "bit_rate":"1152000", "bits_per_raw_sample":"24", "disposition":{ "default":0, "dub":0, "original": 0,“评论”:0,“歌词”:0,“卡拉OK”:0,“强迫”:0,“听力受损”:0,“视觉受损”:0,“clean_effects”:0,“attached_pic”:0, "timed_thumbnails":0 }, "tags":{ "file_package_umid":"0x060A2B340101010501010D2313000000968F75C6B5B34D649967EEDD0076B989","PCMcode-cname_4pcode-cname","PCM_4pname_4cname_4pcname_4_4pcode-cname" ", "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_4", "2":"2处置”:{“默认”:0,“配音”:0,“原始”:0,“评论”:0,“歌词”:0,“卡拉OK”:0,“强制”:0,“hearing_im paired":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
配对”:0,“visual_impaired”:0,“clean_effects”:0,“attached_pic”:0,“timed_thumbnails”:0 },“标签”:{“file_package_umid”:“0x060A2B340101010501010D20501010D20501010D20501010D20501010D200501010D200501010D2310967B97B97B97B97B600000000000000000” 5、"codec_name":"pcm_s24le"、"codec_long_name":"PCM 签名的 24 位小端"、"codec_type":"音频"、"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 , "歌词":0, "卡拉OK":0, "强制":0, "听力受损":0, "视觉受损":0, "clean_effects":0, "attached_pic":0, "timed_thumbnails":0 }, "标签":{ "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"
, "codec_name":"pcm_s24le", "codec_long_name":"PCM 签名 24 位小端", "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, “歌词”:0,“卡拉OK”:0,“强迫”:0,“听力受损”:0,“视觉受损”:0,“clean_effects”:0,“attached_pic”:0,“timed_thumbnails”:0 },“标签”:{“file_package_umid”:“0x060A2B340101010501010D2313000000968F75C6B5B34D649967EEDD0076B989”}},{“索引”:7,“codec_name”,“codec_name”,code-cbitc_end_codec_name,”code24p_audio_name,” ", "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.
, "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":{ “默认”:0,“配音”:0,“原创”:0,“评论”:0,“歌词”:0,“卡拉OK”:0,“强制”:0,“听力受损”:0,“视觉受损” ":0, "clean_effects":0, "attached_pic":0, "timed_thumbnails":0 }, "tags":{ "file_package_umid":"0x060A2B340101010501010D2313000000968B34D2313000000968B34D2313000000968F75C}69D0968F75C}69D000000000000000" pcm_s24le", "codec_long_name":"PCM 签名的 24 位小端", "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_
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”}}], “格式”:{ “文件名”: “/ 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":"c134649161733 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", "修改_ date":"2012-09-17T11:56:20.000000Z", "material_package_umid":"0x060A2B340101010501010D231300000081C32F48A63347D4890F55D3ADC25B99", "timecode":"00:35:30:08" } } }
日期 “:” 2012-09-17T11:56:20.000000Z”, “material_package_umid”: “0x060A2B340101010501010D231300000081C32F48A63347D4890F55D3ADC25B99”, “时间码”: “00:35:30:08”}}}
The code is organised with line breaks.代码是用换行符组织的。 A
\\
breaks a line in a Unix shell. \\
在 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"
"
instead of '
. If I use shell line breaks \\
I get an error with single quotes '
) "
而不是'
。如果我使用 shell 换行符\\
我会收到带有单引号的错误'
)amerge
filter and selectamerge
过滤器并选择
a:0
anda:0
和a:1
,a:1
,ch1ch2
(you can give it any name)ch1ch2
(您可以给它任何名称)amerge
filter and selectamerge
过滤器并选择
a:8
anda:8
和a:9
,a:9
,ch9ch10
ch9ch10
ch1ch2
to 1st audio streamch1ch2
映射到第一个音频流ch9ch10
to 2nd audio streamch9ch10
映射到第二个音频流Here the output has only the 2 mapped audio channels.这里的输出只有 2 个映射的音频通道。
If you want to keep some of the remaining channels you have to map them.如果您想保留一些剩余的频道,您必须映射它们。 You can even add
-map 0
right after Line 7 to stack all streams underneath your merged ones.您甚至可以在第 7 行之后添加
-map 0
以将所有流堆叠在合并的流下方。 (But of course you would end up with 2+16 audio streams.) (当然,您最终会得到 2+16 个音频流。)
You can add more amerge
filters.您可以添加更多的
amerge
过滤器。 Separate them with ;
用
;
分隔它们You can also merge 3 audio streams with [a:0][a:1][a:2]amerge=inputs=3[ch1ch2ch3]
.您还可以使用
[a:0][a:1][a:2]amerge=inputs=3[ch1ch2ch3]
合并 3 个音频流。 Name the audio channels with将音频通道命名为
-metadata:s:a:0 title="channel 1 and 2"
This is useful for testing because you can see the names in VLC.这对测试很有用,因为您可以在 VLC 中看到名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.