Como trocar fluxos de áudio em um vídeo com ffmpeg

2

Eu sei que posso trocar áudio 0 e áudio 1, especificando os fluxos individualmente, como este

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

No entanto, isso apenas copia os dois fluxos nomeados para o arquivo de saída (e eu tenho vários vídeos que têm mais) e sem legendas. Mas se eu incluir instruções para streams e legendas de áudio extras e não houver nenhuma, o comando falhará. Foi assim que pensei que deveria ser escrito

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

mas também não funciona. Onde está o erro aqui?

Adendo: Segue a saída do meu console depois de tentar a solução recomendada:

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.
    
por Dennis Q. Wilson 18.06.2017 / 01:08

1 resposta

1

Em

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

(todos) os fluxos são mapeados de acordo com o arquivo de entrada. Todo o -c:a:1 copy faz é designar o modo de codec para o segundo fluxo de áudio de saída, que será o segundo áudio de entrada. Apenas map pode definir a ordem. Você pode adicionar um sufixo ? para definir o mapeamento condicional.

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
    
por 18.06.2017 / 06:38

Tags