I have 3 versions of the ffmpeg command and none of them are perfect... I am stuck. Below are the examples I have and the issues I face with each version:
ffmpeg -i "%%a" -map 0:v:0 -map 0:a:m:language:eng -c copy -f matroska - | ffmpeg -i - -map 0:v -map 0:a:0 -c copy -c:a eac3 -metadata:s:a:0 title="EAC3 Transcoded" -b:a:0 640k "%%~dpna.EACConverted%%~xa"
This version of the command does transcodes the primary audio track to EAC3, labels it, sets the EAC3 as first/primary track. It also DOES keep only English tracks and removes all others! Removes subtitles, but sadly does NOT keep the original audio track in the original format (i.e DTS converted to EAC3, DTS will be missing.)
ffmpeg -i "%%a" -map 0:v -map 0:a:0 -map 0:a -c:v copy -c:a copy -c:a:0 eac3 -metadata:a:0 title="EAC3 Transcoded" -b:a:0 640k "%%~dpna.EACConverted%%~xa"
This version of the command does remove the subtitles; transcodes the primary audio track to EAC3, labels it, sets the EAC3 as first/primary track, but it also DOES keep the original track before the transcode! (i.e DTS converted to EAC3, DTS will still be there) But the issue with this is it does NOT keep only English tracks. If I have a Chinese track, it will remain.
ffmpeg -i "%%a" -map 0:v:0 -map 0:a:m:language:eng -c copy -f matroska - | ffmpeg -i - -map 0:v -map 0:a:0 -c copy "%%~dpna.EACConverted%%~xa"
This version of the command extracts the 1st video track, English audio tracks from the file, deletes all other tracks and subtitles.(So it DOES keep only English tracks!) But it does not transcode the audio if DTS to EAC3, label it, etc.
I want something that is a mix of these, that does it all, that would mean it transcodes the primary audio track (lets say, DTS) to EAC3, labels it, sets the EAC3 as first/primary track. It also does keep only English tracks and removes all others, and would keep the original English DTS track after the transcode.
The complete example is:
@echo off
cls
set rootfolder="M:\Movies\"
echo Enumerating all MKVs under %rootfolder%
echo.
for %%a in (*.mkv) do (
for /f %%b in ('mkvmerge -i "%%a" ^| find /c /i "TrueHD"') do (
if [%%b]==[0] (
echo "%%a" has no TrueHD Audio
) else (
echo.
echo "%%a" has TrueHD Audio
ffmpeg -i "%%a" -map 0:v:0 -map 0:a:m:language:eng -c copy -f matroska - | ffmpeg -i - -map 0:v -map 0:a:0 -c copy -c:a eac3 -metadata:s:a:0 title="EAC3 Transcoded" -b:a:0 640k "%%~dpna.EACConverted%%~xa"
if errorlevel 1 (
echo Warnings/errors generated during remuxing, original file not deleted
) else (
del /f "%%a"
echo Successfully remuxed to "%%~dpna.EACConverted%%~xa", original file deleted
)
echo.
)
)
)