1

i am trying to run mplayer system command for encode video via Perl script but not working

#!/usr/bin/perl
`"/usr/bin/mplayer -nosound -benchmark -vo yuv4mpeg:file=>(/usr/local/bin/x264 --demuxer y4m --crf 24 --output output.h26 - 2>x264.log) input.mov"`;

if i run on ssh terminal

/usr/bin/mplayer -nosound -benchmark -vo yuv4mpeg:file=>(/usr/local/bin/x264 --demuxer y4m --crf 24 --output output.h26 - 2>x264.log) input.mov

command work on ssh terminal not working in perl script

1 Answer 1

4

You have too many sets of quotes in the Perl script. With gritted teeth, I suppose you could do:

#!/usr/bin/perl
`/usr/bin/mplayer -nosound -benchmark -vo yuv4mpeg:file=>(/usr/local/bin/x264 --demuxer y4m --crf 24 --output output.h26 - 2>x264.log) input.mov`;

Oooh; you've got a bash process redirection in there. That complicates matters; you can't simply split the command up like this:

#!/usr/bin/perl
my $x264 = "/usr/local/bin/x264 --demuxer y4m --crf 24 --output output.h26 - 2>x264.log";
exec "/usr/bin/mplayer", "-nosound", "-benchmark", "-vo",
      "yuv4mpeg:file=>($x264)",
      "input.mov";

This is often the best way to go; it isn't correct for you.

You're probably still better off using:

#!/usr/bin/perl
system "/usr/bin/mplayer -nosound -benchmark -vo yuv4mpeg:file=>(/usr/local/bin/x264 --demuxer y4m --crf 24 --output output.h26 - 2>x264.log) input.mov";

since you really aren't interested in the output of the command. OTOH, there really isn't a reason to be using Perl like this. It would be better to write:

#!/usr/bin/bash
/usr/bin/mplayer -nosound -benchmark -vo yuv4mpeg:file=>(/usr/local/bin/x264 --demuxer y4m --crf 24 --output output.h26 - 2>x264.log) input.mov

optionally with an exec before the command:

#!/usr/bin/bash
exec /usr/bin/mplayer -nosound -benchmark -vo yuv4mpeg:file=>(/usr/local/bin/x264 --demuxer y4m --crf 24 --output output.h26 - 2>x264.log) input.mov

With information about the why's and wherefore's of the request trickling out, we observe:

sh: 1: command : not found error output in perl script

The mention of sh indicates part of the problem. When bash is run as sh, it does not support process substitution. Given that this is one fragment of a bigger Perl script, we'll continue to work towards running the command from Perl.

#!/usr/bin/perl
use strict;
use warnings;

my $x264 = "/usr/local/bin/x264 --demuxer y4m --crf 24 --output output.h26 - 2>x264.log";
system "bash", "-c",
       "/usr/bin/mplayer -nosound -benchmark -vo yuv4mpeg:file=>($x264) input.mov";
Sign up to request clarification or add additional context in comments.

5 Comments

If you'd tried this, why did you not mention that in the question? Why aren't you running a shell script? I really can't see any advantage to using Perl here...
Which variant did you get the sh: 1 information from? Note that when run as sh, bash does not recognize process redirection. So, you may end up having to force Perl to run bash. I'll update the answer...
sh: 1: /usr/bin/mplayer -nosound -benchmark -vo yuv4mpeg:file=>(/usr/local/bin/x264 --demuxer y4m --crf 24 --output output.h26 - 2>x264.log) input.mov: not found this error i getting when run in perl script
There were two Perl script fragments in my answer, and two in your question; you've not indicated which one of those generates the error message. There are now three Perl script fragments in my answer.
Good; glad we got you on your way.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.