bash通过文件路径列表循环-发送到ffmpeg时字符被删除

时间:2018-10-09 04:34:31

标签: bash shell loops ffmpeg

我有一个文本文件,其中包含要转换为wav的flac文件的路径列表。这是其中的一小部分:

/mnt/nfs/Music/Rob D/1995 - Clubbed To Death/Rob D - 02 - Clubbed To Death _Kurayamino Variation_.flac
/mnt/nfs/Music/Blonde Redhead/2000 - Melody of Certain Damaged Lemons/11 - For the Damaged Coda.flac
/mnt/nfs/Music/I Monster/2001 - Daydream In Blue/01 - Daydream In Blue.flac
/mnt/nfs/Music/Moby/2002 - Extreme Ways/01 - Extreme Ways.flac
/mnt/nfs/Music/RJD2/2002 - Deadringer/01 - The Horror.flac
/mnt/nfs/Music/RJD2/2002 - Deadringer/03 - Smoke & Mirrors.flac
/mnt/nfs/Music/RJD2/2002 - Deadringer/06 - Ghostwriter.flac
/mnt/nfs/Music/RJD2/2002 - Deadringer/10 - Chicken-Bone Circuit.flac
/mnt/nfs/Music/FC Kahuna/2003 - Hayling/01 - Hayling _Original_.flac
/mnt/nfs/Music/Lamb/2003 - Between Darkness and Wonder/04 - Angelica.flac

我试图像这样循环遍历它:

while read -r line; do
 wavfile=$(basename "$line")
 wavfile="${wavfile%.*}"
 ffmpeg -i "$line" "$2/$wavfile.wav"
done <$1

......其中$ 1是我将传递文本文件名称的位置,$ 2是目标目录。

以下是不相关的ffmpeg垃圾被删除的输出:

Input #0, flac, from '/mnt/nfs/Music/Rob D/1995 - Clubbed To Death/Rob D - 02 - Clubbed To Death _Kurayamino Variation_.flac':
...
Output #0, wav, to '/mnt/gray/Clubbed To Death/Rob D - 02 - Clubbed To Death _Kurayamino Variation_.wav':
...
/nfs/Music/Blonde Redhead/2000 - Melody of Certain Damaged Lemons/11 - For the Damaged Coda.flac: No such file or directory
...
Input #0, flac, from '/mnt/nfs/Music/I Monster/2001 - Daydream In Blue/01 - Daydream In Blue.flac':
...
Output #0, wav, to '/mnt/gray/Clubbed To Death/01 - Daydream In Blue.wav':
...
nt/nfs/Music/Moby/2002 - Extreme Ways/01 - Extreme Ways.flac: No such file or directory
...
Input #0, flac, from '/mnt/nfs/Music/RJD2/2002 - Deadringer/01 - The Horror.flac':
...
Output #0, wav, to '/mnt/gray/Clubbed To Death/01 - The Horror.wav':
...
nt/nfs/Music/RJD2/2002 - Deadringer/03 - Smoke & Mirrors.flac: No such file or directory
...
Input #0, flac, from '/mnt/nfs/Music/RJD2/2002 - Deadringer/06 - Ghostwriter.flac':
...
Output #0, wav, to '/mnt/gray/Clubbed To Death/06 - Ghostwriter.wav':
...
nt/nfs/Music/RJD2/2002 - Deadringer/10 - Chicken-Bone Circuit.flac: No such file or directory
...
Input #0, flac, from '/mnt/nfs/Music/FC Kahuna/2003 - Hayling/01 - Hayling _Original_.flac':
...
Output #0, wav, to '/mnt/gray/Clubbed To Death/01 - Hayling _Original_.wav':
...
/nfs/Music/Lamb/2003 - Between Darkness and Wonder/04 - Angelica.flac: No such file or directory

如果您注意ffmpeg报告不存在的路径,您会发现从一开始就删除了看似随机的字符数。这似乎发生在偶数行上,但是奇数行有效。我只能在使用ffmpeg时重现此行为。如果我用简单的echo语句替换ffmpeg行,则显示每个文件路径都是正确的。怎么会这样?

也欢迎提出其他建议,但我确实需要按照文件中列出的顺序处理文件。

1 个答案:

答案 0 :(得分:0)

Cyrus的链接确实引导我找到了解决方案。在调用ffmpeg时将/ dev / null发送到stdin解决了我的问题。这是运行循环的样子:

while read -r line; do
 wavfile=$(basename "$line")
 wavfile="${wavfile%.*}"
 ffmpeg -i "$line" "$2/$wavfile.wav" </dev/null
done <$1