So this command works for generating a thumbnail 5 seconds into the video, with a size of 300x300:
$cmd = '/usr/local/bin/ffmpeg -i '.$this->getUploadRootDir().'/'.$fname.' -ss 00:00:05 -f image2 -vframes 1 -s 300x300 '.$this->getUploadRootDir().'/thumb_'.$output;
However, I want to keep the aspect ratio so I changed my code to this:
$cmd = "/usr/local/bin/ffmpeg -i ".$this->getUploadRootDir()."/".$fname." -ss 00:00:5 -f image2 scale='min(300\, iw):-1' ".$this->getUploadRootDir()."/thumb_".$output;
The above code correctly sizes the image, however it's of the first frame in the video.. I need the thumbnail to be 5 seconds in. Any help would be much appreciated.
You can do that with a command line similar to:
ffmpeg -i inputVideo -vf scale='min(300,iw)':-1 -ss 00:00:05 -f image2 -vframes 1 thumbnail.jpg
So in your script, add -vf (video filter) before scale and reorder input and output parameters like below:
$cmd = "/usr/local/bin/ffmpeg -i ".$this->getUploadRootDir()."/".$fname." -vf scale='min(300\, iw):-1' -ss 00:00:5 -f image2 -vframes 1 ".$this->getUploadRootDir()."/thumb_".$output;
#alexbuisson has the correct answer, but just to confirm as I'm playing with ffmpeg today:
This works for me:
ffmpeg -i "my_video.mp4" -ss 00:00:05 -f image2 -vf scale="min(300\, iw):-1" -vframes 1 "capture.jpg"
I get one Jpeg 300 px wide with the correct image ratio.
So adapted to your code this becomes:
$cmd = "/usr/local/bin/ffmpeg -i ".$this->getUploadRootDir()."/".$fname." -ss 00:00:05 -f image2 -vf scale='min(300\, iw):-1' ".$this->getUploadRootDir()."/thumb_".$output;
Related
FFmpeg version 0.6.5 is installed on my web server.
In my website mp4 videos allowed to upload, that part is done.
Now i am working on create a thumbnail of the video and then resize it.
The following links are I referred.
https://trac.ffmpeg.org/wiki/Create%20a%20thumbnail%20image%20every%20X%20seconds%20of%20the%20video
https://trac.ffmpeg.org/wiki/Scaling%20(resizing)%20with%20ffmpeg
This is the command i used to create a thumbnail from video, this command is working.
$cmd = "ffmpeg -i test.mp4 -ss 0 -vframes 1 out.png";
After creating the thumbnail, I tried the following the command to resize it, but this is not working.
$cmd = 'ffmpeg -i out.png -vf scale=210:-1 output_320x240.png';
And Some other commands i have tried
$cmd = "ffmpeg -ss 10 -i test.mp4 -vframes 1 -filter scale=-1:150,crop=200:150 output.jpg";
$cmd = "ffmpeg -itsoffset -1 -i test.mp4 -vframes 1 -filter:v scale=280:-1 output.jpg";
In my localhost I used the following command to create thumbnail and resize in a single command, but this is also not working in the server.
$ffmpeg = 'C:\\ffmpeg\\bin\\ffmpeg';
$video = 'test.mp4';
$cmd = "$ffmpeg -itsoffset -1 -i $video -vframes 1 -filter:v scale=\"210:-1\" thumbnail.png";
Thanks to all
I'm generating thumbnails like so:
exec(ffmpeg -itsoffset -4 -i '.$path.' -vcodec mjpeg -vframes 1 -an -f rawvideo -s 300x300 '.$other_path);
Is it possible to not specify the exact size of output image and set it to 100%?
You can simply remove the -s 300x300 option, and it will note resize.
hello all i am having this code in my php and i want to get an image after 50% of the duration of the video and also get the duration of the video in a variable i have installed ffmpeg in my php and computer
the page has following code
require 'vendor/autoload.php';
//ececute ffmpeg generate mp4
exec('ffmpeg -i '.$uploadfile.' -f mp4 -s 896x504 '.$new_flv.'');
//execute ffmpeg and create thumb
exec('ffmpeg -i '.$uploadfile.' -f mjpeg -vframes 71 -s 768x432 -an '.$new_image_path.'');
i want an image after 50% of the duration of the video and also store the video duration in a variable
please give me some suggestions i am stuck over here
First you need to get the video duration in second
and then you need to multiply total second to 0.5 to get the half.
Try this one:
$total_sec = exec("ffprobe -loglevel error -show_streams inputFile.mp4 | grep duration | cut -f2 -d=");
$total_half_sec = $total_sec * 0.5;
exec("ffmpeg -i source.mp4 -f mjpeg -vframes $total_half_sec -s 768x432 -an destination.jpg");
For more info here https://www.ffmpeg.org/ffmpeg-all.html
I am trying to create videos from images sequence. I tried all the below code given in $ff_command variable.
$path = dirname(__FILE__);
$ff_command = "ffmpeg -f image2 -i {$path}/img%03d.jpg video.mpg";
$ff_command = "ffmpeg -r 10 -b 1800 -i {$path}/img%03d.jpg test1800.mpg";
$ff_command = "ffmpeg -i {$path}/img%03d.jpg -s 1280x720 -aspect 16:9 -r 24 -vb 20M teste.mp4";
$ff_command = "ffmpeg -f image2 -i {$path}/img%03d.jpg -vcodec mpeg4 -b 800k video.avi";
$ff_command = "ffmpeg -f image2 -i {$path}/img%03d.jpg -vcodec libx264 -b 800k video.avi";
Most of these commands are creating a video file. But when I open that video nothing comes or first image is coming for a split second and nothing after that
Please let me know what I am doing wrong here
I noticed that video is too short to see. Is it possible to increase the video duration so that we can see all the images?
How to take pictures of the video through mplayer or ffmpeg to php?
try,
exec("ffmpeg -i $video_file_path -an
-y -f mjpeg -ss 00:02:00 -vframes 1 $image_path")
Assuming ffmpeg is installed on your server, you can use the following code to output the frame at exactly 2 minutes to a JPEG file:
function vidtojpeg($video_filename, $dimensions) {
exec("ffmpeg -i $video_filename -an -ss 00:01:59 -t 00:00:01 -r 1 -y -s $dimensions video%d.jpg");
}
In this function, the $video_filename parameter is self-explanatory. The $dimensions parameter accepts width and height of the outputted images in this format: WIDTHxHEIGHT. For example: 320x480 would be an acceptable parameter.
Converting the video to frames and getting the required frames based on timings can help. Try this : ffmpeg -i video.flv -r 25 -vcodec png -pix_fmt rgb32 %d.png
You can manipulate the formats and bitrate(-r) for getting the required frame in proper format.