ffmpeg + PHP + Zend Framework - php

Here's the situation. While uploading a video, I want to capture a screenshot of that video and save it as a video thumbnail. I currently can't install ffmpeg on my local machine (it will be installed on the production server of course) so I cannot test the following controller action helper I wrote for this purpose:
<?php
/**
* FlvThumbnail
*
* #author Richard Knop
*/
class My_Controller_Action_Helper_FlvThumbnail extends Zend_Controller_Action_Helper_Abstract
{
public function direct($flv, $thumbnail) {
$command = "ffmpeg -v 0 -y -i $flv -vframes 1 -ss 10 -vcodec mjpeg -f rawvideo -s 210x140 -aspect 16:9 $thumbnail";
return shell_exec($command);
}
}
$flv is path to the video (this action helper will be executed right after the video is uploaded)
$thumbnail is path where the thumbnail image should be saved
Could anyone please tell me if the above helper will work as I expect? I'm still not sure when will the production server be purchased but I would like to know in advance if this will work.

works OK for me

Related

FFMPEG is not working centos linux server

I am using FFMPEG for video thumbnails creation,
I have downloaded FFMPEG (ffmpeg-2.4.2.tar.bz2) and installed in server.
located in
/usr/bin/ffmpeg
and used in this below code:
if($extension === 'mp4' OR $extension == 'MP4' )
{
$video = $timestamp.$imagename;
$videoname=substr($imagename,0, -4).$timestamp;
$image = "sites/default/files/content_images/{$videoname}-thumb.jpg";
var_dump($video);
$cmd="/usr/bin/ffmpeg -i /opt/lampp/htdocs/mydashboard/sites/default/files/content_videos/".$video." -ss 00:00:14.435 -f image2 -vframes 1 /opt/lampp/htdocs/mydashboard/sites/default/files/content_images/$videoname-thumb.jpg";
$cmdstr = $cmd;
$locale = 'en_IN.UTF-8';
setlocale(LC_ALL, $locale);
putenv('LC_ALL='.$locale);
echo exec($cmd);
but this command not working as i expect..
$cmd="/usr/bin/ffmpeg -i /opt/lampp/htdocs/mydashboard/sites/default/files/content_videos/".$video." -ss 00:00:14.435 -f image2 -vframes 1 /opt/lampp/htdocs/mydashboard/sites/default/files/content_images/$videoname-thumb.jpg";
issue was video thumbnail is not created,when we upload videos.
any help great appreciation
Variable concatenation is wrong at the end of your cmd definition.
Try with :
[...]les/content_images/".$videoname."-thumb.jpg";
Addendum :
What are the rights on the output directory ?
Your CMD will be run with your webserver user (www-data on Debian systems, httpd on RH, etc...). Make sure directory ownership and/or write rights are set properly

Codeigniter - exec ffmpeg (win 8.1 with xampp)

i want to merge some image files (jpeg,png) to a short stop motion video clip.
The User can upload the images and the webapp will do a short movie... Thats the plan.
I have tried some variations i found in www -> exec, shell_exec
The ffmpeg.exe is in my root Folder (xampp/htdocs/xxx/ffmpeg.exe)
I put a function in my controller to do the clip.
public function render() {
// Save the Session ID into the variable sessionId
$sessionId = $this->session->userdata('session_id');
// Path to the Userimage-Folder
$image_path = "C:\xampp\htdocs\xxx\uploads\$sessionId";
$command = "C:\xampp\htdocs\xxx\ffmpeg -framerate 1/5 -i".$image_path."/img_%03d.JPG -c:v libx264 -r 30 -pix_fmt yuv420p out.mp4";
exec($command);
}
The images are already in the same format and have a consecutive numbering.
I'am still a beginner, so please help me.
regards :)

ffmpeg - which video rate is correct?

I am using ubuntu 13.04
Version of ffmpeg is ffmpeg version N-61041-g52a2138
Through php, I am calling ffmpeg commands to extract images and do some modification in those images and again merge those images back to video.
While merging all images through ffmpeg command, I need to pass video bit rates.
Command is as below
public function mergeImagesToVideo($frame_no,$user_directory_name,$video_bit_rates,&$output,&$status){
/* merge all of frames to create one second video */
$user_frames_path=$GLOBALS["all_user_dir_path"].$user_directory_name."/";
$command= $GLOBALS['ffmpeg'].' -f image2 -r 30 -i '.
$user_frames_path.'f'.$frame_no.'_%d.png -r 30 -b:v '
.$video_bit_rates.'k '.$user_frames_path.'f'.$frame_no.'.mp4';
//echo $command;
exec($command,$output,$status);
return;
}
The call is made as below
$this->mergeImagesToVideo($start_second,$user_directory,$video_bit_rates,$output,$status);
if($status!=0){
echo "some thing went wrong in merging all images to create a video <br>";
}
Now When check bit rates through ffmpeg command output is like as below
ffmpeg -i f1.mp4
This command shows 7303 kb/s
While I right click the image and show properties, it shows 7295 kbps
Which is the correct one ?? Not getting correct line..
Thanks in advance.

