Error getting video thumbnails with mplayer in loop

随声附和 提交于 2020-01-06 14:05:55

问题


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?

I've tried to encapsulate in a sub-shell or redirected stdin / stdout ... but I fail

This is the code

while read video; do
   ....

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


done < video_list.txt

output 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)

回答1:


Problem: mplayer keeps reading stdin and that affects its execution until it fails.

Solution options:

A) Tell mplayer NOT to read stdin as JNevill well indicated

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

B) Provide an empty stdin input (with </dev/null )

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

I got B) from https://bugs.launchpad.net/ubuntu/+source/mplayer/+bug/697655 (extract below)

" Running mplayer in a loop is impossible because it consumes standard input even when invoked just to batch convert a file.

Consider a script like:

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

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.

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. "



来源:https://stackoverflow.com/questions/29232980/error-getting-video-thumbnails-with-mplayer-in-loop

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!