If your TV does not play default language stream by default, then it is not FFmpeg's fault

Your TV's media player may be hardwired to prefer English over other language audio tracks. Maybe it was you who set other languages as preferred. There is always AI to place the blame on.

In an older post, I had shown how to downmix low-volume 5.1 to listenable stereo.

Recently, I went back to that script to copy my downmix filter setting. This was because I had downloaded a few videos that had 5.1 or 6-channel audio and they were barely audible on my TV. The device showed the audio stream as Dolby Audio. This was new to me. ffprobe showed that the audio stream used eac3 codec.

After studying the eac3 encoder, I learned a new way to downmix the 5.1 audio to stereo — one using Dolby Pro Logic II downmixer. I created a Caja Action Configuration script that creates two Dolby Audio streams with it — one with headphone mode ON and other OFF. It also created a stream using my custom downmix filter strategy. For what it was worth, the original audio was added as another stream. So, three stereo streams and one surround stream.

#! /bin/bash
set -ux

### Caja Actions Configuration ###

# Context label:    Downmix surround sound to stereo
# Tooltip:          Convert 5.1 or 7.1 audio to stereo
# Command:          terminator
# Parameters:         -x bash $HOME/CajaActionsConfiguration/DownmixSurroundChannels.txt %f
# Mimetype:       video/*
# Environment:                  Count = 1

sFile="$*"
sFileDir=$(dirname "$sFile")
sFileFullName=$(basename "$sFile")
sFileName="${sFileFullName%.*}"
sExt="${sFileFullName##*.}"

sOutputFile="${sFileDir}/${sFileName}-DM.${sExt}"

# Check if it has three or more channels
iChannels=$(ffprobe -select_streams a:0 -show_entries "stream=channels" -print_format "default=nokey=1:noprint_wrappers=1"  -i "$sFile" 2> /dev/null)

if [ -z $iChannels ] || [ $iChannels -le 2 ]; then
  notify-send "Downmix surround sound" "Error: File does not have surround channels"
  echo "Downmix surround sound error: File does not have surround channels"
else
  ffmpeg -i "${sFile}" \
         -filter_complex \
           "[0:a:0]pan=stereo|FL=FL+0.5*BL+2*FC+LFE|FR=FR+0.5*BR+2*FC+LFE[a]" \
         -map 0:v:0 -map 0:a:0 -map 0:a:0 -map "[a]" -map 0:a:0 \
         -ac 2 \
         -c:v:0 copy \
         -c:a:0 eac3 -mixing_level 111 -room_type 2 -dmix_mode dplii -dsur_mode off -dsurex_mode off -dheadphone_mode off \
         -c:a:1 eac3 -mixing_level 111 -room_type 2 -dmix_mode dplii -dsur_mode off -dsurex_mode off -dheadphone_mode on \
         -c:a:2 libfdk_aac -vbr 5 \
         -c:a:3 copy \
         -metadata:s:a:0 language="ita" -metadata:s:a:0 title="Dolby Pro Logic II downmix — Headphone mode OFF" \
         -metadata:s:a:1 language="dut" -metadata:s:a:1 title="Dolby Pro Logic II downmix — Headphone mode ON" \
         -metadata:s:a:2 language="fre" -metadata:s:a:2 title="FFmpeg pan filter downmix by V. Subhash" \
         -metadata:s:a:3 language="rus" -metadata:s:a:3 title="${iChannels}-channel surround sound" \
         -disposition:a:0 default -disposition:a:1 -default -disposition:a:2 -default -disposition:a:3 -default  \
         -y "${sOutputFile}"
    if [ $? -eq 0 ]; then
    notify-send "Downmix surround sound: Success" "${sOutputFile}"
    echo "Downmix surround sound success: ${sOutputFile}"
  else
      notify-send "Downmix surround sound: Failure" "${sOutputFile}"
      echo "Downmix surround sound failure: ${sFile}"
  fi
fi

read -p "Press Enter to quit" oNothing

It initially did not work out fine. My TV continued to play the old surround stream as default. It was a hassle to pause playback and then change to a downmixed stream for each file.

TV screen grab

Even after changing the TV's language preferences to whatever is specified in the file, the media player continued to prefer the English audio stream.

After making changes to my script to identify the original audio stream as Russian, the TV player defaulted to the default audio stream specified in the file (by ffmpeg).

Screenshot of VLC player

WARNING