using ffmpeg exe in php

and am wanting to use ffmpeg as command line direct on windows 7 x64, I tried adding the extension, but unfortunately it did not work for some unknown reason, but the executable worked perfectly, I'm using the exec command, the only problem is that does not work with direct lines, I have to create a file. bat to run the program. this is my doubt.
$a = exec('\b.bat');
if ($a)
{
echo "Success"."\n";
print $a;
}else {
echo "No good"."\n";
print $a;
}
b.bat
ffmpeg -i video.flv -an -ss 00:00:16 -an -r 1 -vframes 1 -y %a.jpg
already tried several alternatives but the only one that worked was with the. bat
$a = exec('\windows/system32/ffmpeg.exe ffmpeg -i video.flv -an -ss 00:00:16 -an -r 1 -vframes 1 -y %a.jpg');
Make sure you include the full path to your .bat file and also make sure to include the full path to ffmpeg.exe in your .bat file.
Well, I am also working on this ffmpeg file to convert my movies and stuff my idea is for people to watch movies for free anyway here is what I use to convert my movies, have a note that when the ffmpeg.exe is not in the same folder than the movies then you will need to give a full path or use of ../ to go up a folder and / to a folder for example:
$input_path= $_FILES["file"]["tmp_name"];
$output_result= "movies/" . basename($_FILES["file"]["name"]).".flv";
exec("FFMPEG.EXE -i '$input_path' -s 900x400 -r 29.97 -b 1024k -ar 22050 -ab 50k -ac 1 '$output_result'");
there I am using scale and rateframe as well as bitrate and sound quality so my input and output I gave them in a variable basically that command you can use as is just give a value to those variables $input and $output. Please note that I am barely working out the idea too so far this is what I have come out with please do not expect excellent results since we are using microsoft windows the results may vary from version to version and you may have to use the command in administrator mode I hope this helps you my email is support#web2021.com if anything let me know man.

Generate thumbnail for a bunch of mp4 video in a folder

I have read this but didnt help too much.
I have a folder called videos and another folder called thumbnails. I have many mp4 videos in video folder and want to catch thumbnails at 4th second to the thumbnails folder using ffmpeg and php.
I am using Wamp server 2.2 on windows whit php 5.3.8 and Apache 2.2.21
I downloaded ffmpeg from FFmpeg Windows Builds section of ffmpeg download page and the static 32 build from this link.
I extracted the 7z file to my website root
here is my php code:
$ffmpeg = "includes/ffmpeg/bin/ffmpeg";
foreach(glob('files/videos/*.mp4') as $pathname){
$filename = substr($pathname,13,strripos($pathname,'.mp4')-13);
$thumbnail = 'files/thumbnails/'.$filename.'.jpg';
exec("ffmpeg -i $pathname -an -y -f mjpeg -ss 00:00:04 -vframes 1 $thumbnail");
}
but nothing happens and the thumbnails folder is always empty!
- How can I find out is ffmpeg installed on my server or not?
- How can I get my script to work?
Please help
try this:
$ffmpeg = "c:/wamp/www/includes/ffmpeg/bin/ffmpeg";
$videos = "c:/wamp/www/files/videos/*.mp4";
$ouput_path = "c:/wamp/www/files/thumbnails/";
foreach(glob($videos) as $v_file){
$fname = basename($v_file, ".mp4");
$thmb = $ouput_path.$fname.'_tn.jpg';
$cmd = "$ffmpeg -i $v_file -an -y -f mjpeg -ss 00:00:04 -vframes 1 $thmb";
$stat = system ($cmd);
}
Try with absolute paths in commands instead of depending on PATH ENV variable:
Both exec() and system() works. Resolve the path definitions.
/* Using Absolute paths */
$ffmpeg = "c:/wamp/www/includes/ffmpeg/bin/ffmpeg";
$videos = "c:/wamp/www/files/videos/*.mp4";
$ouput_path = "c:/wamp/www/files/thumbnails/";
foreach(glob($videos) as $video_file){
$filename = basename($video_file, ".mp4");
$thumbnail = $ouput_path.$filename.'_tn.jpg';
$command = "$ffmpeg -i $video_file -an -y -f mjpeg -ss 00:00:04 -vframes 1 $thumbnail";
$status = system ($command);
/*or
$status = exec($command);
if ($status === false) {
var_dump("ERROR: Conversion Failed!!!!");
} else
var_dump($status);
*/
}
I´m not allowed to add a comment, so here (as a Post) is what I found out while dealing with this:
The white space in the file name prevents ffmpeg from finding the right file. So one way is to change the file name.

Categories