Jump to content

Script to change the Audio default on 4K Remux's


rbjtech
 Share

Recommended Posts

rbjtech

Hi All,

As you may be aware, one of the problem areas for 4K playback (HEVC) on any TV that does not directly support HD Audio via an Emby Client (ie ALL TV's that I am aware of..) or is not connected to an Emby Client + AVR capable of direct playing HD Audio - is that unless you change the Audio track to one that will playback (EAC3, AC3 or if you're lucky DTS) - it will force the playback to transcode, resulting in a loss of video quality, loss of HDR/DV etc and loss of audio quality from HD-Audio to reduced bitrate AC3.

The key issue is the HD Audio track, be it Tru-HD/Atmos or DTS-HD/X is normally the Default track.  Emby's current logic uses this as the track it will try and play - it does not try and select alternative tracks - even if they are available.

So this is a 'Work In progress' thread to try and understand what is needed to make this 'decision/logic' based on various metedata attributes within the source files.

It's easy enough to extract the attributes with the likes of ffprobe - the issue is which ones and what can be relied upon to make informed decisions.

My thoughts are as follows -

  • Codec Short Name (ac3, dts, truhd etc)
  • Channels (8 = 7.1 (likely Atmos/DTS-X), 6 = 5.1 (likely AC3/DTS), 2 = Stereo etc)
  • Default Audio Track Now
  • Is the Audio Track marked as 'Forced' ?
  • Is the Audio Track marked as 'Hearing Impaired' ? 
  • Audio Track Language
  • Audio Track 'Title' - This is free text, so it cannot be replied upon but we should be able to search for key words to potentially make a decision.

Using the above metadata on a example file - I get the following :-

ffprobe.exe -hide_banner -loglevel panic -show_entries stream=index,codec_name,channels -show_entries stream_tags=language,title -show_entries stream_disposition=default,forced,hearing_impaired -select_streams a -of default=noprint_wrappers=1 -print_format csv "example.mkv"

stream,1,truehd,8,1,0,0,eng,Surround 7.1
stream,2,ac3,6,0,0,0,eng,Surround 5.1
stream,3,ac3,2,0,0,0,eng,Commentary 1
stream,4,ac3,2,0,0,0,eng,Commentary 2

So we can see Audio Track 1 is the current default and thus it would force a transcode if I tried to play it - but what other tracks do I have available ?

Track 2 - it is AC3 (playable), it is 5.1, it is English -   This sounds promising.

Track 3 - it is AC3 (playable), it is Stereo Only, it is English  - So not ideal as it's only Stereo - this is LIKELY to be a commentary track.

Track 4, it is AC3 (playable), it is Stereo Only, it is English - So not ideal as it's only Stereo - this is LIKELY to be a commentary track.

.. so in summary, it was reasonably easy to determine that Audio Track 2 is a perfect alternative to trying to use Track 1.

Now I know this, I can simply use 'mkvpropedit' (via a script) to modify the Default Audio track (no remuxing is needed, it just modifies the header) to use Track 2 - and my problem is solved.

Now I appreciate there are MANY combo's here - dts will need a combination of dts and channels to determine if it's dts-hd or plain dts 5.1 - but either way, we should set the Default to AC3 or EAC3 if we can to guarantee playback without transcoding.

Anyway - just thought I've post this to share my thoughts but would welcome any feedback and other key 'decision attributes'  that I have no doubt completely forgotten about !

Thanks.

;)

 

 

 

 

Link to comment
Share on other sites

rbjtech

So the first part is done - it appears to work well in the limited testing I've done (yea it's batch script - kill me..)

From all your 4K files - this 'finds' the first audio track specified in the script - ready for the next part which is to pass this to mkvpropedit to set the new Default Audio Track...

@echo off
setlocal ENABLEDELAYEDEXPANSION

rem set Default track preferences below ..

set language=eng
set codec=ac3
set /A channels=6

FOR /F "delims=" %%x in ('dir /a-s /b /s *.mkv') DO (

	echo.	
	echo Working on : %%x
	echo.

	"C:\emby-server\system\ffprobe.exe" -hide_banner -loglevel panic -show_entries stream=index,codec_name,channels -show_entries stream_tags=language,title -show_entries stream_disposition=default,forced,hearing_impaired -select_streams a -of default=noprint_wrappers=1 -print_format csv "%%x" > temp.csv

	set default_audio_track=1
	set /A count=1

	FOR /F "eol= tokens=1-9 delims=," %%a in (temp.csv) DO (

		set stream_=%%a
		set stream_num=%%b
		set stream_codec=%%c
		set stream_channels=%%d
		set stream_default=%%e
		set stream_forced=%%f
		set stream_hi=%%g
		set stream_language=%%h
		set stream_title=%%i

		rem If codec AND channels AND Language = TRUE - then select as Default Track

		if !stream_codec!==!codec! (
			if !stream_channels!==!channels! (
				if !stream_language!==!language! (

						rem Counter used to only set first true condition otherwise last found will be used (bad)

						if !count!==1 set default_audio_track=!stream_num!
						echo.
						echo TRUE Condition Found {!count!} :
						echo Track #		: !stream_num!
						echo Codec		: !stream_codec!
						echo Channels	: !stream_channels!
						echo Language	: !stream_language!
						echo Title		: !stream_title!
						set /A count=!count!+1
						rem end if stream_language
						) 	
					rem end if stream_channels
					)
				rem end if stream_codec
				)

	rem end temp.csv FOR loop
	)

	if !count!==1 echo No alternative audio track found  

	echo.
	echo Default Audio Track : !default_audio_track!
	echo.

pause

rem end *.mkv FOR loop
)

 

Link to comment
Share on other sites

rbjtech

Forgot to add the conditions to reject if 'Title' contains 'commentary' etc and also reject if it's a HI track ... not sure about Forced - I think that's used for subs only - I've never seen a 'Forced' Audio track ..

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...