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
Related
I am generating thumbnail from video while uploading and I have installed ffmpeg on local but in live server ffmpeg is not installed and hosting provider asking extra charges to install it, so i have kept ffmpeg directory which i copied from local machine and placed to live server and provided live server path and try to call script but it is not generating thumbnail
$ffmpeg = 'https://example.com/ffmpeg/bin/ffmpeg.exe';
$video_temp_path = $_FILES['upload_file']['tmp_name'];
$video_title = $_FILES['upload_video']['name'];
$image = 'upload/' . $video_title . uniqid().'.jpg';
//time to take screenshot at
$interval = 5;
//screenshot size
$size = '320x240';
//ffmpeg command
$command = $ffmpeg.' -i '.$video_temp_path.' -deinterlace -an -ss '.$interval.' -f mjpeg -t 1 -r 1 -y -s '.$size.' '.$image.' 2>&1';
exec($command, $array);
after upload ffmpeg on live server restart server first then it's work
My ffmpeg command in php is
echo $cmd_thumbnail_create = ("\"$ffmpeg\" -i \"" . $dir.$videopath . "\" -an -ss $getFromSecond \"" . $dir.$thumbnailpath ."\"");
exec($cmd_thumbnail_create);
Output of which is
"C:\FFMPEG\bin\ffmpeg" -i "C:/xampp/htdocs/final/uploaded_videos/intro_en.mp4" -an -ss 6 "C:/xampp/htdocs/final/thumbnail/intro_en.jpg"
This when copied and executed on the command prompt creates the thumbnail at proper location with proper name.
Any suggestions?
This worked for me...
first.... locate your path to FFMPEG
mine is
$ffmpeg = "H:\\SERVr\\htdocs\\ffmpeg\\bin\\ffmpeg";
Then.. in your shell_exec...
shell_exec("$ffmpeg -i your-input.jpg -an -ss 30 -s 120x100 your-output.jpg 2>&1");
-i is your input file.
-ss is video time you want the clip pulled from.
-s is the size of the thumbnail you want
This works on my Windows machine with XAMPP, and works perfectly.
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.
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.
In my website I have a option to upload video file by the user. In that I want to create a thumbnail image of that video. I have tried in local system with some coding it is working fine. I tried same coding in to service it is not working. I checked for ffmpeg enabled in server, it was disabled. Is their any other option to creating thumbnail in server with out enabling the ffmpeg? Please help me to find the solution.
you can use ffmpeg ( Form you tag i guess you knew )
What you needed to pass to ffmpeg is
-i = input file
-deinterlace = deinterlace pictures
-an = disable audio recording
-ss = start time in the video (seconds)
-t = duration of the recording (seconds)
-r = set frame rate
-y = overwrite existing file
-s = resolution size
-f = force format
Example
// where ffmpeg is located
$ffmpeg = '/usr/bin/ffmpeg';
//video dir
$video = 'path/to/video';
//where to save the image
$image = 'path/to/image.jpg';
//time to take screenshot at
$interval = 5;
//screenshot size
$size = '640x480';
//ffmpeg command
$cmd = "$ffmpeg -i $video -deinterlace -an -ss $interval -f mjpeg -t 1 -r 1 -y -s $size $image 2>&1";
exec($cmd);
Or try
$second = 15;
$cmd = "$ffmpeg -itsoffset -$second -i $video -vcodec mjpeg -vframes 1 -an -f rawvideo -s $size $image";
exec($cmd);
Think you should also look at detail dissuasion on possible issues
ffmpeg-php to create thumbnail of video
If you don't want to use ffmpeg you could use mencoder as an alternative too. But in the end you will need to install ffmpeg/mencoder and then use that to render the thumbnail as PHP has no built in functionality to handle video.
If you're on a shared webhost you might want to look into services like zencoder that can generate you converted streams of video including thumbnails:
https://app.zencoder.com/docs/api/encoding/thumbnails