FFMPEG gif resizing not working while I am adding watermark - php

I am trying to resize video to gif image. But everytime i am getting failure.
Please check my cdde:
$input = "files/video.mp4";
$thumbnail = 'img/logo.png'
$output = 'gif/'.time().'.gif';
$command = "ffmpeg -t 3 -ss 00:00:02 -i $input -i $thumbnail -filter_complex overlay=W-w-5:H-h-5 -codec:a copy $output"
#exec($command, $ret);
print_r($ret);
Above command I am not getting array result. But working fine. My video successfully converted to GIF with watermark. But if I am trying to resize below code. This command not working. Please tell me where is error
$command = "ffmpeg -t 3 -ss 00:00:02 -i $input -vf scale=400:-1 -i $thumbnail -filter_complex overlay=W-w-5:H-h-5 -codec:a copy $output"
Please help me. Let me know if any other way to make video to gif with resize and watermark image.
EDIT: If I am removing watermark command. Then my resize GIF working fine.

The scaling should occur within the complex as well.
ffmpeg -t 3 -ss 00:00:02 -i $input -i $thumbnail -filter_complex [0]scale=400:-1[b];[b][1]overlay=W-w-5:H-h-5 -codec:a copy $output
Else the standalone vf output is mapped for output by ffmpeg.
FFmpeg offers palettegen and paletteuse filters for optimized GIF generation.
ffmpeg -t 3 -ss 00:00:02 -i $input -i $thumbnail -filter_complex [0]scale=400:-1[b];[b][1]overlay=W-w-5:H-h-5,split[v][p];[p]palettegen,fifo[pal];[v][pal]paletteuse -codec:a copy $output

Related

how to add watermark in multiple areas using ffmpeg?

i am using laravel framework and also using ffmpeg php library. Actually i have done almost 70% of work. But the problem i faced is to show watermark at multiple areas on video. I have done the watermark on top-left corner that is running very fine on that video. But i want to add watermark in top-left, bottom-left, bottom-right. I have used this code for top-left watermark (for video):-
$inputVideo = public_path('input/airplane_flight_airport_panorama_1080.mp4');
$outputVideo = public_path('uploads/output.mp4');
$watermark = public_path('input/watermark.jpg');
$wmarkvideo = "ffmpeg -i ".$inputVideo." -i ".$watermark." -filter_complex ". '"overlay=x=(main_w-overlay_w):y=(main_h-overlay_h)/(main_h-overlay_h)"'." ".$outputVideo;
exec($wmarkvideo );
Please help me how can i add watermark on top-left, bottom-left, bottom-right in these areas. Thanks in advance :)
This is the ffmpeg command you would use for multiple watermarks
ffmpeg -i inputVideo -i watermark-tr -i watermark-tl -i watermark-br -i watermark-bl
-filter_complex "[0][1]overlay=x=W-w:y=0[tr];
[tr][2]overlay=x=0:y=0[tl];
[tl][3]overlay=x=W-w:y=H-h[br];
[br][4]overlay=x=0:y=H-h" outputfile
tr = top-right; tl = top-left; br = bottom-right; bl = bottomleft
With center as well,
ffmpeg -i inputVideo -i watermark-tr -i watermark-tl -i watermark-br -i watermark-bl -i watermark-c
-filter_complex "[0][1]overlay=x=W-w:y=0[tr];
[tr][2]overlay=x=0:y=0[tl];
[tl][3]overlay=x=W-w:y=H-h[br];
[br][4]overlay=x=0:y=H-h[bl];
[bl][5]overlay=x=(W-w)/2:y=(H-h)/2" outputfile

FFMPEG image resize not working

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

To water mark videos at bottom right corner using ffmpeg

