I have a written script application for gstreamer (pipeline) in ubuntu to capture 2 video streams through a webcam and capture frames and put them in one container:
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 just put it in a .sh file and executed it through the terminal. to make life easier, I wrote simple PHP code to create a simple (!) website interface (running on the local host) to control the capture process (start: run the .sh file and stop: Ctrl + c)
including two additional buttons to simply test the streams coming from the frame invader and webcam separately to see if they are connected or not:
Webcam Preview:
gst-launch v4l2src device=/dev/video1 ! ffmpegcolorspace ! xvimagesink
FrameGrabber frame preview:
gst-launch v4l2src device=/dev/video0 ! ffmpegcolorspace ! xvimagesink
Here is the question:
Each time I load the page and press the start button, it seems that php executes the .sh pipeline and exits immediately (I get this message on the screen: Release the pipeline ...), so I donβt get the captured stream (!), Even if I try to use test buttons so that the result of the live broadcast is the same ...
can you help me and tell me how can I run the pipeline code for gstreamer to capture using this php code? (the gstreamer pipeline should be completed only when I click the Stop button, which should execute the function Ctrl + c)
Additional Information:
Here is the main.php code for the interface (it's a little dirty, sorry for that):
<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>"; } <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>
and here is the .php entry for buttons and other details:
<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; </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>"; } <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> <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"> <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"> <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"> <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> <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> <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> <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>
and just a simple timer that will be displayed when recording on the page:
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; }