参考:
比如:
$ ffmpeg -i 九品芝麻官.BD.720p.国粤双语中字.mkv ffmpeg version 4.2.4-1ubuntu0.1 Copyright (c) 2000-2020 the FFmpeg developers built with gcc 9 (Ubuntu 9.3.0-10ubuntu2) configuration: --prefix=/usr --extra-version=1ubuntu0.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-nvenc --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared libavutil 56. 31.100 / 56. 31.100 libavcodec 58. 54.100 / 58. 54.100 libavformat 58. 29.100 / 58. 29.100 libavdevice 58. 8.100 / 58. 8.100 libavfilter 7. 57.100 / 7. 57.100 libavresample 4. 0. 0 / 4. 0. 0 libswscale 5. 5.100 / 5. 5.100 libswresample 3. 5.100 / 3. 5.100 libpostproc 55. 5.100 / 55. 5.100 Input #0, matroska,webm, from '九品芝麻官.BD.720p.国粤双语中字.mkv': Metadata: encoder : libebml v1.0.0 + libmatroska v1.0.0 creation_time : 2015-09-19T14:26:58.000000Z Duration: 01:46:44.22, start: 0.000000, bitrate: 1703 kb/s Stream #0:0(chi): Video: h264 (High), yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], 24 fps, 24 tbr, 1k tbn, 48 tbc (default) Stream #0:1(chi): Audio: aac (HE-AAC), 48000 Hz, stereo, fltp (default) Metadata: title : 粤语 Stream #0:2(chi): Audio: aac (HE-AAC), 48000 Hz, stereo, fltp Metadata: title : 国语
下面实现的功能是将上面的视频文件的视频流和国语音频流提取出来,合并成新的文件:
$ ffmpeg -i 九品芝麻官.BD.720p.国粤双语中字.mkv -vcodec copy -map 0:0 -acodec copy -map 0:2 b.mkv
查看输出文件格式信息:
$ ffmpeg -i b.mkv ffmpeg version 4.2.4-1ubuntu0.1 Copyright (c) 2000-2020 the FFmpeg developers built with gcc 9 (Ubuntu 9.3.0-10ubuntu2) configuration: --prefix=/usr --extra-version=1ubuntu0.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-nvenc --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared libavutil 56. 31.100 / 56. 31.100 libavcodec 58. 54.100 / 58. 54.100 libavformat 58. 29.100 / 58. 29.100 libavdevice 58. 8.100 / 58. 8.100 libavfilter 7. 57.100 / 7. 57.100 libavresample 4. 0. 0 / 4. 0. 0 libswscale 5. 5.100 / 5. 5.100 libswresample 3. 5.100 / 3. 5.100 libpostproc 55. 5.100 / 55. 5.100 Input #0, matroska,webm, from 'b.mkv': Metadata: ENCODER : Lavf58.29.100 Duration: 01:46:44.22, start: 0.000000, bitrate: 1640 kb/s Stream #0:0(chi): Video: h264 (High), yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], 24 fps, 24 tbr, 1k tbn, 48 tbc (default) Metadata: DURATION : 01:46:44.083000000 Stream #0:1(chi): Audio: aac (HE-AAC), 48000 Hz, stereo, fltp Metadata: title : 国语 DURATION : 01:46:44.223000000
交换国语和粤语音轨:
$ ffmpeg -i 九品芝麻官.BD.720p.国粤双语中字.mkv -vcodec copy -map 0:0 -acodec copy -map 0:2 -acodec copy -map 0:1 b.mkv
下面是音视频流的映射信息:
Input #0, matroska,webm, from '九品芝麻官.BD.720p.国粤双语中字.mkv': Metadata: encoder : libebml v1.0.0 + libmatroska v1.0.0 creation_time : 2015-09-19T14:26:58.000000Z Duration: 01:46:44.22, start: 0.000000, bitrate: 1703 kb/s Stream #0:0(chi): Video: h264 (High), yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], 24 fps, 24 tbr, 1k tbn, 48 tbc (default) Stream #0:1(chi): Audio: aac (HE-AAC), 48000 Hz, stereo, fltp (default) Metadata: title : 粤语 Stream #0:2(chi): Audio: aac (HE-AAC), 48000 Hz, stereo, fltp Metadata: title : 国语 Output #0, matroska, to 'b.mkv': Metadata: encoder : Lavf58.29.100 Stream #0:0(chi): Video: h264 (High) (H264 / 0x34363248), yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 24 fps, 24 tbr, 1k tbn, 1k tbc (default) Stream #0:1(chi): Audio: aac (HE-AAC) ([255][0][0][0] / 0x00FF), 48000 Hz, stereo, fltp Metadata: title : 国语 Stream #0:2(chi): Audio: aac (HE-AAC) ([255][0][0][0] / 0x00FF), 48000 Hz, stereo, fltp (default) Metadata: title : 粤语 Stream mapping: Stream #0:0 -> #0:0 (copy) Stream #0:2 -> #0:1 (copy) Stream #0:1 -> #0:2 (copy)
查看格式信息:
$ ffmpeg -i b.mkv ffmpeg version 4.2.4-1ubuntu0.1 Copyright (c) 2000-2020 the FFmpeg developers built with gcc 9 (Ubuntu 9.3.0-10ubuntu2) configuration: --prefix=/usr --extra-version=1ubuntu0.1 --toolchain=hardened --libdir=/usr/lib/x86_64-linux-gnu --incdir=/usr/include/x86_64-linux-gnu --arch=amd64 --enable-gpl --disable-stripping --enable-avresample --disable-filter=resample --enable-avisynth --enable-gnutls --enable-ladspa --enable-libaom --enable-libass --enable-libbluray --enable-libbs2b --enable-libcaca --enable-libcdio --enable-libcodec2 --enable-libflite --enable-libfontconfig --enable-libfreetype --enable-libfribidi --enable-libgme --enable-libgsm --enable-libjack --enable-libmp3lame --enable-libmysofa --enable-libopenjpeg --enable-libopenmpt --enable-libopus --enable-libpulse --enable-librsvg --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libssh --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx265 --enable-libxml2 --enable-libxvid --enable-libzmq --enable-libzvbi --enable-lv2 --enable-omx --enable-openal --enable-opencl --enable-opengl --enable-sdl2 --enable-libdc1394 --enable-libdrm --enable-libiec61883 --enable-nvenc --enable-chromaprint --enable-frei0r --enable-libx264 --enable-shared libavutil 56. 31.100 / 56. 31.100 libavcodec 58. 54.100 / 58. 54.100 libavformat 58. 29.100 / 58. 29.100 libavdevice 58. 8.100 / 58. 8.100 libavfilter 7. 57.100 / 7. 57.100 libavresample 4. 0. 0 / 4. 0. 0 libswscale 5. 5.100 / 5. 5.100 libswresample 3. 5.100 / 3. 5.100 libpostproc 55. 5.100 / 55. 5.100 Input #0, matroska,webm, from 'b.mkv': Metadata: ENCODER : Lavf58.29.100 Duration: 01:46:44.22, start: 0.000000, bitrate: 1705 kb/s Stream #0:0(chi): Video: h264 (High), yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], 24 fps, 24 tbr, 1k tbn, 48 tbc (default) Metadata: DURATION : 01:46:44.083000000 Stream #0:1(chi): Audio: aac (HE-AAC), 48000 Hz, stereo, fltp Metadata: title : 国语 DURATION : 01:46:44.223000000 Stream #0:2(chi): Audio: aac (HE-AAC), 48000 Hz, stereo, fltp (default) Metadata: title : 粤语 DURATION : 01:46:44.223000000