0

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)
Robin pilot
  • 447
  • 6
  • 15
  • What is the file `video` here. Is it a list of video files? Is it that the actual Video file? – JNevill Mar 24 '15 at 15:20
  • Also, for fun (assuming that `video` file is a list of files) change your mplayer command to `mplayer -ss 60 -nosound -vo jpeg -frames 1 "$video"` If your file locations have any oddball characters in them like spaces and whatnot, then you'll have them safely enclosed in quotes where they belong. – JNevill Mar 24 '15 at 15:24
  • Yes `textfile` is a list of video files, sorry. And name files not contain spaces, anyway I correct it – Robin pilot Mar 24 '15 at 16:24
  • 1
    Try running mplayer with `−noconsolecontrols`. That should be on automatically when running mplayer from the command line, but sometimes when reading from stdin you have to toggle it manually. Perhaps it will be quiet and run then. – JNevill Mar 24 '15 at 16:32
  • That worked, that was what was happening. thx – Robin pilot Mar 24 '15 at 20:13

1 Answers1

0

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

Rub
  • 2,071
  • 21
  • 37