Wednesday, November 26, 2014

6 channel AAC to AC3 on the fly encoding on the MPV player

Old audio amplifiers usually doesn't support 6 channel AAC audio playback. Let's say that you have video file in the MKV container that contains 6 channel audio in AAC format. In the playback that file is probably downmixed to stereo.

There is no need to buy a new receiver you just need to set your video player to on-the-fly encode those 6ch AAC audio tracks to AC3 audio tracks. That on-the-fly encoding is quite easy to configurate if your video player is MPV player (MPlayer fork).

Small check list before you start


  • Your amplifiers supports Dolby Digital 5.1 (AC3) - most common format that is used in DVD's
  • Your PC is connected to the amplifier using S/PDIF cable
  • Your distribution provides MPV player and AFTEN AC3 encoder

Configure


This way it is done in Debian but you can configure it similar manner in Ubuntu, Arch etc...

First install MPV player:

$ sudo apt-get install mpv

Note: You need to enable deb-multimedia repositories

Then you should install Aften, AC3 encoder

$ sudo apt-get install aften

Then in your home directory make new directory for MPV config files:

$ mkdir .mpv

Then go to the .mpv folder and create two config files example using your filemanager. Files:

config
input.conf


Here is mine content of "config" file... the text in the red is used for AAC to AC3 on-the-fly encoding:


[default]
##################
# video settings #
##################

# Specify default video driver (see --vo=help for a list).

#vo=vdpau
#vo=xv

# Start in fullscreen mode by default.
#fs=yes

# force starting with centered window
geometry=50%:50%

# don't allow a new window to have a size larger than 90% of the screen size
#autofit-larger=90%x90%

# Disable the On Screen Controller (OSC).
#osc=no

# Keep the player window on top of all other windows.
#ontop=yes

#For both AC-3 and DTS passthrough, use ad=spdif:ac3,spdif:dts,
ad=spdif:ac3,spdif:dts,

# Default color corrections
brightness=0
contrast=0
hue=0
saturation=0


##################
# CPU Cores      #
##################

#Number of threads to use for decoding. Whether threading is actually supported depends on codec. 0 means autodetect number of cores on the machine and use that, up to the maximum of 16 (default: 0).
vd-lavc-threads=0




##################
# audio settings #
##################

# Specify default audio driver (see --ao=help for a list).
# Could contain card + device number if needed "ao=alsa:device=[hw:0,3]" - "aplay -l" -command can be used to find right device
ao=alsa
#ao=alsa:device=[hw:0,3]

# Disable softvol usage, and always use the system mixer if available.
#softvol=no

# Scale audio tempo by playback speed without altering pitch. (By default does
# nothing if playback speed is not changed. May introduce artifacts.)
#af=scaletempo

# Output 5.1 audio natively, and upmix/downmix audio with a different format.
# Audio channels - 6 = 5.1, 2 = stereo. You can keep it as 2 and still got 5.1 surround sounds if you have ac3, dts passthough
audio-channels=2


# Disable any automatic remix, _if_ the audio output accepts the audio format.
# of the currently played file.
#audio-channels=empty

#For both AC-3 and DTS passthrough, use ad=spdif:ac3,spdif:dts,
ad=spdif:ac3,spdif:dts,


#On the fly decode 6 channel AAC to AC3 aka DolbyDigital, lavcac3enc[=tospdif[:bitrate[:minchn]]]
af=scaletempo,lavcac3enc=yes:640:3



##################
# sync          #
##################

#sync every 30 frames
autosync=30

# Use 8MB input cache by default. The cache is enabled for network streams only.
#cache-default=8192

# Use 20MB input cache for everything, even local files.
cache=20000

# If a seek is issued, and the target is 1024KB past the cached range, then
# keep reading until the seek target is hit, instead of doing a real seek.
#cache-seek-min=1024

# Disable the behavior that the player will pause if the cache goes below a
# certain fill size.
#cache-pause=no

# Read ahead about 5 seconds of audio and video packets.
#demuxer-readahead-secs=5.0


##################
# VobSubs and     #
# text based     #
# subtitles      #
##################

# Align subs
# Set subtitle position. (100: as low as possible)
#subpos=100
sub-pos=100


# Anti-alias subs. (4: best and slowest)
#spuaa=4
#sub-gauss=<0.0-3.0>
sub-gauss=1.0


# Set language.
slang=fi,fin,en,eng

# Play Finnish audio if available, fall back to English otherwise.
alang=fi,en


# Find the subtitle files, autosub-match=<exact|fuzzy|all> (fuzzy: load all subs containing movie name)
sub-auto=fuzzy

# Set font encoding.
#subfont-encoding=unicode

# Set subtitle file encoding.
#unicode=no
#utf8=no

# Show capitalize versions of Ä and Ö, without this those are displayed as question marks
#subcp=iso8859-15

# Change subtitle encoding. For Arabic subtitles use 'cp1256'.
# If the file seems to be valid UTF-8, prefer UTF-8.
#sub-codepage=utf8:cp1256
#sub-codepage=iso8859-15

# Enable hardware decoding if available. Often, this requires using an certain
# video output, otherwise no hardware decoding will be used.
#hwdec=auto

# Set font size. (2: proportional to movie width)
#subfont-autoscale=2
sub-text-font-size=30

# Set font blur radius. (default: 2)
#Values: <0..20.0>
sub-text-blur=2.0

# Set font outline thickness. (default: 2)
#sub-text-outline=2.0

# Set autoscale coefficient. (default: 5)
#sub-text-scale=3.4

#Use for a widescreen tv so keeps 4:3 content from stretching
monitoraspect="16:9"

############
# Profiles #
############

# The options declared as part of profiles override global default settings,
# but only take effect when the profile is active.
# The following profile can be enabled on the command line with: --profile=vdpau
#[vdpau]
# The profile forces the vdpau VO.
#vo=vdpau
# Use hardware decoding (this might break playback of some h264 files)
#hwdec=vdpau
# Most video filters do not work with hardware decoding.
#vf-clr=yes
# You can also include other configuration files.
#include=/path/to/the/file/you/want/to/include

Optional step: Activate feature to sync your subtitles


Set G an Y keyboard keys to sync out of sync subtitles. This feature is not activated by default so you need to add following to the "input.conf" file:
g sub_step -1
y sub_step +1

Testing


Now you need MKV test file with 6 channel audio.

Download

Then play the downloaded test file:


$ mpv 6ch_aac.mkv

Now you should hear the sounds in the correct speakers. My receiver also displays the Dolby Digital icon.



1 comment:

  1. I'm starting to learn mpv and this is very interesting because my DAC doesn't support AAC.

    ReplyDelete