in my large movie collection I would like to search for movies with the primary (first) audio track with DTS coding to be converted to Dolby.
My problem would be the first track I think. My current bash script will list any movie containing a DTS track, but does not specify which track.
#!/bin/bash
# My message to create DTS list
find /home/Movies -name '*.mkv' | while read f
do
if mediainfo "$f" | grep A_DTS; then
echo $f
fi
done
After that I would like to run this command
ffmpeg -i $f -map 0:v -map 0:a:0 -map 0:a -map 0:s -c:v copy -c:a copy -c:s copy -c:a:0 ac3 -b:a:0 640k $f
or is there a way to move all the audio tracks down and adding the new AAC track?
###Progress
Thanks to @llogan I have finetuned the bash to find the required files.
#!/bin/bash
# My DTS conversion script
# credits to llogan
find /Mymovies -name '*.mkv' | while read f
do
if ffprobe -v error -select_streams a:0 -show_entries stream=codec_name -of csv=p=0 "$f" | grep dts; then
echo "$f"
fi
done
Now digging into the command I think I may have a working command. Anybody spot a problem?
ffmpeg -i $f
-map 0:v -c:v copy
-map 0:a:0? -c:a:0 ac3
-map 0:a:0? -c:a:1 copy
-map 0:a:1? -c:a:2 copy
-map 0:a:2? -c:a:3 copy
-map 0:a:3? -c:a:4 copy
-map 0:a:4? -c:a:5 copy
-map 0:a:5? -c:a:6 copy
-map 0:a:6? -c:a:7 copy
-map 0:a:7? -c:a:8 copy
-map 0:a:8? -c:a:9 copy
-map 0:s? -c copy
-b:a:0 640k
/tmp/output.mkv
mv $f /home/DTS_BACKUP/
mv /tmp/output.mkv $f
rm /tmp/output.mkv
So the end result would look like:
#!/bin/bash
# My DTS conversion script
# credits to llogan
find /Mymovies -name '*.mkv' | while read f
do
if ffprobe -v error -select_streams a:0 -show_entries stream=codec_name -of csv=p=0 "$f" | grep dts; then
ffmpeg -i $f
-map 0:v -c:v copy
-map 0:a:0? -c:a:0 ac3
-map 0:a:0? -c:a:1 copy
-map 0:a:1? -c:a:2 copy
-map 0:a:2? -c:a:3 copy
-map 0:a:3? -c:a:4 copy
-map 0:a:4? -c:a:5 copy
-map 0:a:5? -c:a:6 copy
-map 0:a:6? -c:a:7 copy
-map 0:a:7? -c:a:8 copy
-map 0:a:8? -c:a:9 copy
-map 0:s? -c copy
-b:a:0 640k
/tmp/output.mkv
mv $f /home/DTS_BACKUP/
mv /tmp/output.mkv $f
rm /tmp/output.mkv
fi
done
question from:
https://stackoverflow.com/questions/65617649/bash-script-to-recursive-find-and-convert-movies 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…