问题
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