VideoHelp Forum
+ Reply to Thread
Results 1 to 11 of 11
Thread
  1. I'm using the "-ac 2" parameter in ffmpeg to downmix 8 channel audio to stereo.

    Both the 8 channel audio, and the downmixed 2 channel audio, have the same maximum amplitude of 0.0 dB. But the 8 channel audio sounds significantly louder than the downmixed stereo audio, when played back with PotPlayer with the PotPlayer's volume slider set to 100%.

    Does this mean that PotPlayer does downmixing better than "ffmpeg -ac 2"? Is "ffmpeg -ac 2" the best way to downmix, or is there a better way than this? Is SoX better at downmixing than ffmpeg?
    Last edited by codemaster; 12th Dec 2023 at 11:36.
    Quote Quote  
  2. There is many information about correct downmix for 5.1 to sterero, g.e.
    https://superuser.com/questions/852400/properly-downmix-5-1-to-stereo-using-ffmpeg
    Read this and make some tests for 8ch to 2ch.
    Quote Quote  
  3. I want to use Dave_750's downmix formula instead of "-ac 2", but I can't because it's for 5.1 channels.
    Code:
    -af "pan=stereo|c0=0.5*c2+0.707*c0+0.707*c4+0.5*c3|c1=0.5*c2+0.707*c1+0.707*c5+0.5*c3"
    If I need to downmix 7.1 to 2.0, do I have to add two extra channels to this formula?
    Last edited by codemaster; 12th Dec 2023 at 23:51.
    Quote Quote  
  4. You can add the missing ch7 and ch8 with a factor you like, but the sum of all channels should not go to high to avoid clipping.
    But you could also use it as it is and omit the missing channels.
    Quote Quote  
  5. I made sure to prevent clipping by using the ffmpeg's "volume" filter to lower volume of input enough to prevent maximum amplitude of output to increase above -1 dB. For "-ac 2" I had to use "volume=-8.2dB" to get -1 dB max amplitude. But is there any disadvantage if I omit channels 7 and 8 when downmixing to stereo?
    Last edited by codemaster; 13th Dec 2023 at 11:52.
    Quote Quote  
  6. You could open the 8ch audio in audacity and listen to ch7 and ch8 only, so you know what you're missing.
    Quote Quote  
  7. Originally Posted by codemaster View Post
    I made sure to prevent clipping by using the ffmpeg's "volume" filter to lower volume of input enough to prevent maximum amplitude of output to increase above -1 dB. For "-ac 2" I had to use "volume=-8.2dB" to get -1 dB max amplitude.
    With -ac 2, no volume change should be necessary to avoid clipping.
    The reason why -ac 2 is not ideal for a 5.1 downmix is that the surround elements are too loud and the speech (FC channel) is too quiet.
    Quote Quote  
  8. I tested with "-ac 2" and Dave_750's formula. Source is 8 channel live concert, with -0.0 dB maximum volume. Both outputs have -1.0 dB maximum volume. Live song at 1:57:29 is 1 dB louder with the "-ac 2" formula, compared with Dave_750's formula.

    But the source 8 channel audio stream is several dB louder than this when played back with PotPlayer. And the same live song on YouTube has the same low volume as I have after downmixing with both formulas.

    The commands I used to downmix:
    Code:
    ffmpeg -i infile.mkv" ^
    -filter:a "volume=-8.2dB" ^
    -ac 2 -codec:a pcm_f32le ^
    outfile.wav
    Code:
    ffmpeg -i infile.mkv" ^
    -filter:a "volume=-4.7dB, pan=stereo|c0=0.5*c2+0.707*c0+0.707*c4+0.5*c3|c1=0.5*c2+0.707*c1+0.707*c5+0.5*c3" ^
    -codec:a pcm_f32le ^
    outfile.wav
    Last edited by codemaster; 13th Dec 2023 at 16:39.
    Quote Quote  
  9. I would omit the volume adjustment.
    Quote Quote  
  10. Originally Posted by codemaster View Post
    I tested with "-ac 2" and Dave_750's formula. Source is 8 channel live concert, with -0.0 dB maximum volume. Both outputs have -1.0 dB maximum volume. Live song at 1:57:29 is 1 dB louder with the "-ac 2" formula, compared with Dave_750's formula.

    But the source 8 channel audio stream is several dB louder than this when played back with PotPlayer. And the same live song on YouTube has the same low volume as I have after downmixing with both formulas.
    Potplayer, or your sound card, is probably downmixing to stereo without reducing the volume to prevent clipping, so it sounds louder than a stereo version where the volume was reduced while downmixing to prevent it.

    For MPC-HC / Lav Filters you can enable a "normalise matrix" which means the volume is reduced according to the number of source channels so after they're combined the output can't have clipping. A normalize matrix is usually a "worst case scenario" volume reduction. The volume is reduced enough to prevent clipping even if all the channels have peaks at maximum at the same time. If they don't the downmixed stereo might be a bit quieter than it needs to be.

    Image
    [Attachment 75522 - Click to enlarge]


    This is the example in the ffmpeg docs for downmixing 7.1ch.
    I'd probably increase the center channel volume.
    I haven't tried it myself as I don't re-encode audio with ffmpeg directly a great deal, but.....
    https://ffmpeg.org/ffmpeg-all.html#pan-1
    If the = in a channel specification is replaced by <, then the gains for that specification will be renormalized so that the total is 1, thus avoiding clipping noise.

    pan=stereo| FL < FL + 0.5*FC + 0.6*BL + 0.6*SL | FR < FR + 0.5*FC + 0.6*BR + 0.6*SR

    Foobar2000 comes with a "downmix to stereo" DSP. It has no options though and I don't know the formula it uses, but it can be added to both the playback and conversion chains.
    The version of foobar2000 I've linked to below also comes with the Matrix Mixer component. You can add it to the playback chain while you fiddle around, save it as a DSP preset and then add that preset to the conversion chain. You can adjust the downmix however you like, and with the "normalize" box checked, it'll automatically reduce the over-all volume to prevent clipping. A 7.1ch to stereo downmix might look like this:

    Image
    [Attachment 75524 - Click to enlarge]


    foobar2000 might come with a bit of a learning curve at first, but it's worth it if you do a lot of audio encoding.
    foobar2000 portable (for audio encoding)
    There's also a 7.1ch->2ch preset I created that you might want to try. It combines the left surround channels without changing the volume (same with the right), then runs the resulting 5.1ch through a limiter in case combining the surround channels caused clipping, and from there it downmixes the 5.1ch to stereo using a standard formula. I borrowed the idea from tebasuna51 at doom9. MeGUI uses his Avisynth script for downmixing 7.1ch to 2ch in much the same manner.
    Last edited by hello_hello; 14th Dec 2023 at 09:18.
    Quote Quote  
  11. I downmixed again without adjusting volume:
    Code:
    ffmpeg -i infile.mkv ^
    -ac 2 -codec:a pcm_f32le ^
    outfile.wav
    And now live song at 1:57:29 is much louder than before, and is not barely audible like before. In the previous downmixed file, it was barely audible because I was using the volume filter because I thought if I don't, there will be clipping. It seems "-ac 2" prevents clipping somehow, and I wasn't aware of that.
    Last edited by codemaster; 14th Dec 2023 at 17:01.
    Quote Quote  



Similar Threads

Visit our sponsor! Try DVDFab and backup Blu-rays!