2015-05-02 21 views
6

ho una scritta uno script per l'applicazione GStreamer (gasdotto) in ubuntu per catturare 2 stream video tramite webcam e un frame grabber e metterli in un unico contenitore:L'esecuzione di script gasdotto Gstreamer al codice php

gst-launch -e mpegtsmux name="muxer" ! filesink location=TestHDMainCamera.ts \ 
v4l2src device="/dev/video1" ! video/x-raw-yuv, width=1280 ,height=720, \ 
    framerate=30/1 ! videorate ! ffmpegcolorspace ! x264enc ! muxer. \ 
v4l2src device="/dev/video0" ! video/x-raw-yuv, width=1024 ,height=768, \ 
framerate=30/1 ! x264enc ! muxer. pulsesrc \ 
device="alsa_input.usb-046d_Logitech_Webcam_C930e_AAF8A63E-02-C930e.analog-stereo" \ 
    ! audioconvert ! lamemp3enc target=1 cbr=true ! muxer. 

I basta inserirlo in un file .sh ed eseguirlo tramite terminale. per semplificare la vita ho scritto un semplice codice php per creare una semplice (!) interfaccia del sito (in esecuzione su host locale) per controllare il processo di acquisizione (inizio: esegui il file .sh e ferma: Ctrl + c)

due pulsanti aggiuntivi per testare solo i flussi provenienti dal frame grabber e webcam separatamente per vedere se sono collegati o meno:

prova Anteprima di webcam:

gst-launch v4l2src device=/dev/video1 ! ffmpegcolorspace ! xvimagesink 

prova Anteprima di FrameGrabber:

gst-launch v4l2src device=/dev/video0 ! ffmpegcolorspace ! xvimagesink 

Ecco la domanda:

Ogni volta che carico la pagina e premo il pulsante di avvio sembra che php esegua la pipeline .sh e la interrompa immediatamente (ottengo questo messaggio sullo schermo: Liberare la pipeline ...) quindi non ottengo stream catturato (!) anche se provo a usare i pulsanti di prova per avere un risultato live streaming è lo stesso ...

puoi aiutarmi e dirmi come posso eseguire la pipeline codice per gstreamer da catturare usando questo codice php? (Gasdotto gstreamer deve essere terminato solo quando premo "Stop", che dovrebbe svolgere la funzione Ctrl + c)

Maggiori informazioni:

ecco il codice main.php per l'interfaccia (è un po ' disordinato, dispiace):

<html> 
<head> 
    <title>PHP Test</title> 
</head> 
<body> 
<?php 
echo '<p>Hello</p>'; 
print_r($_GET); 

if (isset($_GET['action'])) { 
switch ($_GET['action']) { 
    case 'Test Webcam': 
     testWebcam(); 
     break; 
    case 'Test Framegrabber': 
     testFramegrabber(); 
     break; 
} 
} 

function testFramegrabber() { 
echo "The Test Framegrabber function is called."; 
$output = shell_exec('ls -lart'); 
echo "<pre>$output</pre>"; 
} 

function testWebcam() { 
echo "The Test Webcam function is called."; 
$output = shell_exec('ls -lart'); 
echo "<pre>$output</pre>"; 
} 

//$output = shell_exec('ls -lart'); 
//echo "<pre>$output</pre>"; 
?> 
<form action="main.php"> 
    <input type="submit" class="button" name="action" value="Test Webcam" /> 
<input type="submit" class="button" name="action" value="Test  Framegrabber" /> 
</form> 
</body> 
</html> 

ed ecco la record.php per i pulsanti e altri particolari:

<html> 
<head> 
<title>Recording page</title> 
<link rel="stylesheet" type="text/css"  href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css"> 

<script type="text/javascript"> 
var w = null; // initialize variable 

//function to start the timer 
function startTimer() 
{ 
// First check whether Web Workers are supported 
if (typeof(Worker)!=="undefined"){ 
    // Check whether Web Worker has been created. If not, create a new Web  Worker based on the Javascript file simple-timer.js 
    if (w==null){ 
     w = new Worker("simple-timer.js"); 
    } 
    // Update timer div with output from Web Worker 
    w.onmessage = function (event) { 
     document.getElementById("timer").innerHTML = event.data; 
    }; 
} else { 
    // Web workers are not supported by your browser 
    document.getElementById("timer").innerHTML = "Sorry, your browser does  not support Web Workers ..."; 
} 
} 

//function to stop the timer 
function stopTimer() 
{ 
w.terminate(); 
timerStart = true; 
w = null; 
} 

function handleTimer() { 
    document.getElementById("timerp").innerHTML = "start timer"; 
} 
</script> 
</head> 
<body> 
<?php 
echo '<p>Hello</p>'; 
print_r($_GET); 

if (isset($_GET['action'])) { 
    switch ($_GET['action']) { 
     case 'Test Webcam': 
      testWebcam(); 
      break; 
     case 'Test Framegrabber': 
      testFramegrabber(); 
      break; 
     case 'Record': 
      record(); 
      break; 
    } 
} 

function testFramegrabber() { 
    echo "The Test Framegrabber function is called."; 
    $output = shell_exec('ls -lart'); 
    echo "<pre>$output</pre>"; 
} 

