title: run ffmpeg from PHP web script
body: <p>I need to manage the recording/capture of a website mindwhile it is running a slide-show to get videos form these slides.</p>
  
  <p>My approach is:</p>
  
  <pre><code>&lt;?php 
  
  define('FFMPEG_LIBRARY', '/usr/bin/ffmpeg ');
  
  $ffmpegcmd = "ffmpeg -f x11grab -r 25 -s 800x600 -i :0.0 /tmp/output.mpg";
  
  shell_exec($ffmpegcmd);  
  
  ?&gt;
  </code></pre>
  
  <p>But i get this error from php error log:</p>
  
  <pre><code>[x11grab @ 0x81e8aa0] device: :0.0 -&gt; display: :0.0 x: 0 y: 0 width: 800 height: 600
  No protocol specified
  No protocol specified
  [x11grab @ 0x81e8aa0] Could not open X display.
  :0.0: Input/output error
  </code></pre>
  
  <p>Similar command from console run good.</p>
  
  <p>Please, any help to get display and be able to control ffmpeg from browser php script?</p>
  
  <p>Thanks in advance.</p>
  
  <hr>
  
  <p>thanks for your time.</p>
  
  <p>I got rid the X display error, but not I still haven't got the capture.</p>
  
  <p>Using xvfb I get an unknown file at /tmp written by www-data user:
  -rw-r--r-- 1 www-data www-data 11252 Sep 12 09:49 server-B20D7FC79C7F597315E3E501AEF10E0D866E8E92.xkm</p>
  
  <p>Running startx I got also an unknown file at /tmp
  -rw------- 1 www-data www-data    59 Sep 12 09:53 serverauth.oLcFlG7tXC</p>
  
  <p>any of both grow in size so it is not capturing anything. The content is some binary thing. 
  What are those files about?</p>
  
  <p>What I am trying is to write a script in which I can control the time ffmpeg is capturing the desktop to create a video from a jquery slide displayed on a website.</p>
  
  <p>My try from console is closer, but if I can do it by browser I will be able to know when to stop sending an AJAX request once the slide is finished.</p>
  
  <p>This is my try from console:</p>
  
  <pre><code>#!/bin/bash
  
  # start the slide website: I will need to change it to control by querystring the language and course level
  firefox http://www.languagecourse.net/vocabulary-trainer.php &amp;
  # start recording: I will need to adjust the frame to capture
  ffmpeg -f x11grab -r 25 -s 800x600 -i :0.0 /tmp/output2.mpg &amp;
  # since I can't control the time a course takes I pause an arbitrary time
  sleep 5
  # look for the capture PID and close it
  for i in $(ps aux | grep ffmpeg | sed "s/  */#/g" | cut -f2 -d#)
  do
    echo "proceso $i killed"
    kill -9 $i
  done
  </code></pre>
  
  <p>I wonder once the website is opened I can continue doing the control from AJAX, but not know if I will be able to get the ffmpeg PID to stop the command.</p>
  
  <p>I will appreciate any kind of comments.</p>
  
  <p>Regards,
  ·_-</p>