How do I know there is error occured in ffmpeg command? and How do I get the error in my php?
below is my code
<?php
$cmd = "$ffmpeg -i $vid -an -ss $getfromsecond -s $size -vframes 1 $imageFile";
if(!shell_exec($cmd)){
echo "Thumbnail created" . "<br/>";
}else{
echo "Error Creating thumbnail". "<br/>";
}
?>
I am not sure if above approach is right.I have also tried below code
exec($cmd, $output, $return);
echo '$output :' ; print_r($output); echo "<br/>";echo '$return :' . $return . "<br/>";exit;
but in server it is just showing out put as
$output :Array ( )
$return127
I don't understand what is that error no, How to know if error has occurred and return the ffmpeg error no and ffmpeg error text , in php.
use it
exec($cmd,$test);
then check
if(file_exists($image))
{
echo 'suc';
}
Related
here is my code for FFMPEG
$mp3path=realpath("1.mp3");
$cmd = "/usr/include/ffmpeg -i $mp3path -ab 128 /home/swiftfa1/public_html/output.mp3 2>&1";
exec($cmd, $output, $value);
echo '<pre>'; print_r($output); echo '</pre>';
echo '<pre>'; print_r($value); echo '</pre>';
exit;
and here is my result:
Array
(
[0] => sh: /usr/include/ffmpeg: Is a directory
)
126
I used whereis for ffmpeg path and searched a lot but can't solve my issue. any command returns 126!
I'm working on generating thumbnail from uploaded video in Codeigniter for this I'm using ffmpeg but when I'm trying to generate the thumbnail I'm getting this error
ffmpeg: symbol lookup error: /usr/lib/x86_64-linux-gnu/libass.so.5:
undefined symbol: FT_Outline_EmboldenXY
I've already installed ffmpeg on my system, currently I'm trying to print the result.
This is my code to generate thumbnail
if ( $this->upload->do_upload( 'userFile' ) ) {
$videoData = $this->upload->data();
/*for thumbnail of video*/
echo "</pre>";
exec( "/tagittty/ffmpeg.exe" );
$videoFile = $_FILES['userFile']['name'];
exec( 'ffmpeg -i' . $videoFile . ' -r 1 -ss 00:00:50 -vf scale=1024:-1 -vframes 1 output.jpeg 2>&1', $result );
echo "<pre>";
print_r( $result );
echo "</pre>";
die();
}
Response I got after
ldd -r /usr/lib/x86_64-linux-gnu/libass.so.5
Thanks for the help. :)
Is there a way to run a shell script from PHP and echo the results after progress is completed?
Here is my shell script:
(Its multilines - a few commands that have to be ran one after the other. )
cd
cd /var/www/html/
npm uninstall gulp --save
npm install gulp --save
npm start
here's my currently functioning PHP script. It only outputs some of the progress and only outputs it when complete. I need a live preview of the progress.
<?php
echo "loaded<br><br>";
// echo shell_exec("cd /var/www/html/..");
// rin the shell scrip from header_register_callback
echo '<pre>';
// Outputs all the result of shellcommand "ls", and returns
// the last output line into $last_line. Stores the return value
// of the shell command in $retval.
$last_line = system('cd /var/www/html/; npm start', $retval);
// Printing additional info
echo '
</pre>
<hr />Last line of the output: ' . $last_line . '
<hr />Return value: ' . $retval;
?>
Here is another approach. It uses redirection to output the results and then file_get_contents() to read the output.
<?php
echo "loaded<br><br>";
$cmd = 'npm start';
$run = $cmd . ' > result.txt 2> errors.txt';
$output = shell_exec($run);
$results = file_get_contents('result.txt');
if (strlen(file_get_contents('errors.txt')) != 0) {
$results .= file_get_contents('errors.txt');
}
echo "<pre>$results</pre>";
?>
I guess, ob_flush() would work:
<?php
echo "loaded<br><br>";
ob_flush();
// echo shell_exec("cd /var/www/html/..");
// rin the shell scrip from header_register_callback
echo '<pre>';
ob_flush();
// Outputs all the result of shellcommand "ls", and returns
// the last output line into $last_line. Stores the return value
// of the shell command in $retval.
$last_line = system('cd /var/www/html/; npm start', $retval);
// Printing additional info
echo '
</pre>
<hr />Last line of the output: ' . $last_line . '
<hr />Return value: ' . $retval;
?>
But I don't understand why you echo HTML-tags when you run that script on the console... Hope I got you right
I want to convert all pages of a PDF to JPEG. The PHP-script does what it should locally but fails on our live server.
$pdf = Zend_Pdf::load($file['tmp_name']);
echo 'Pages: '.sizeof($pdf->pages).'<br />';
for($pageCounter = 0; $pageCounter < $object->getNumberOfPages(); $pageCounter++) {
$pagenumber = $pageCounter + 1;
$currentfilename = $filename . "_$pagenumber.jpg";
echo $thumbPath.$currentfilename.'<br />';
echo $file['tmp_name']."[$pageCounter]<br />";
$return; $out;
exec("convert -density 250 '".$file['tmp_name']."[$pageCounter]' -quality 60 '$bigPath$currentfilename'", $out, $return);
var_dump($return); echo '<br />'; echo var_dump($out); echo '<br />';
exec("/usr/bin/convert -density 16 '/home/data/websites/www/meonline.be/public_html/images/magazines/".$file['name']."[$pageCounter]' -quality 60 '$thumbPath$currentfilename'", $out, $return);
var_dump($return); echo '<br />';
}
I tried to refer to the convert command by explicitly pointing to /usr/bin/convert & /usr/local/bin/convert. I always get 1 (or 127 if i'm pointing to the wrong folder) and the output array is always empty.
All folder as shown exist and have mode 777 set.
Here's a summary of all echoed output:
Full exec command:
convert -density 250 '/home/data/websites/www/meonline.be/public_html/images/magazines/HogeschoolPromotorenP-studenten.pdf[0]' -quality 60 '/home/data/websites/www/meonline.be/public_html/images/magazines/big/pLjB9_HogeschoolPromotorenP-studenten.pdf/hogeschoolpromotorenp-studenten_1399449783_1.jpg'
First echo echo 'Pages: '.sizeof($pdf->pages).'<br />';
pages: 1
Second echo echo $thumbPath.$currentfilename.'<br />';
/home/data/websites/www/meonline.be/public_html/images/magazines/thumb/pLjB9_HogeschoolPromotorenP-studenten.pdf/hogeschoolpromotorenp-studenten_1399449783_1.jpg
Third echo echo $file['tmp_name']."[$pageCounter]<br />";
/home/data/websites/www/meonline.be/public_html/images/magazines/HogeschoolPromotorenP-studenten.pdf[0]
Fourth echo var_dump($return); echo '<br />'; echo var_dump($out); echo '<br />';
int(1)
array(0) { }
UPDATE
Someone executed my command in the terminal and got the following response:
convert: Postscript delegate failed `/home/data/websites/www/meonline.be/public_html/images/magazines/HogeschoolPromotorenP-studenten.pdf': No such file or directory # error/pdf.c/ReadPDFImage/713.
convert: no images defined `/home/data/websites/www/meonline.be/public_html/images/magazines/big/fs5Jd_HogeschoolPromotorenP-studenten.pdf/hogeschoolpromotorenp-studenten_1399455323_1.jpg' # error/convert.c/ConvertImageCommand/3150.
I'm 100% sure that the PDF file exists and the second line complains about the image not being defined, but this command should create them for me.
In case anyone is looking for an answer, the problem was actually quite simpel.
The local server had Ghostscript installed, the live server didn't...
Download it here and follow the instructions here.
In my case, I didn't have access to the commandline on the live server. In that case, check if /usr/bin/gs is available (in which case it is installed) with this command from PHP:
$return; $out;
exec("/usr/bin/gs 2>&1", $out, $return);
var_dump($return); echo '<br />'; echo var_dump($out); echo '<br />';
I need to read the output from ffmpeg in order to even try the solution to my question from yesterday. This is a separate issue from my problem there, so I made a new question.
How the heck do I get the output from an ffmpeg -i command in PHP?
This is what I've been trying:
<?PHP
error_reporting(E_ALL);
$src = "/var/videos/video1.wmv";
$command = "/usr/bin/ffmpeg -i " . $src;
echo "<B>",$command,"</B><br/>";
$command = escapeshellcmd($command);
echo "backtick:<br/><pre>";
`$command`;
echo "</pre><br/>system:<br/><pre>";
echo system($command);
echo "</pre><br/>shell_exec:<br/><pre>";
echo shell_exec($command);
echo "</pre><br/>passthru:<br/><pre>";
passthru($command);
echo "</pre><br/>exec:<br/><pre>";
$output = array();
exec($command,$output,$status);
foreach($output AS $o)
{
echo $o , "<br/>";
}
echo "</pre><br/>popen:<br/><pre>";
$handle = popen($command,'r');
echo fread($handle,1048576);
pclose($handle);
echo "</pre><br/>";
?>
This is my output:
<B>/usr/bin/ffmpeg -i /var/videos/video1.wmv</B><br/>
backtick:<br/>
<pre></pre><br/>
system:<br/>
<pre></pre><br/>
shell_exec:<br/>
<pre></pre><br/>
passthru:<br/>
<pre></pre><br/>
exec:<br/>
<pre></pre><br/>
popen:<br/>
<pre></pre><br/>
I don't get it. safe_mode is off. There's nothing in disable_functions. The directory is owned by www-data (the apache user on my Ubuntu system). I get a valid status back from exec() and system() and running the same command from the command line give me tons of output. I feel like I must be missing something obvious but I have no idea what it is.
The problem is you catch only stdout and not stderr (see Standard Streams).
Change this line:
$command = "/usr/bin/ffmpeg -i " . $src;
into
$command = "/usr/bin/ffmpeg -i " . $src . " 2>&1";
and give it another try :)
Use ffprobe instead, it's much quicker and supports JSON output.
$output = shell_exec('ffprobe -v quiet -print_format json -show_format -show_streams "path/to/yourfile.ext"');
$parsed = json_decode($output, true);
And you have all your video info in a php array! This is much faster than ffmpeg -i for some reason.
To get output status and output:
exec("ffmpeg -i input.avi output.mp4 2>&1", $output, $returnStatus);
print_r($output);
if($returnStatus === 0){
// success
}
else {
//fail
}
You can use exec and print_r the output...
exec("ffmpeg -i input.avi -vcodec h264 -acodec aac -strict -2 output.mp4 2>&1",$output);
echo "<pre>";
print_r($output);
echo "</pre>";