问题描述
我需要使用mplayer通过循环获取视频缩略图,但是mplayer给我错误.但是,相同的命令可以在循环外正常工作
I need to get video thumbnails with mplayer using a loop,but mplayer gives me error.However the same command works fine out of the loop
如何防止我的命令受循环影响?
How do I prevent my command is affected by the loop?
我试图封装在子外壳中或重定向到stdin/stdout ...但是我失败了
I've tried to encapsulate in a sub-shell or redirected stdin / stdout ... but I fail
这是代码
while read video; do
....
mplayer -ss 60 -nosound -vo jpeg -frames 1 "$video"
done < video_list.txt
输出mplayer
......
No bind found for key '~'.
No bind found for key 'l'.
No bind found for key 'b'.
No bind found for key 'H'.
No bind found for key 'R'.
No bind found for key 'Y'.
No bind found for key 'B'.
No bind found for key '"'.
No bind found for key 'l'.
No bind found for key '='.
No bind found for key '"'.
No bind found for key '"'.
Dead key input on file descriptor 0
===== PAUSE =====
Exiting... (Quit)
推荐答案
问题:mplayer不断读取stdin并影响其执行,直到失败为止.
Problem: mplayer keeps reading stdin and that affects its execution until it fails.
解决方案选项:
A)告诉mplayer不要读JNevill指出的标准输入
A) Tell mplayer NOT to read stdin as JNevill well indicated
mplayer -noconsolecontrols -ss 60 -nosound -vo jpeg -frames 1 "$video"
B)提供一个空的stdin输入(带有</dev/null
)
B) Provide an empty stdin input (with </dev/null
)
mplayer -ss 60 -nosound -vo jpeg -frames 1 "$video" </dev/null
我从 https://bugs.launchpad.net获得了B) /ubuntu/+ source/mplayer/+ bug/697655 (在下面提取)
"不可能在循环中运行mplayer,因为即使只是为了批量转换文件而调用它,它也会消耗标准输入.
"Running mplayer in a loop is impossible because it consumes standard input even when invoked just to batch convert a file.
考虑如下脚本:
find . -type f |
while read file; do
echo "# $file"
mplayer -vc null -vo null -ao pcm:file="$file.wav" "$file"
done
这将神秘地失败,并显示未找到键'O'的绑定"警告等,因为显然mplayer正在吃掉find命令的某些输出,就好像用户正在交互使用它并按下键来调整显示大小一样.另外一个症状是,回显的输出将神秘地包含文件名.
This will fail mysteriously with "No bind found for key 'O'" warnings etc because apparently mplayer is eating some of the output from the find command as if the user were using it interactively and pressing keys to resize the display etc. As an additional symptom, the output from the echo will mysteriously have chopped file names.
作为一种解决方法,可以通过添加重定向来修复上面的小示例脚本
Google中有几个与此相关的主题,但我发现没有一个主题可以正确诊断并更正此问题."
As a workaround, the small sample script above can be fixed by adding a redirection
There are several threads about this in Google but none I have found actually correctly diagnosed and corrected this problem."
这篇关于使用mplayer循环获取视频缩略图时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!