in reply to Passing an in memory scalar to an external command as an argument

This may help:
my $mp3 = <binary contents of an mp3 file already in memory>; $pid = open(PLAY, "| ffmpeg -i pipe:0") or die "Couldn't fork: $!\n"; print PLAY $mp3; close(PLAY) or die "Couldn't close: $!\n";
  • Comment on Re: Passing an in memory scalar to an external command as an argument
  • Download Code

Replies are listed 'Best First'.
Re^2: Passing an in memory scalar to an external command as an argument
by LanX (Saint) on Apr 08, 2015 at 19:07 UTC
      Thank you, BINMODE added to fh PLAY
Re^2: Passing an in memory scalar to an external command as an argument
by RonW (Parson) on Apr 08, 2015 at 20:55 UTC

    I would suggest:

    use IO::Pipe; my $pipe = IO::Pipe->new(); $pipe->writer(qw(ffmpeg -i pipe:0)); print $pipe $mp3;

    to avoid the shell being used to launch ffmpeg.

      I like that solution. But I need to capture stdout also (so I am actually using open2 for this). Can I write and read using IO::Pipe? The docs look like it is one or the other.

        It is possible, but open2 is easier:

        $pid = open2(\*CHLD_OUT, \*CHLD_IN, 'ffmpeg', '-i', 'pipe:0');
Re^2: Passing an in memory scalar to an external command as an argument
by Rodster001 (Pilgrim) on Apr 08, 2015 at 19:08 UTC
    That's what I was looking for, thank you sir