video uploading using PHP - 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

Related

adding a logfile to ffmpeg

ive been searching for a solution for some hours now, but I cant find a solution.
I want ffmpeg to give me a log file after converting is completed.
this is my code:
$convert = '/usr/bin/ffmpeg -i /var/www/html/videos/' . $fileNormal . '.mp4 -vn -sn -c:a mp3 -ab 192k /var/www/html/audio/' . $fileFixed . '.mp3 2> var/www/html/logs/' . $id . '.txt';
exec($convert);
same with
$convert = '/usr/bin/ffmpeg -i /var/www/html/videos/' . $fileNormal . '.mp4 -vn -sn -c:a mp3 -ab 192k /var/www/html/audio/' . $fileFixed . '.mp3 2> /var/www/html/logs/' . $id . '.txt';
exec($convert);
or
$convert = '/usr/bin/ffmpeg -i /var/www/html/videos/' . $fileNormal . '.mp4 -vn -sn -c:a mp3 -ab 192k /var/www/html/audio/' . $fileFixed . '.mp3 2> /logs/' . $id . '.txt';
exec($convert);
if I add anything at the end after mp3 it doesnt convert at all.
appreciate any help. thanks
If you want to log the screen output of the ffmpeg command, you can do this by redirecting the output to a log file. For example:
/usr/bin/ffmpeg -i /var/www/html/videos/' . $fileNormal . '.mp4 -vn -sn -c:a mp3 -ab 192k /var/www/html/audio/' . $fileFixed . '.mp3 > log_file_path.txt
Also see the man page for the ffmpeg command: https://linux.die.net/man/1/ffmpeg. It mentions loglevel and debug options which can be used to control the level of detail in the log data

FFMPEG- How to generate thumbnail from video in Codeigniter

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

escape single qoute in ffmpeg filename varible php

code works fine but if the filename has a single qoute just as "Britney's video.mp4" it does not work.
$ffmpeg = "/usb/bin/local/ffmpeg";
$videos = "/videos/*.mp4";
$ouput_path = "/videos/thumbnails/";
foreach(glob($videos) as $video_file){
$lfilename = basename($video_file);
$filename = basename($video_file, ".mp4");
$thumbnail = $ouput_path.$filename.'.jpg';
if (!file_exists($filename)) {
#$thumbnail = str_replace("'", "%27", $thumbnail);
exec("/usr/local/bin/ffmpeg -i '$video_file' -an -y -f mjpeg -ss 00:00:30 -vframes 1 '$thumbnail'");
}
echo "<a href='$lfilename'>$filename<img src='thumbnails/$filename.jpg' width='350'>";
i got it working but not using something overly complicated.
thanks all
$comd = "/usr/local/bin/ffmpeg -i \"$video_file\" -y -f mjpeg -ss 00:00:30 -vframes 1 \"$thumbnail\" 2>&1"; shell_exec($comd);
shell_exec($comd);
As suggested in the comments, you can just wrap all your shell-command String within the escapeshellarg() as shown below.
<?php
foreach(glob($videos) as $video_file){
$lfilename = basename($video_file);
$filename = basename($video_file, ".mp4");
$thumbnail = $ouput_path.$filename.'.jpg';
if (!file_exists($filename)) {
$cmd = "/usr/local/bin/ffmpeg -i ";
$cmd .= $video_file . " -an -y -f mjpeg -ss 00:00:30 ";
$cmd .= "-vframes 1 " . $thumbnail;
exec( escapeshellarg($cmd) );
}

php shell_exec() command pop out error and permission denied ffmpeg

This is the main index.php file where I run my code to generate a video thumbnail with ffmpeg but it has no lucks at all I have been searching online for a lot of solution but nothing comes out i will be very appreciate if you guys can help me out. The shell_exec() keep giving me error
<html>
<head>
</head>
<body>
<form action="index.php" method="POST" enctype="multipart/form-data">
<input type="file" name="file"><input type="submit" name="submit" value="upload">
</form>
<?php
if(isset($_POST['submit'])){
$ffmpeg = "/Users/mac/Documents/ffmpeg/3.1.4/bin/ffmpeg";
$videoFile = $_FILES["file"]["tmp_name"];
$imageFile = "1.jpg";
$size = "320x240";
$getFromSecond = 5;
$cmd = "$ffmpeg -i $videoFile -an -ss $getFromSecond -s $size $imageFile 2>&1";
echo shell_exec($cmd);
echo shell_exec('whoami');
if(!shell_exec($cmd)){
echo "thumbnail created";
}else{
echo "error creating thumbnail";
}
}
?>
</body>
</html>
The user which is attempting to run this file does not have the correct permissions (usually www-data). To test this theory, try running with sudo:
shell_exec('sudo -u user -p pass -s $ffmpeg -i $videoFile -an -ss $getFromSecond -s $size $imageFile 2>&1');
You could also configure Apache to run your virtual host as a different user other than www-data or change permissions to the files you would like www-data to access:
https://unix.stackexchange.com/questions/30879/what-user-should-apache-and-php-be-running-as-what-permissions-should-var-www

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