Bash脚本以递归查找和转换电影 [英] Bash script to recursive find and convert movies
问题描述
在我的大型电影收藏中,我想搜索具有DTS编码的主要(第一)音轨的电影,并将其转换为杜比(Dolby).
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.
我的问题将是我认为的第一条曲目.我当前的bash脚本将列出所有包含DTS曲目的电影,但未指定哪个曲目.
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
之后,我想运行此命令
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
或者是否有办法将所有音频轨道下移并添加新的AAC轨道?
or is there a way to move all the audio tracks down and adding the new AAC track?
###进度
由于@llogan,我已经对bash进行了微调以找到所需的文件.
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
推荐答案
好,所以我对脚本进行了微调以分隔dts和dts-hd.我得出的结论是不需要这样做,因为我无法将dts-hd解码为e-ac3,也可能将其编码为ac3.但是我在bash中玩得很开心.
Ok, so i finetuned the script to seperate dts and dts-hd. I came to the conclusion this was not needed because i cant decode dts-hd to e-ac3 and may as well also encode it to ac3. But i had fun in bash.
当前bash:
#!/bin/bash
# My DTS conversion script
# credits to llogan
find /MyMovies -name '*.mkv' | while read f
do
function codec_profile {
ffprobe -v error -select_streams a:0 -show_entries stream=$1 -of csv=p=0 "$f"
}
#first check for audio format
if [ "$(ffprobe -v error -select_streams a:0 -show_entries stream=codec_name -of csv=p=0 "$f")" = "dts" ]; then
if [ "$(codec_profile "profile")" = "DTS" ]; then
echo "$f" >> dts.txt
codec_profile "profile" >> dts.txt
codec_profile "channels" >> dts.txt
if [ "$(codec_profile "channels")" -gt 5 ]; then
echo "check" >> dts.txt; else
echo "stereo" >> dts.txt;
fi
else [ "$(ffprobe -v error -select_streams a:0 -show_entries stream=profile -of csv=p=0 "$f")" = "DTS-HD MA" ];
echo "$f" >> dts-hd.txt
codec_profile "profile" >> dts-hd.txt
codec_profile "channels" >> dts-hd.txt
fi
fi
done
我检查了创建的txt文件,结果为现场操作.我还测试了@llogan给我的命令,并且可以完美地工作.
I checked the created txt files and the result is spot op. I also tested the command that @llogan gave me and works perfect.
ffmpeg -i "$f" -map 0 -map -0:a -map 0:a:0 -map 0:a -c copy -c:a:0 ac3 -b:a:0 640k /tmp/output.mkv
最后要弄清楚的是如何检查退出代码并用此命令替换文本文件的创建
Last thing to figure out is how to check the exit code on this and replace the text file creation with this command
想法:
ffmpeg -i "$f" -map 0 -map -0:a -map 0:a:0 -map 0:a -c copy -c:a:0 ac3 -b:a:0 640k /tmp/output.mkv
RC=$?
if [ "${RC}" -ne "0" ]; then
# list error in txt file and move on to next
else
# mv output file to overwrite original file
fi
这篇关于Bash脚本以递归查找和转换电影的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!