function testWebcam() { 
    echo "The Test Webcam function is called."; 
    $output = shell_exec('ls -lart'); 
    echo "<pre>$output</pre>"; 
} 

function record(){ 
echo "The Record function is called."; 
echo "<script> startTimer(); </script>"; 
} 
function stop(){ 
    echo "The Stop function is called."; 
    echo "<script> stopTimer(); </script>"; 
} 
//$output = shell_exec('ls -lart'); 
//echo "<pre>$output</pre>"; 
?> 
<div class="header">A simple timer:</div> 

    <div class="timer" id="timer">00:00</div> 
    <div class="buttons"> 
     <button onclick="startTimer()" id="button1">Start</button> 
     <button onclick="stopTimer()" id = "button2">Stop</button> 
    </div> 
<form class="form-horizontal" action="record.php"> 
<fieldset> 

<!-- Form Name --> 
<legend>Sreen recorder</legend> 

<table class="tg" width="100%"> 
    <tr> 
    <th class="tg-031e"></th> 
    <th class="tg-031e">fdsfs</th> 
    </tr> 
    <tr> 
    <td class="tg-031e"></td> 
    <td class="tg-031e"></td> 
    <td class="tg-031e"></td> 
    </tr> 
    <tr> 
    <td class="tg-031e"></td> 
    <td class="tg-031e"></td> 
    <td class="tg-031e"></td> 
    </tr> 
    <tr> 
    <td class="tg-031e"> 
     <!-- Button --> 
     <div class="control-group"> 
     <label class="control-label" for="recordbtn"></label> 
     <div class="controls"> 
     <button id="recordbtn" name="action" class="btn btn-danger"  value="Record" onclick="startTimer()">Record</button> 
     </div> 
     </div> 
    </td> 
    <td class="tg-031e"> 
     <!-- Button --> 
     <div class="control-group"> 
     <label class="control-label" for="stopbtn"></label> 
     <div class="controls"> 
     <button id="stopbtn" name="action" class="btn btn-inverse"  value="Stop" onclick="stopTimer()">Stop</button> 
     </div> 
     </div> 
    </td> 
    <td class="tg-031e"> 
     <!-- Button --> 
     <div class="control-group"> 
     <label class="control-label" for="nextbtn"></label> 
     <div class="controls"> 
     <button id="nextbtn" name="action" class="btn btn-inverse">Next  recording</button> 
     </div> 
     </div> 
    </td> 
    </tr> 
</table> 



<!-- Button --> 
<div class="control-group"> 
<label class="control-label" for="webcamTest"></label> 
<div class="controls"> 
<button id="webcamTest" name="action" value="Test Webcam" class="btn  btn-info">Test Webcam</button> 
</div> 
</div> 

<!-- Button --> 
<div class="control-group"> 
<label class="control-label" for="testFramegrabber"></label> 
<div class="controls"> 
<button id="testFramegrabber" name="action" value="Test Framegrabber"  class="btn btn-info">Test Framegrabber</button> 
</div> 
</div> 

<!-- Select Basic --> 
<div class="control-group"> 
<label class="control-label" for="recordPath">Path to record</label> 
<div class="controls"> 
<select id="recordPath" name="recordPath" class="input-xlarge"> 
<option>/desktop</option> 
<option>/home/var</option> 
</select> 
</div> 
</div> 



</fieldset> 
</form> 
</body> 
</html> 

e solo un timer semplice essere visualizzati mentre c apturing nella pagina:

var timerStart = true; 

function myTimer(d0) 
{ 
    // get current time 
    var d=(new Date()).valueOf(); 
    // calculate time difference between now and initial time 
    var diff = d-d0; 
    // calculate number of minutes 
    var minutes = Math.floor(diff/1000/60); 
    // calculate number of seconds 
    var seconds = Math.floor(diff/1000)-minutes*60; 
    var myVar = null; 
    // if number of minutes less than 10, add a leading "0" 
    minutes = minutes.toString(); 
    if (minutes.length == 1){ 
     minutes = "0"+minutes; 
    } 
    // if number of seconds less than 10, add a leading "0" 
    seconds = seconds.toString(); 
    if (seconds.length == 1){ 
     seconds = "0"+seconds; 
    } 

    // return output to Web Worker 
    postMessage(minutes+":"+seconds); 
} 

if (timerStart){ 
    // get current time 
    var d0=(new Date()).valueOf(); 
    // repeat myTimer(d0) every 100 ms 
    myVar=setInterval(function(){myTimer(d0)},100); 
    // timer should not start anymore since it has been started 
    timerStart = false; 
    } 

risposta

0

Consiglierei di controllare l'utente apache. Hai detto che stai usando Ubuntu, quindi sarebbe "www-data", che probabilmente non può accedere né al tuo DISPLAY né a "/ dev/video0".

  • tenta di eseguire voi .SH come www-data in un terminale (potrebbe essere necessario consentire l'accesso shell per www-dati a/etc/passwd)

  • Una soluzione rapida e sporca sarebbe eseguendo il tuo php come un normale utente. Da una scrittura terminale:

    php -S 0.0.0.0:8080 -t your_directory/