Check collection of MKVs and convert only if they have DTS

Questions involving a Windows version of FFmpeg.
Post Reply
JCDinPGH
Posts: 4
Joined: Sun Mar 24, 2019 5:15 pm

Check collection of MKVs and convert only if they have DTS

Post by JCDinPGH » Mon Jul 29, 2019 6:34 pm

I have a large collection of MKV files and would like a way to only convert the audio track if it has DTS. The conversion part is relatively easy but I can't find an automated way to check an MKV to see if it has a DTS track. I could do it manually but with the huge number of MKVs, this would take quite awhile.

Any way to check an MKV for a DTS track via software via batch?

qyot27
Posts: 84
Joined: Wed Jan 23, 2013 4:10 pm
Contact:

Re: Check collection of MKVs and convert only if they have DTS

Post by qyot27 » Tue Jul 30, 2019 5:07 am

Using a combination of bash, mediainfo, and ffmpeg:

Code: Select all

#!/bin/bash
set -e

mkdir audio-converted

if mediainfo --inform="Audio;%Format%" "$1" | grep DTS > /dev/null ; then
	ffmpeg -i "$1" -vcodec copy -acodec flac "audio-converted/${1%.*}-flac.mkv"
fi
Save that snippet as dtstest.sh, and then run it on an individual file like this:

Code: Select all

./dtstest.sh test.mkv
Which, if test.mkv has DTS, results in it copying the video stream and converting the audio to FLAC, saving it to a new MKV with "-flac" appended to the filename, in a new directory to keep the original files and the new copies separate from one another. Adjust the ffmpeg conversion command as you'd like, of course. Anyway, to process an entire directory, you can do another trick in bash:

Code: Select all

for n in *.mkv ; do ./dtstest.sh "$n" ; done
Which will scan every MKV in the directory, and every one containing DTS will have the conversion run on it.

Post Reply
'