ffmpeg reducing the qualitu of photos - php

I am using ffmpeg to convert photos to video and i am pretty successfull so far.
However I am facing quality issue.
$command1="ffmpeg -r 1/1 -pattern_type glob -i 'pics/*.jpg' -vf \"pad=ceil(iw/2)*2:ceil(ih/2)*2\" finalPics/video.mp4";
exec($command1);
What is wrong with the command as video quality is really reducing the quality of images

Try using
ffmpeg -r 1/1 -framerate 25 -pattern_type glob -i 'pics/*.jpg' -c:v libx264 -profile:v high -crf 20 -pix_fmt yuv420p pics/video.mp4

Related

FFMPEG command in PHP shell_exec is too slow for a 300Mo mp4

I have a web site where user upload videos.
When a video is uploaded I shell_exec 3 ffmpeg commands:
Generate preview:
$cmd = "ffmpeg -ss 1 -i ".$filePath." -vf \"scale='if(gt(dar,360/202),202*dar,360)':'if(gt(dar,360/202),202,360/dar)',setsar=1,crop=360:202\" -frames:v 1 ".$thumbnail;
Compress the video:
$cmd = "ffmpeg -i ".$filePath." -c:v libx264 -crf 23 -preset veryfast -c:a aac -ab 128k -movflags faststart ".$wmoutput;
Add watermark:
$cmd = 'ffmpeg -i '.$wmoutput.' -i new/watermark.png -filter_complex "overlay=10:10" '.$finaloutput;
The problem is that these 3 commands take a lot of time to finish and sometimes it goes over Maximum execution time specialy for video files that are bigger than 300Mo. I can just expand the Maximum execution time but I don't know how many seconds I have to set.
Is there a way to make the scripts above execute faster without having to change the Maximum execution time?
Combine Compress the video and add watermark into one command:
ffmpeg -i input.mp4 -i new/watermark.png -filter_complex "overlay=10:10" -c:v libx264 -crf 23 -preset veryfast -c:a aac -ab 128k -movflags faststart output.mp4
Should be significantly faster and you avoid yet another instance of generation loss.

ffmpeg - convert mkv to mp4 with default subtitle

What is best way to convert mkv to mp4, with default subtitle (that mkv have), and keep same quality of video / audio ?
Currently I'm using this command
ffmpeg -y -i filename.mkv -vf subtitles='filename.mkv' -disposition:s default+forced -c:v libx264 -c:a libmp3lame -crf 27 -preset ultrafast filename.mp4
But the command still not perfect, the mkv have better quality than mp4 generated. Any advise?
Thanks
your preset is lowest possible quality, and crf could be lower, 18 is more or less lossless, this will make the transcoding slower. of course
So suggest -crf 18 and -preset slow
If you aren't bothered about which codecs you use you could just copy everything into the mp4 container, which would be megaquick

ffmpeg command is not run when I hit using exec function in php

I have to convert some video to "h264" using FFmpeg.When I hit the below command as a cloud user with ssh login it converts successful.
ffmpeg -i /var/www/media/photos/video_demo/55291482115655.MP4 -codec:v libx264 -profile:v high -preset slow -b:v 500k -maxrate 500k -bufsize 1000k -vf scale=-1:300 -threads 0 -pass 1 -codec:a libfdk_aac -b:a 500k -f mp4 /var/www/media/photos/video_demo/5888.MP4.
But when I run this command using PHP it gives me an error.
$cmd = "ffmpeg -i /var/www/media/photos/video_demo/55291482115655.MP4 -codec:v libx264 -profile:v high -preset slow -b:v 500k -maxrate 500k -bufsize 1000k -vf scale=-1:300 -threads 0 -pass 1 -codec:a libfdk_aac -b:a 500k -f mp4 /var/www/media/photos/video_demo/85493.MP4 ";
exec($cmd .' 2>&1', $outputAndErrors, $return_value);
php error: Error while opening encoder for output stream #0:0 - maybe incorrect parameters such as bit_rate, rate, width or height
I also followed this link similar to my problem but still not get solution for this problem,In my server there is 3 FFmpeg installed.

Issue in converting .mov to .mp4 php

I am trying to convert a video with extension .mov to .mp4 format. Following is the command that I try to use
$file_name = "abc.mov";
$mp4_file = "abc.mp4";
$cmd = 'sudo /usr/bin/ffmpeg -i /path_to_file' . $file_name . ' -strict experimental -vcodec libx264 -pix_fmt yuv420p -profile:v baseline -preset slower -crf 18 -vf "scale=trunc(in_w/2)*2:trunc(in_h/2)*2" /destination_path/' . $mp4_file;
exec($cmd, $out, $res);
However the desired file( with .mp4 ) is not getting created. When I copy the command and paste it inside terminal, the file with the desired format is getting created. However same is not working with exec command in my php code.
I am not able to figure out the actual cause of issue, since it seems out to be strange. Any help shall be appreciated. Thanks in advance
Try putting a '2&>1' at the end of the exec?
Use this code it Work's for me :)
ffmpeg -i input.mov -vcodec libx264 -pix_fmt yuv420p -profile:v baseline -preset slow -crf 22 -movflags +faststart output.mp4
Hope it help you.

Why does FFMPEG work in terminal but not in php with exec()?

I am trying to get FFMPEG to work in php. I just installed ffmpeg and x264 and ran the following command in my terminal:
$command = 'ffmpeg -i /home/gman/Desktop/cave.wmv -acodec libfaac -aq 100 -vcodec libx264 -preset slow -crf 22 -threads 0 /home/gman/Desktop/newvideo.flv
It worked perfectly and created a new flv video from the inital video, just like I wanted.
Now when I try the same thing in php, nothing happens...
$safe_path = escapeshellarg("/home/gman/Desktop/newvideo.flv");
$command = 'ffmpeg -i /home/gman/Desktop/cave.wmv -acodec libfaac -aq 100 -vcodec libx264 -preset slow -crf 22 -threads 0 ' . $safe_path;
exec($command);
Anyone have any ideas? Can I somehow see what exec is doing and see some sort of output? Would appreciate it.
Usually when you are calling ffmpeg in an exec you need to put in the absolute path to ffmpeg eg:
$safe_path = escapeshellarg("/home/gman/Desktop/newvideo.flv");
$command = '/usr/local/bin/ffmpeg -i /home/gman/Desktop/cave.wmv -acodec libfaac -aq 100 -vcodec libx264 -preset slow -crf 22 -threads 0 ' . $safe_path;
exec($command);
http://blog.codyjung.com/2011/05/29/problems-with-lampp-and-exec/
My solution was to simply copy the ones from /usr/lib/i386-linux-gnu and overwrite the LAMPP ones. Could that cause problems later? Maybe, but I guess we’ll deal with that when it shows up.

Categories