The original 5.1 surround audio streams seemed to have very low volume on my stereo system. Comparitively, the downmixed audio stream were very loud. If you intend on retaining the original audio like I did with the above script, then be sure to play at low volumes. Otherwise, you will damage your audio equipment and/or ears.

Notes

  • EAC3 Codec: The command ffmpeg -h encoder=eac3 gives this output.
    Encoder eac3 [ATSC A/52 E-AC-3]:
      General capabilities: dr1 
      Threading capabilities: none
      Supported sample rates: 48000 44100 32000
      Supported sample formats: fltp
      Supported channel layouts: mono stereo 3.0(back) 3.0 quad(side) quad 4.0 5.0(side) 5.0 2 channels (FC+LFE) 2.1 4 channels (FL+FR+LFE+BC) 3.1 4.1 5.1(side) 5.1
    E-AC-3 Encoder AVOptions:
    -mixing_level      <int>        E...A...... Mixing Level (from -1 to 111) (default -1)
    -room_type         <int>        E...A...... Room Type (from -1 to 2) (default -1)
       notindicated    0            E...A...... Not Indicated (default)
       large           1            E...A...... Large Room
       small           2            E...A...... Small Room
    -per_frame_metadata <boolean>    E...A...... Allow Changing Metadata Per-Frame (default false)
    -copyright         <int>        E...A...... Copyright Bit (from -1 to 1) (default -1)
    -dialnorm          <int>        E...A...... Dialogue Level (dB) (from -31 to -1) (default -31)
    -dsur_mode         <int>        E...A...... Dolby Surround Mode (from -1 to 2) (default -1)
       notindicated    0            E...A...... Not Indicated (default)
       on              2            E...A...... Dolby Surround Encoded
       off             1            E...A...... Not Dolby Surround Encoded
    -original          <int>        E...A...... Original Bit Stream (from -1 to 1) (default -1)
    -dmix_mode         <int>        E...A...... Preferred Stereo Downmix Mode (from -1 to 3) (default -1)
       notindicated    0            E...A...... Not Indicated (default)
       ltrt            1            E...A...... Lt/Rt Downmix Preferred
       loro            2            E...A...... Lo/Ro Downmix Preferred
       dplii           3            E...A...... Dolby Pro Logic II Downmix Preferred
    -ltrt_cmixlev      <float>      E...A...... Lt/Rt Center Mix Level (from -1 to 2) (default -1)
    -ltrt_surmixlev    <float>      E...A...... Lt/Rt Surround Mix Level (from -1 to 2) (default -1)
    -loro_cmixlev      <float>      E...A...... Lo/Ro Center Mix Level (from -1 to 2) (default -1)
    -loro_surmixlev    <float>      E...A...... Lo/Ro Surround Mix Level (from -1 to 2) (default -1)
    -dsurex_mode       <int>        E...A...... Dolby Surround EX Mode (from -1 to 3) (default -1)
       notindicated    0            E...A...... Not Indicated (default)
       on              2            E...A...... Dolby Surround EX Encoded
       off             1            E...A...... Not Dolby Surround EX Encoded
       dpliiz          3            E...A...... Dolby Pro Logic IIz-encoded
    -dheadphone_mode   <int>        E...A...... Dolby Headphone Mode (from -1 to 2) (default -1)
       notindicated    0            E...A...... Not Indicated (default)
       on              2            E...A...... Dolby Headphone Encoded
       off             1            E...A...... Not Dolby Headphone Encoded
    -ad_conv_type      <int>        E...A...... A/D Converter Type (from -1 to 1) (default -1)
       standard        0            E...A...... Standard (default)
       hdcd            1            E...A...... HDCD
    -stereo_rematrixing <boolean>    E...A...... Stereo Rematrixing (default true)
    -channel_coupling  <int>        E...A...... Channel Coupling (from -1 to 1) (default auto)
       auto            -1           E...A...... Selected by the Encoder
    -cpl_start_band    <int>        E...A...... Coupling Start Band (from -1 to 15) (default auto)
       auto            -1           E...A...... Selected by the Encoder
  • Dolby Pro Logic II: Dolby Pro Logic (v1) encoding encodes four-channel audio (right, left, center and rear) as stereo. The output stereo plays as stereo on stereo devices (none the wiser) but plays as four-channel audio on devices supporting Dolby Pro Logic. Similarly, Dolby Pro Logic II encodes 5.1 or 6-channel audio as four-channel audio. Using the old logic 😁️, Dolby Pro Logic II can downmix 5.1 audio all the way to stereo.
Link: | Magic Link:

Comments are not enabled yet.

For older posts, check the archives.