1

This is my shell script but it gives errors:

#!/bin/sh

while getopts "i:o:" flag
do
   case $flag in
   i) file_input=$OPTARG
   ;;
   o) file_output=$OPTARG
   ;;
   esac
done

mplayer -nosound -benchmark -vo yuv4mpeg:file=>(x264 --demuxer y4m \
              --crf 20 --threads auto --output $file_output - ) $file_input

The error message is:

Can't get memory or file handle to write ">(x264 --demuxer y4m --crf 20 --threads auto --output video.264 - )"!FATAL: Cannot initialize video driver.

When I run this cmd on putty:

mplayer -nosound -benchmark -vo yuv4mpeg:file=>(x264 --demuxer y4m \
              --crf 20 --threads auto --output video.264 - ) video.wmv

it works perfectly..

What am I doing wrong?

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Sascha
  • 11
  • 2

3 Answers3

4

The command you're using uses an intricate bash's pipe stream to subshell syntax, i.e. >() to achieve what you want. Probably your /bin/sh (that you invoke as a shell for this script in shebang) is not the same as the shell you're using interactively (i.e. bash)?

GreyCat
  • 16,622
  • 18
  • 74
  • 112
  • /bin/sh is probably a link to /bin/bash, but under the name /bin/sh, not all the features of bash are available - and the '`=>`' notation in particular is not supported. – Jonathan Leffler Jan 21 '11 at 13:39
  • @Jonathan: there is no `=>` notation. The `=` is part of the mplayer command. `>(...)` is what Bash parses. – thkala Jan 21 '11 at 13:41
  • Not always. Nowadays Ubuntu & Debian are popular, and `/bin/sh` is usually implemented with dash there, which is a very minimalistic strictly POSIX-compatible shell. – GreyCat Jan 21 '11 at 13:41
  • @thkala: You're probably correct - the problems start between the = and the >, and /bin/sh doesn't like it and /bin/bash does. So it is 'process substitution' again...makes sense. – Jonathan Leffler Jan 21 '11 at 13:43
1

The >(...) process substitution operator is Bash-specific. It is also not available if Bash is called as /bin/sh, because in that case Bash restricts itself to a more compliant subset of its features.

Just use #!/bin/bash instead of #!/bin/sh at the start of your script.

thkala
  • 84,049
  • 23
  • 157
  • 201
0

I suggest you to add some ' to protect you special chars:

mplayer -nosound -benchmark -vo 'yuv4mpeg:file=>(x264 --demuxer y4m --crf 20 --threads auto --output $file_output - )' $file_input
gabuzo
  • 7,378
  • 4
  • 28
  • 36