How to display a screenshot of a stream using avconv and php with exec?

410 views Asked by At

When this script is run, the image is saved to a file:

<?php

  $url = "rtmp://109.71.162.112:1935/live/sd.jasminchannel.stream";
  exec('avconv -i "'.$url.'" -ss 00:00:01 -t 1 -r 1 -f image2 "screenshot.jpg" 2>&1', $output, $status);

  header("Content-type: image/png");
  readfile("screenshot.jpg");

I wish it was returned on the screen (on the fly means it, write to variable, instead without saving to file and afterwards reading, display, deleting this file):

<?php

  $url = "rtmp://109.71.162.112:1935/live/sd.jasminchannel.stream";
  exec('avconv -i "'.$url.'" -ss 00:00:01 -t 1 -r 1 -f image2 $variable 2>&1', $output, $status);

  header("Content-type: image/png");
  echo $variable;

How can I do this?

1

There are 1 answers

0
Megasaturnv On

I think this will solve your problem:

<?php

  $url = "rtmp://109.71.162.112:1935/live/sd.jasminchannel.stream";
  header("content-type: image/jpeg");
  echo passthru('avconv -i "'.$url.'" -ss 00:00:01 -t 1 -r 1 -f image2 pipe:.jpg 2>/dev/null');

This is untested, but it should work. I've been working on a similar problem at: https://gist.github.com/megasaturnv/a42ed77d3d08d0d3d91725dbe06a0efe

and with the image in an tag: https://gist.github.com/megasaturnv/6e5965732d4cff91f2e976e7a39efbaa