I have an exec command I am using to make ffmpeg work.
$process = exec("/usr/local/bin/ffmpeg -i /home/g/Desktop/cave.wmv -deinterlace
-acodec libfaac -ab 96k -ar 44100 -vcodec libx264 -s 480x320 -f flv /home/g/Desktop
/file.flv 2>&1 | php testing123.php") ;
In testing123.php I use
$h = fopen('php://stdin', 'r'); $str = fgets($h); fclose($h);
//topic removed
$sql = 'INSERT INTO table
(id,status) VALUES(?,?)';
$stmt3 = $conn->prepare($sql);
$result=$stmt3->execute(array(rand(),$str));
However, as you may have guessed I get one database entry, only when the file initially executes from the exec command in the other file. Is there a way to keep executing the file or something else so that the output fed to the file can be inserted into my database every couple seconds?
You need to use a while loop. There are some examples in the fgets documentation.
$h = fopen('php://stdin', 'r');
while ( ($str = fgets($h)) !== false )
{
$sql = 'INSERT INTO ...';
mysql_query($sql);
}
fclose($h);
One of the comments in the documentation suggests using stream_get_line instead of fgets. In case you're interested, here's the direct link: http://www.php.net/manual/en/function.fgets.php#86319.
Related
I am uploading video using ffmpeg command. I am then creating then thumbnail. I want to rotate video, how can I achieve this?
Here is my Code:
$thumbnail_name = preg_replace('"\.(mp4|avi|flv|vob|oggg)$"', '.jpg', $newfilename);
$movie = "/home/foldername/public_html/master/assets/user_videos/".$newfilename;
$thumbnail = "/home/foldername/public_html/master/assets/user_videos/".$thumbnail_name;
$command = '/usr/bin/ffmpeg -y -ss 00:00:01 -i '.$movie.' -f image2 -vframes 1 '.$thumbnail.' 2>&1';
Add your command -vf transpose=1
Full code: ffmpeg -i input.mp4 -ss 0 -vframes 1 -vf transpose=1 out.jpg
For the transpose parameter you can pass:
0 = 90CounterCLockwise and Vertical Flip (default)
1 = 90Clockwise
2 = 90CounterClockwise
3 = 90Clockwise and Vertical Flip
Use -vf "transpose=2,transpose=2" for 180 degrees.
I am executing the following php code, and the status returned is -1, while output array is empty. What does this mean?
$cmd = "sort -T /var/www/html/my_app/protected/runtime/sort// -t '|' /var/www/html/my_app/protected/runtime/workflow/db-export/filename_1818.txt -o /var/www/html/my_app/protected/runtime/workflow/db-export/filename_1818.txt 2>&1";
exec($cmd, $output, $status);
print_r($output);
echo $status;
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?
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
Using FFMPEG, I want to get the frame from the video on a specific time (provided by the user) in PHP.
Can anybody help me with this? I've never used FFMPEG.
Thanks in advance.
I found the solution
//video dir
$video = 'Salient.avi';
//where to save the image
$image = 'testimage%d.jpg';
//time to take screenshot at
$interval = '00:00:12';
//screenshot size
$size = '535x346';
echo "Starting ffmpeg...\n\n<br>";
$cmd = "ffmpeg -i $video -ss $interval -f image2 -s $size -vframes 1 $image";
echo shell_exec($cmd);
echo "Done.\n";
When I run proc_open with a file.txt path for the stderr output, that file is constantly updated every couple seconds with output of the proc_open program I am running which is ffmpeg. I just want to redirect that output to a phpfile where it can be read and parsed but while the process is running (so send info every couple seconds) so I can update a database. IS this possible? I have been googling for hours so if there are any experts out there who actually know how to use this function of have experience in this I would greatly appreciate any help.
this puts output in a text doc. If I change to 2 => array("pipe","w") and the echo the output only comes on my screen at the end of the process
$descriptorspec = array(
0 => array("pipe","r"),
1 => array("pipe","w"),
2 => array("file","/home/g/Desktop/test.txt","a")
) ;
$cwd = './' ;
// open process /bin/sh
$process = proc_open("/usr/local/bin/ffmpeg -i /home/g/Desktop/vid.wmv /home/g/Desktop/vid.flv", $descriptorspec, $pipes, $cwd) ;
you could run ffmpeg like this:
ffmpeg ..optinons... 2>&1 | php script.php
But you could have in input STDERR and STDOUT of ffmpeg
And second normal decision:
<?
$cmd = 'ffmpeg -i /home/azat/Desktop/src.avi -y /home/azat/Desktop/dst.avi';
$pipes = array();
$descriptors = array(2 => array('file', '/tmp/atest.log', 'a'));
$p = proc_open($cmd, $descriptors, $pipes);
while (true) {
sleep(1);
$status = proc_get_status($p);
if (!$status['running']) break;
echo "STEEL RUN\n";
// some manupulations with "/tmp/atest.log"
}
Also you can see this class - it is a wrapper for exec processes