0

我需要使用循环使用 mplayer 获取视频缩略图,但 mplayer 给了我错误。但是,相同的命令在循环之外可以正常工作

如何防止我的命令受到循环的影响?

我试图封装在一个子外壳或重定向标准输入/标准输出......但我失败了

这是代码

while read video; do
   ....

    mplayer -ss 60 -nosound -vo jpeg -frames 1 "$video"


done < video_list.txt

输出播放器

......
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)
4

1 回答 1

0

问题:mplayer 一直在读取标准输入,这会影响它的执行,直到它失败。

解决方案选项

A) 告诉 mplayer 不要像 JNevill 那样读取标准输入

mplayer -noconsolecontrols -ss 60 -nosound -vo jpeg -frames 1 "$video"

B) 提供一个空的 stdin 输入(带 </dev/null

mplayer -ss 60 -nosound -vo jpeg -frames 1 "$video"  </dev/null

我从https://bugs.launchpad.net/ubuntu/+source/mplayer/+bug/697655得到 B) (摘录如下)

" 在循环中运行 mplayer 是不可能的,因为即使调用它只是为了批量转换文件,它也会消耗标准输入。

考虑如下脚本:

find . -type f |
while read file; do
 echo "# $file"
  mplayer -vc null -vo null -ao pcm:file="$file.wav" "$file"
done

这将神秘地失败,出现“没有为键'O'找到绑定”警告等,因为显然 mplayer 正在吃 find 命令的一些输出,就好像用户正在交互使用它并按下键来调整显示大小等。作为附加症状是,回显的输出会神秘地具有切碎的文件名。

作为一种解决方法,可以通过添加重定向来修复上面的小示例脚本

谷歌中有几个关于此的主题,但我没有发现真正正确诊断并纠正了这个问题。"

于 2015-11-16T13:20:25.380 回答