I found some answer here in stack which is indeed using ffmpeg but it is giving me some error.
I ran it in command window and the error is quite like
"Unable to find a suitable output format for 'ΓÇôi'
ΓÇôi: Invalid argument".
my command is as follows
ffmpeg –i inputvideo.avi -vf "movie=watermarklogo.png [watermark]; [in][watermark] overlay=(main_w-overlay_w-10)/2:(main_h-overlay_h-10)/2 [out]" outputvideo.mp4
please suggest some ideas.
Basically overlay property defines where your watermark image will be posted -
main_w: video width
main_h: video height
overlay_w: overlay width
overlay_h: overlay height.
I guess this should work fine
$mark = "ffmpeg -i ".$inputvideo." -i logo.png -filter_complex ". '"overlay=x=(main_w-overlay_w):y=(main_h-overlay_h)/(main_h-overlay_h)"'." ".uniqid()."topright.mp4";
You can try these out. Should work out for you.
/*
* At top left watermark
*/
$mark = "ffmpeg -i ".$inputvideo." -i logo.png -filter_complex ". '"overlay=x=(main_w-overlay_w)/(main_w-overlay_w):y=(main_h-overlay_h)/(main_h-overlay_h)"'." ".uniqid()."topleft.mp4";
/*
* At top right watermark
*/
$mark = "ffmpeg -i ".$inputvideo." -i logo.png -filter_complex ". '"overlay=x=(main_w-overlay_w):y=(main_h-overlay_h)/(main_h-overlay_h)"'." ".uniqid()."topright.mp4";
I tried with this command, and it worked for me. hope it will work for you as well.
$mark = "ffmpeg -i inputvideo.mp4 -i watermark.png -filter_complex 'overlay=x=(main_w-overlay_w):y=(main_h-overlay_h)' outputvideo.mp4";
exec($mark);

ffmpeg Getting image or thumbnail from video error

i have a simple site on which people upload videos, so i want to generate a simple thumbnail from an uploaded video. i have tried every trick and way to do this from a number of websites but i am failing to make the command run without problems.
$video = $_FILES['vpopupdropin']["tmp_name"];
$ffmpeg = "C:\\Ffmpeg\\ffmpeg-20130605-git-3289670-win64-static\\bin";
$image = "manu.jpg";
$second = 12;
$size = "150x90";
$command = "$ffmpeg -i $video -an -ss $second -s $size -vcodec mjpeg $image";
echo $command;
shell_exec($command);
if(shell_exec($command)){
echo 'okay';
echo '<img src="'.$image.'"/ >';
}
else{
echo ' Problem';
}
i Echoed the the command from PHP and this is what i got:
C:\Ffmpeg\ffmpeg-20130605-git-3289670-win64-static\bin -i C:\xampp\tmp\php27F1.tmp -an -ss 12 -s 150x90 -vcodec mjpeg manu.jpg Problem
so i took the Command above and entered it in Cmd and got this error
[image2 # 00000000000000003d87580] Could not open file : manu.jpg
av_interleaved_write_frame(): Input/output error. the uploaded file transfers well to where iam saving it and plays well on the site meaning the file is not corrupt. but the thumbnail command seems to fail, i have even checked the other questions on this site but i seem to fail to get the right solution. the paths in the Command are correct and i have verified that at least
You did not give ffmpeg a name :-) So you tried to execute a \\bin folder !
$ffmpeg = "C:\\Ffmpeg\\ffmpeg-20130605-git-3289670-win64-static\\bin";
you forget ffmpeg.exe
$ffmpeg = "C:\\Ffmpeg\\ffmpeg-20130605-git-3289670-win64-static\\bin\\ffmpeg";
I do it for a .avi with following command
ffmpeg -i Echo2012.avi -r 1 -s 1024x576 -f image2 -vframes 1 foo-001.jpg
Don't execute your command twice !
$command = "$ffmpeg -i $video -an -ss $second -s $size -vcodec mjpeg $image";
echo $command;
shell_exec($command);
if(shell_exec($command)){
EDIT :
your command string :
ffmpeg -i upload.tmp -an -ss 12 -s 150x90 -vcodec mjpeg manu.jpg
-vcodec codec (output) : Set the video output codec. It's a switch for a output video. You want as output an image.
-an : You can disable Audio stream. You don't need Audio for an image.
-ss : position (input/output) When used as an input option (before -i), seeks in this input file to position.
my command string :
ffmpeg -i Echo2012.avi -r 1 -s 1024x576 -f image2 -vframes 1 foo-001.jpg
-r : fps (input/output,per-stream) . Set frame rate (Hz value, fraction or abbreviation).
As an input option, ignore any timestamps stored in the file and instead generate timestamps assuming constant frame rate fps.
-f image2 : Force output file format image2. The format is normally auto detected guessed from the file extension for output files.
-vframes number (output) : Set the number of video frames to record.

How to take pictures of the video through mplayer or ffmpeg to php?

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.

Categories