Bash 脚本在 while 循环中停止执行 ffmpeg - 为什么? [英] Bash script stops execution of ffmpeg in while loop - why?
问题描述
我有这个 bash 脚本,用于将 .mp4
视频转换为 .mp3
音频.它运行,但只循环一次,尽管 /home/myname/mp4dir
中有更多 mp4 文件.
I have this bash script for converting .mp4
video to .mp3
audio.
It runs, but does the loop only once, though there are more mp4 files in /home/myname/mp4dir
.
脚本将它找到的第一个 .mp4
文件转换为 .mp3
,除非已经存在 .mp3
文件.这应该在循环中完成,但在第一次调用 ffmpeg 后脚本停止.
The script converts the first .mp4
file it finds to .mp3
, unless there is already an .mp3
file. This should be done in a loop, but after the first call to ffmpeg the script stops.
为什么?
#!/bin/bash
find /home/myname/mp4dir -name "*.mp4" | while read f
do
fOut=`echo $f | sed s/mp4/mp3/`
echo "convert $f => $fOut"
if ! test -f $fOut
then
ffmpeg -i $f -vn -f mp3 $fOut
fi
done
推荐答案
从我们得到的评论来看,实际上有你正在循环的输入文件(无论哪种),并且至少 ffmpeg
开始一次.然后,你被卡住了.
From the comments we got that there actually are input files you are looping over (of what kind soever) and that ffmpeg
at least starts once. Then, you are stuck.
添加
&> ffmpeg.outerr < /dev/null
到您的 ffmpeg
命令并在您的循环"(即 ffmpeg)执行时监视文件 ffmpeg.outerr
.它会告诉你问题是什么.您可以自己解决这个问题,也可以使用标签 ffmpeg
回到 stackoverflow 解决这个 ffmpeg 特定问题.
to your ffmpeg
command and monitor the file ffmpeg.outerr
while your "loop", i.e. ffmpeg, executes. It will tell you what the problem is. Either you can solve this problem yourself, or you come back to stackoverflow with this ffmpeg-specific problem using the tag ffmpeg
.
这篇关于Bash 脚本在 while 循环中停止执行 ffmpeg - 为什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!