0

The Problem

I have a mkv file that contains audio in a format that not all my devices support. To get full support, I want to copy that audio and convert it while retaining the original audio.

Input:

  • mkv
  • 4 stereo audio tracks

Output:

  • mka (I only care about the audio)
  • 2 stereo audio tracks (original, track 0 and 2 copied)
  • 2 stereo audio tracks (converted, track 0 -> track 1, track 2 -> track 3)
  • the original track 1 and 3 shall be discarded

What I´ve found so far (using ffmpeg 6.1):

To copy audio track 0 and 2, I can use the following command:

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

And this command to change the audio format of track 0 to OPUS.

ffmpeg -i intput.mkv -map 0:a -mapping_family 1 -ac 6 -c:a:0 libopus -metadata:s:a:0 title='Opus 5.1' -metadata:s:a:0 language='eng' output.mka

I think I can remove the -mapping_family 1 -ac 6 part, as I´m only dealing with stereo audio.

The question:

How can I combine both commands to get the following track layout?:

  • track 0 (original, copied, metadata retained)
  • track 1 (re-encode from track 0)
  • track 2 (original, copied, metadata retained)
  • track 3 (re-encode from track 2)
1
  • 1
    mapping ffmpeg -i "$f" -map 0:a:0 -map 0:a:0 -map 0:a:2 -map 0:a:2 -c:0 copy -c:1 libopus -c:2 copy -c:3 libopus -metadata:s:0 title="aac 0" -metadata:s:1 title="Opus 1" -metadata:s:2 title="aac 2" -metadata:s:3 title="Opus 3" /tmp/out.mka Mar 18 at 2:09

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.