0

I'm using Plex, which always considers the first audio stream, but is also failing to decode surround media files on my stereo system (my laptop).

For that reason, I intend to downmix (following a formula suggested in this answer, which is an improvement over -ac 2) a bunch of files so I have:

Stream 0:0 > Video
Stream 0:1 > 2.0 Filtered audio
Stream 0:2 > 5.1 Original audio

The problem is that while my downmixing requires filtering, the doubling of a stream requires copying and I found out that these 2 doesn't seem to go together, although it seems to me this could be done because while the filtering and copying are applied for the same input stream, they're not for the same output stream.

Here's my currently failing command:

ffmpeg -i "INPUT.mkv" -map 0:v -c:v copy -map 0:a:0 -c:a:0 ac3 -vol 425 -filter_complex "[0:a:0]pan=stereo|FL=0.5*FC+0.707*FL+0.707*BL+0.5*LFE|FR=0.5*FC+0.707*FR+0.707*BR+0.5*LFE" -map 0:a:0 -c:a:0 copy  "OUTPUT.mkv"

Is there a way to do it?

Fabio Freitas
  • 71
  • 1
  • 9

1 Answers1

2

So, you want to map 5.1 audio to 2 output audio streams: filtered 2.0 and original 5.1. You are on a right track but mixed up in the stream specifiers. Try this:

ffmpeg -i "INPUT.mkv" \
  -filter_complex "[0:a:0]pan=stereo|FL=0.5*FC+0.707*FL+0.707*BL+0.5*LFE|FR=0.5*FC+0.707*FR+0.707*BR+0.5*LFE,volume=1.66[filtered]" \
  -map 0:v -c:v copy \
  -map [filtered] -c:a:0 ac3 \
  -map 0:a:0 -c:a:1 copy \
  "OUTPUT.mkv"

Changes: (1) named filter output as [filtered], (2) 2nd output audio stream should be a:1, (3) moved volume setting to complex_filter

Edit Note: Reflects Fabio and Lex's comments to the answer

kesh
  • 4,515
  • 2
  • 12
  • 20
  • This almost works, but volume should be adjusted only for the 2.0 stream. It also seems `-vol` has been deprecated and must be passed as an audio filter, I believe the proper way to do so is `"[0:a:0]volume=1.66,pan=stereo|FL=0.5*FC+0.707*FL+0.707*BL+0.5*LFE|FR=0.5*FC+0.707*FR+0.707*BR+0.5*LFE[filtered]"`? – Fabio Freitas Feb 15 '22 at 22:10
  • @FabioFreitas You can replace `[filtered]` in @kesh's complex filter with `[a];[a]volume=1.66[filtered]`. – Lex Feb 15 '22 at 22:16
  • `-filter_complex "[0:a:0]pan=stereo|FL=0.5*FC+0.707*FL+0.707*BL+0.5*LFE|FR=0.5*FC+0.707*FR+0.707*BR+0.5*LFE[a];[a]volume=1.66[filtered]"` – Lex Feb 15 '22 at 22:18
  • It seems both versions produce the exact same file, byte for byte. I inferred my version from [this answer](https://stackoverflow.com/a/12402374/12194725), good to know that. – Fabio Freitas Feb 15 '22 at 22:23
  • 1
    @Lex - I like moving the volume filter to the end as it saves the computation a bit (2 channels vs. 6 channels) but no need to make a graph when you are butting a single-output filter with a single-input filter. – kesh Feb 15 '22 at 22:38
  • I think you can replace that multiple codecs with just two: `-map 0:v -map [filtered] -map 0:a:0 -c copy -c:a:0 ac3` - that should copy all the streams except the first audio. Am I right? – Lex Feb 15 '22 at 23:00
  • @Lex - That sounds right, but I've never verified it myself. – kesh Feb 15 '22 at 23:18