我把在这里(也许在其他一些网站上)找到的所有东西都用了,创建了一个小工具,不仅可以递归创建flac的mp3,还可以保留相对路径以在多线程支持下在其他地方创建它们。
哦,是的,我知道,在那种情况下,我没有使用ffmpeg,因为我的OSMC没有提供ffmpeg的软件包,只有avconv,但由于您已经在这里,我想您知道,这基本上是同样-至少对于最重要的部分。只需将命令“ avconv”替换为“ ffmpeg”即可。我的第一次运行是使用ffmpeg bin和完全相同的选项。
我绝不是bash黑客,但我做到了,因为我的第一个bashscript具有给定的要求,也许有人会受益。我愿意接受您的任何建议,但到目前为止它对我有用。
我的脚本启动了四个实例,每个核心一个,如下所示:
#!/bin/bash
# this should be quite self-explanatory
for i in {1..4}
do
echo "started instance no: $i"
/home/osmc/transform.sh . &
# sleeping time can be shorter, this is just so, that
# not all 4 processes will want to start with the same
# file, during runtime collisions should not become an issue
sleep 5
done
echo "all instances started"
像这样的工作脚本:
#!/bin/bash
# take care of spaces
IFS=$'\n'
# my music folders, remote is the source, local the target dir
remote=/mnt/music/FLAC
local=/mnt/1tb/mp3
# for all flac files start loop
for i in $(find $remote -type f -iname '*.flac' );
do
## SET VARIABLES for PATHS and FILENAMES
## this might be able to be super short with sed and complex one-liner,
## but I s*ck at regex
fullfile=$i
# strip extension
filename="${i##*/}"
# add new extension
filename="${filename%.*}.mp3"
# get full dirname from inputfile
fulldir=$(dirname "${i}")
# strip leading dirs from full input dir
# count the dirs, add two, then you're good.
reldir="$(echo $fulldir | cut -d'/' -f5-)"
# some subdirs in my collection even have a flac subdir, you might
# ignore this, it strips only if it exists
reldir=${reldir//flac}
# combine target dir and relative dir
outdir="$local/$reldir"
# generate the full output filename for conversion
outfile="$outdir/$filename"
# create whole target directory - yes, I need it only once, but hey,
# it works, didn't want to start a if not exist statement... should I?
mkdir -p "$outdir"
# run conversion - finally... you may want or need to replace
# "avconv" with "ffmpeg"
avconv -n -nostats -loglevel info -i "$fullfile" -codec:a libmp3lame -qscale:a 0 "$outfile"
done
可以在https://github.com/erdnuesse/flac-to-mp3上找到
问候,凯