如何使用 ffmpeg 交换视频中的音频流

如何使用 ffmpeg 交换视频中的音频流

我知道我可以通过单独指定流来交换音频 0 和音频 1,就像这样

ffmpeg -i input.mkv -map 0:v:0 -map 0:a:1 -map 0:a:0 -c copy output.mkv

但是,这只会将两个命名流复制到输出文件(我有几个视频有更多命名流),而不会复制字幕。但如果我包含有关额外音频流和字幕的说明,而没有字幕,则命令会失败。我认为应该这样写

ffmpeg -i input.mkv -map 0 -c copy -c:a:1 copy -c:a:0 copy output.mkv

但还是不起作用。这里的错误在哪里?

附录:以下是我尝试推荐的解决方案后的控制台输出:

ffmpeg version git-2015-02-23-29bbc1b Copyright (c) 2000-2015 the FFmpeg develop
ers
  built with gcc 4.9.2 (Rev4, Built by MSYS2 project)

  configuration: --arch=x86 --disable-debug --disable-shared --disable-doc --dis
able-w32threads --enable-gpl --enable-version3 --enable-runtime-cpudetect --enab
le-avfilter --enable-bzlib --enable-zlib --enable-decklink --enable-librtmp --en
able-gnutls --enable-avisynth --enable-frei0r --enable-filter=frei0r --enable-li
bbluray --enable-libcaca --enable-libopenjpeg --enable-fontconfig --enable-libfr
eetype --enable-libass --enable-libgsm --enable-libilbc --enable-libmodplug --en
able-libmp3lame --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-l
ibvo-amrwbenc --enable-libschroedinger --enable-libsoxr --enable-libtwolame --en
able-libspeex --enable-libtheora --enable-libutvideo --enable-libvorbis --enable
-libvo-aacenc --enable-libopus --enable-libvidstab --enable-libvpx --enable-libw
avpack --enable-libxavs --enable-libx264 --enable-libx265 --enable-libxvid --ena
ble-libzvbi --enable-nonfree --enable-libfaac --enable-libfdk-aac
  libavutil      54. 19.100 / 54. 19.100
  libavcodec     56. 25.101 / 56. 25.101
  libavformat    56. 23.104 / 56. 23.104
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 11.100 /  5. 11.100
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  3.100 / 53.  3.100

Input #0, matroska,webm, from 'TestClip.mkv.mkv':
  Metadata:
    creation_time   : 2017-06-18 01:22:02
    ENCODER         : Lavf56.23.104
  Duration: 00:00:20.32, start: 0.000000, bitrate: 1108 kb/s
    Stream #0:0: Video: hevc (Main), yuv420p(tv), 1280x720, SAR 1:1 DAR 16:9, 23
