I have a bunch of video files with DTS audio that I need to convert to AC3. I have found commands that can do different parts of the task but I'm not sure how to put it all together to make a script that works. I have found the following script that will convert the audio from all my files to AC3 however I would prefer for it to only convert the DTS audio files to AC3. The script is as follows.
shopt -s globstar
for f in **/*.mkv;
do
fname="${f##*/}"
ffmpeg -i "$f" -c:v copy -c:s copy -c:a ac3 "/some/directory/$fname" &&
mv "/some/directory/$fname" "$f"
done
I have also found this command that will return what sort of audio codec the mkv file is using.
`ffprobe -v error -select_streams a:0 -show_entries stream=codec_name -of default=nokey=1:noprint_wrappers=1 input.mkv`
So I'm wondering how I can combine the two to create a script that will do what I want it to do. I'm guessing I can add an if function using ffprobe at the beginning of the script? Something like this...
shopt -s globstar
for f in **/*.mkv;
do
fname="${f##*/}"
if ffprobe -v error -select_streams a:0 -show_entries stream=codec_name -of
default=nokey=1:noprint_wrappers=1 "$f" | egrep "DTS"; then
ffmpeg -i "$f" -c:v copy -c:s copy -c:a ac3 "/some/directory/$fname" &&
mv "/some/directory/$fname" "$f"
fi
done
Are there any problems with that? I haven't written scripts since I was in high school playing around with my graphics calculator because I was bored so any help would be greatly appreciated.
So I think I came up with something that works for me. I'm sure someone that actually knows what they're doing could make this cleaner and more efficient but for anyone that is interested this is what I came up with...
This will search for any movies that have a DTS audio track in the directory that the script is placed in, including subdirectories, and transcode the track to AC3. It also accounts for Stereo or Surround tracks and adjusts the bitrate accordingly.