Use FFmpeg to convert a DTS soundtrack to AC3 without re-encoding video

Problem:
Some Plex players do not give Plex full access to the OS/hardware for DTS decoding. This means that Plex will then have to transcode the audio which can mean lots of buffering or in the case of the Xbox One X will force 4K video to be transcoded to 1080p.  You may also find that If you don’t have a true 5.1 channel audio system (such as some soundbars) you may find that DTS soundtracks are quiet when used with media players suck as Kodi, Plex or Windows media player.  As the Xbox One X fully supports Plex using AC3 the solution below also solved many audio sync issues for me that seemed to occur when the DTS audio was being transcoded.  After running my .mkv files through the below script I had an .mkv file that I could play on Xbox One X which had clear/loud audio, would direct play (including 4K HDR) and had no audio sync issues.

Solution:
There was no solution I could find within the applications or the audio systems to correct this.  The only solution was to re-encode the audio track using FFmeg.  The below script takes a DTS audio track from a file and re-encodes it to 5.1 channel AC3.  For me this made the soundtrack much louder and especially made a difference to dialog.  Fortunately using this method means that you only have to re-encode the audio not the video so only takes a few minutes even on an old core i5.

In it’s the simplest form you can just use the command as below:

C:\ffmpeg\bin\ffmpeg.exe -i "F:\temp\Video.mkv" -map 0 -vcodec copy -scodec copy -acodec ac3 -b:a 640k "c:\temp\Video.mkv"

 

This script will ask you for a path to a file and then convert the file entered from DTS to AC3

Add-Type -AssemblyName Microsoft.VisualBasic

$Filepath = [Microsoft.VisualBasic.Interaction]::InputBox('Enter file path', 'File Path')

$NewFilepath = $Filepath -replace ("`"","")

$source = Get-ChildItem -path $NewFilepath -Recurse -Include *.mkv, *.mp4, *.avi
	
	
$ffpath = "C:\ProgramData\chocolatey\lib\ffmpeg\tools\ffmpeg\bin\ffmpeg.exe"



	
$DirOut = "D:\Temp"
$output = Join-Path $DirOut -ChildPath ((Get-Item $source).basename + ".mkv")

 
& $ffpath -i $source -map 0 -vcodec copy -scodec copy -acodec ac3 -b:a 640k $output -loglevel 8 -stats

 

The script below will simply convert any .mkv file that you drop into the ‘Convert’ folder from DTS to AC3:

$source = Get-ChildItem -path "F:\Convert*" -Recurse -Include *.mkv
	
	
$ffpath = "C:\ProgramData\chocolatey\lib\ffmpeg\tools\ffmpeg\bin\ffmpeg.exe"



	
$DirOut = "F:\Converted"
$output = Join-Path $DirOut -ChildPath ((Get-Item $source).basename + "_out.mkv")

 
& $ffpath -i $source -map 0 -vcodec copy -scodec copy -acodec ac3 -b:a 640k $output -loglevel 8 -stats

 

This code will allow you to drop in a number of files and loop through all the .mkv files converting the soundtracks from DTS to AC3:

$sources = Get-ChildItem -path "F:\Convert*" -Recurse -Include *.mkv
	
	
$ffpath = "C:\ProgramData\chocolatey\lib\ffmpeg\tools\ffmpeg\bin\ffmpeg.exe"

foreach ($source in $sources)
	
{$DirOut = "D:\Temp"
$output = Join-Path $DirOut -ChildPath ((Get-Item $source).basename + ".mkv")

 
& $ffpath -i $source -map 0 -vcodec copy -scodec copy -acodec ac3 -b:a 640k $output -loglevel 8 -stats}




11 Replies to “Use FFmpeg to convert a DTS soundtrack to AC3 without re-encoding video”

  1. This is awesome, Robin. The simple instructions above not only converted the DTS to AC3, but more importantly the newly created AC3 track IS IN SYNC with the video from beginning to end! This was NOT the case with some half-a-dozen other free methods that I wasted many hours experimenting with, e.g. Popcorn MKV Audio Converter, Pazera Free Audio Extractor, etc.

    I do have a question, though. If possible, could you please modify the initial command above so that the resultant mkv contains not only the newly converted AC3 but also the original DTS as a second audio option? Thanks again for solving this difficult problem.

  2. Hello
    have a number of video files which won’t play on my TV as they have DTS audio. I have a commercial program Bigasoft Video converter, which will do the job, but it will take forever, even only converting the audio.

    I am told FFMpeg would be a better quicker way to go, but not comfortable with command line instructions.

    don’t want to have to change the name of every video file, was hoping for a Batch method, to do this conversion, without renaming the video files.

    Looked at the code shown, but what is chocolatey ???

    thanks

  3. The script below will simply convert any .mkv file that you drop into the ‘Convert’ folder from DTS to AC3:
    I used this routine with great success, thanyou
    couple of questions
    1- Is it easy to change to allow the source video to be in a different folder
    2-and Is it easy to change to allow the output video to be in a different folder
    3-is it possible to create folders with the converted files as in the source folder

    thanks

    this is awesome, i had so many DTS video files, now i can convert to AC3 so easily and quickly

  4. save in notepad as .PS1 file, chose other filetypes…..then when you open it, will run powershell, if not make sure its associated with it, or do open with, find powershell and tick use this in future

  5. A friend created this to allow different source and target directories

    But gives several errors, could you help please ?

    :: convert all mkv files in a source Folder to mkv with AC3 using ffmpeg
    :: eg. source T:\Old mkvs and eg.destination D:\New mkvs

    :———————————————————————————————————————————–
    :: first edit the two Directory values for the Source and Destination “and” the path of ffmpeg
    :———————————————————————————————————————————–

    SET Source_Files_Dir=T:\Old mkvs
    SET Converted_Files_Dir=D:\New mkvs
    SET ffmpeg=C:\mp4v\ffmpeg\ffmpeg.exe

    cd /d %Converted_Files_Dir%
    for /F “delims=” %%a in (‘dir /b /s “%Source_Files_Dir%”\*.mkv’) do (
    “%ffmpeg%” -i “%%a” -map 0 -an -vcodec copy -scodec copy -acodec ac3 -b:a 640k “%%~na_out.mkv” -loglevel 8 -stats
    )
    pause
    exit

Leave a Reply

Your email address will not be published. Required fields are marked *