.98 fps, 23.98 tbr, 1k tbn, 23.98 tbc (default)
    Metadata:
      BPS             : 958029
      BPS-eng         : 958029
      DURATION        : 00:00:20.145000000
      DURATION-eng    : 00:00:20.145000000
      NUMBER_OF_FRAMES: 482
      NUMBER_OF_FRAMES-eng: 482
      NUMBER_OF_BYTES : 2412437
      NUMBER_OF_BYTES-eng: 2412437
      _STATISTICS_WRITING_APP: mkvmerge v9.7.1 ('Pandemonium') 64bit
      _STATISTICS_WRITING_APP-eng: mkvmerge v9.7.1 ('Pandemonium') 64bit
      _STATISTICS_WRITING_DATE_UTC: 2017-06-18 01:22:02
      _STATISTICS_WRITING_DATE_UTC-eng: 2017-06-18 01:22:02
      _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
      _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES

    Stream #0:1: Audio: aac (HE-AACv2), 48000 Hz, stereo, fltp
    Metadata:
      BPS             : 48003
      BPS-eng         : 48003
      DURATION        : 00:00:20.180000000
      DURATION-eng    : 00:00:20.180000000
      NUMBER_OF_FRAMES: 473
      NUMBER_OF_FRAMES-eng: 473
      NUMBER_OF_BYTES : 121089
      NUMBER_OF_BYTES-eng: 121089
      _STATISTICS_WRITING_APP: mkvmerge v9.7.1 ('Pandemonium') 64bit
      _STATISTICS_WRITING_APP-eng: mkvmerge v9.7.1 ('Pandemonium') 64bit
      _STATISTICS_WRITING_DATE_UTC: 2017-06-18 01:22:02
      _STATISTICS_WRITING_DATE_UTC-eng: 2017-06-18 01:22:02
      _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
      _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES

    Stream #0:2: Audio: aac (HE-AACv2), 48000 Hz, stereo, fltp
    Metadata:
      BPS             : 52409
      BPS-eng         : 52409
      DURATION        : 00:00:20.180000000
      DURATION-eng    : 00:00:20.180000000
      NUMBER_OF_FRAMES: 473
      NUMBER_OF_FRAMES-eng: 473
      NUMBER_OF_BYTES : 132203
      NUMBER_OF_BYTES-eng: 132203
      _STATISTICS_WRITING_APP: mkvmerge v9.7.1 ('Pandemonium') 64bit
      _STATISTICS_WRITING_APP-eng: mkvmerge v9.7.1 ('Pandemonium') 64bit
      _STATISTICS_WRITING_DATE_UTC: 2017-06-18 01:22:02
      _STATISTICS_WRITING_DATE_UTC-eng: 2017-06-18 01:22:02
      _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
      _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES

    Stream #0:3: Audio: aac (HE-AACv2), 48000 Hz, stereo, fltp
    Metadata:
      BPS             : 52430
      BPS-eng         : 52430
      DURATION        : 00:00:20.180000000
      DURATION-eng    : 00:00:20.180000000
      NUMBER_OF_FRAMES: 473
      NUMBER_OF_FRAMES-eng: 473
      NUMBER_OF_BYTES : 132256
      NUMBER_OF_BYTES-eng: 132256
      _STATISTICS_WRITING_APP: mkvmerge v9.7.1 ('Pandemonium') 64bit
      _STATISTICS_WRITING_APP-eng: mkvmerge v9.7.1 ('Pandemonium') 64bit
      _STATISTICS_WRITING_DATE_UTC: 2017-06-18 01:22:02
      _STATISTICS_WRITING_DATE_UTC-eng: 2017-06-18 01:22:02
      _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
      _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES

    Stream #0:4(eng): Subtitle: subrip
    Metadata:
      title           : English
      LANGUAGE        : eng
      BPS             : 47
      BPS-eng         : 47
      DURATION        : 00:00:01.668000000
      DURATION-eng    : 00:00:01.668000000
      NUMBER_OF_FRAMES: 1
      NUMBER_OF_FRAMES-eng: 1
      NUMBER_OF_BYTES : 10
      NUMBER_OF_BYTES-eng: 10
      _STATISTICS_WRITING_APP: mkvmerge v9.7.1 ('Pandemonium') 64bit
      _STATISTICS_WRITING_APP-eng: mkvmerge v9.7.1 ('Pandemonium') 64bit
      _STATISTICS_WRITING_DATE_UTC: 2017-06-18 01:22:02
      _STATISTICS_WRITING_DATE_UTC-eng: 2017-06-18 01:22:02
      _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
      _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES

    Stream #0:5(fre): Subtitle: subrip
    Metadata:
      title           : English
      LANGUAGE        : fre
      BPS             : 47
      BPS-eng         : 47
      DURATION        : 00:00:01.668000000
      DURATION-eng    : 00:00:01.668000000
      NUMBER_OF_FRAMES: 1
      NUMBER_OF_FRAMES-eng: 1
      NUMBER_OF_BYTES : 10
      NUMBER_OF_BYTES-eng: 10
      _STATISTICS_WRITING_APP: mkvmerge v9.7.1 ('Pandemonium') 64bit
      _STATISTICS_WRITING_APP-eng: mkvmerge v9.7.1 ('Pandemonium') 64bit
      _STATISTICS_WRITING_DATE_UTC: 2017-06-18 01:22:02
      _STATISTICS_WRITING_DATE_UTC-eng: 2017-06-18 01:22:02
      _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
      _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES

    Stream #0:6(ita): Subtitle: subrip
    Metadata:
      title           : English
      LANGUAGE        : ita
      BPS             : 47
      BPS-eng         : 47
      DURATION        : 00:00:01.668000000
      DURATION-eng    : 00:00:01.668000000
      NUMBER_OF_FRAMES: 1
      NUMBER_OF_FRAMES-eng: 1
      NUMBER_OF_BYTES : 10
      NUMBER_OF_BYTES-eng: 10
      _STATISTICS_WRITING_APP: mkvmerge v9.7.1 ('Pandemonium') 64bit
      _STATISTICS_WRITING_APP-eng: mkvmerge v9.7.1 ('Pandemonium') 64bit
      _STATISTICS_WRITING_DATE_UTC: 2017-06-18 01:22:02
      _STATISTICS_WRITING_DATE_UTC-eng: 2017-06-18 01:22:02
      _STATISTICS_TAGS: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES
      _STATISTICS_TAGS-eng: BPS DURATION NUMBER_OF_FRAMES NUMBER_OF_BYTES

Stream map '0:a:3?' matches no streams.

答案1

ffmpeg -i input.mkv -map 0 -c copy -c:a:1 copy -c:a:0 copy output.mkv

(所有) 流都按照输入文件进行映射。-c:a:1 copy所做的只是指定第二个输出音频流的编解码器模式,该音频流将是第二个输入音频。只能map设置顺序。您可以添加后缀?来设置条件映射。

ffmpeg -i input.mkv -map 0:v:0 -map 0:a:1 -map 0:a:0 -map 0:a:2? -map 0:a:3? -map 0:a:4? -map 0:a:5? -map 0:s? -c copy output.mkv

相关内容