FFMPEG- How to generate thumbnail from video in Codeigniter - php

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. :)

Related

FFMPEG exec exit code 126

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!

Get the error returned by FFMPEG

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';
}

video uploading using PHP

I am using the following code for uploading videos
$img1 = $_FILES['video']['name'];
if (!empty($img1)) {
$fname = $_FILES['video']['name'];
$img_name1 = "video/" . $fname;
if(move_uploaded_file($_FILES['video']['tmp_name'], $img_name1)){
$new_name = ShowFileName($fname);
$output = 'video/'.$new_name.'.flv';
$command = "$ffmpegpath -i $img_name1 -s 486x368 -b 400kb -ac 1 -ar 44100 -r 25 -s 320x240 -f flv $output";
$command = $ffmpegpath.' -i'.$img_name1.' -s 486x368 -b 400kb -ac 1 -ar 44100 -r 25 -qmin 3 -qmax 5 -y '.$output;
exec($command);
$thumb_dir = 'video_thumbs/';
$thumb = $new_name.'jpg';
exec($ffmpegpath .' -i '.$img_name1.' -an -y -f mjpeg -ss 0.05 -vframes 1 '.$thumb_dir.$img_name1);
unlink($img_name1);
}
}
It is working properly.ie Successfully moving video into videos folder and insering video name to database table. But the problem is related to the thumb image of this video. Thumb name was insert into database but the image wasn't uploding to the video_thumb folder.......
please help me....
The only problem I see is with the file name in the ffmpeg command line. If it contains special chars you should use escapeshellarg().
php function escapeshellarg

Getting FLV duration with php

I have an flv file uploaded to a server. I would like to display its duration in the following format "minutes:seconds". Can anybody help me with this ?
Thank you
There is also a FFMPEG PHP extension ie. apt-get install php5-ffmpeg then
$movie = new ffmepg_movie("path/to/movie.flv");
$duration_in_seconds = $movie->getDuration();
This has worked for me previously. The extension is good for retrieving meta-data and testing if an uploaded file is an FLV, etc.
Here is my code to grab a frame and generate the image from the video...
// get the duration and a random place within that
$cmd = "ffmpeg -i " . $videoPath . " 2>&1";
if (preg_match('/Duration: ((\d+):(\d+):(\d+))/s', `$cmd`, $time)) {
$total = ($time[2] * 3600) + ($time[3] * 60) + $time[4];
$second = rand(1, ($total - 1));
}
exec($cmd);
// get the screenshot
exec("ffmpeg -i " . $videoPath . " -deinterlace -an -ss $second -t 00:00:01 -r 1 -y -vcodec mjpeg -f mjpeg " . $imageOutput . " 2>&1");
$second variable is random number between 0 and total duration.
and the second exec() is to create a image file from selected frame.
$imageOutput is absolute path location to the generated image.
eg: /home/ariawan/image-generated.jpg
I´d use the getID3 PHP library, written in plain old PHP without any dependencies.
It not only gives you the duration of the .flv movie in seconds, but converts it to minute:seconds format already. Here is a code sample with v. 1.7.9 (latest stable version of getid3):
<?php
// getId3 library uses deprecated eregi_* functions
// which generate errors under PHP 5.3 - so I excluded them
error_reporting(E_ALL ^ E_DEPRECATED);
// just for debugging/sample
header('Content-Type: text/plain');
// include the getid3 base class in order to use the lib
require_once('./lib/getid3.php');
// path to your .flv file
$filename = './sample.flv';
$getID3 = new getID3();
$fileInfo = $getID3->analyze($filename);
// echoes something like 127.8743
print 'Playtime in seconds: ' . $fileInfo['playtime_seconds'];
print chr(10);
// echoes something like: 2:07
print 'Playtime in minute:seconds format: ' . $fileInfo['playtime_string'];
i am using php and ffmpeg to get duration of the video.
$cmd = "ffmpeg -i " . $videoPath . " 2>&1";
if (preg_match('/Duration: ((\d+):(\d+):(\d+))/s', `$cmd`, $time)) {
$total = ($time[2] * 3600) + ($time[3] * 60) + $time[4];
}
exec($cmd);
print_r() the $time variable to see.
make sure ffmpeg installed on your machine..
hope this will help.

Capture FFMPEG output

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>";

Categories