ffmpeg with php not completed if file size > 5mb - php

I'm using FFMPEG to upload videos to my server,
I've tested on 1MB file and another one 5MB and it is working correctly, but then I've tested on 6MB and 50MB file and it try to upload but still with "processing" status with no change.
Here is the code which I use
exec("/usr/local/bin/ffmpeg -i ../uploadedvideo/".$image_name." -ab 56 -ar 44100 -b 200 -r 15 -s 240x180 -fs 314572800 -f flv ../uploadedvideo/".$image_namew.".flv");
What could be the problem?

Related

504 Gateway Timeout ffmpeg video compression

I have a PHP script that use the ffmpeg to compress mov file and convert in mp4.
When I upload a 1gb file, this is converted and in the end appears in console 504 (Gateway Timeout).
The instruction I use is this:
$cmd = shell_exec("$ffmpegPath -i $UploadedFilePath -vcodec libx264 -preset ultrafast -filter:v scale=426:-2 $convertUrl 2>&1");
How can I do?
I would like the videos to be reduced considerably while maintaining good quality and without overloading the server.
The PHP parameters can be found at this link:
https://artruism.me/test.php
UPDATE
The call to the script is with ajaxForm

Reduce file size of ffmpeg converted video

I have a .mp4 video with a file size of 540kb and a duration of 30 seconds before it was converted, but when I use ffmpeg to convert it to the file size became 21mb. What options do I need to add inorder to reduce the file size to less than 1mb?
ffmpeg command I am using right now:
video_filename = __DIR__. '/uploads/VID.mp4';
exec('ffmpeg -i '.$video_filename.' -c:v libx264 '.$video_filename.'');
Create tmp_dir in the desired location
exec('ffmpeg -i '.$video_filename.' -c:v libx264 -crf 25 tmp_dir'.$video_filename.'');
exec('rm -rf '. $video_filename);
exec('mv tmp_dir/'.$video_filename.' ..');
I hope it will work properly, I haven't test it!.

how to compress mp3 file from php

I am using both commands in my controller, but sometimes they are not working properly.
Sometimes the compressed file size is larger than size of the original file.
exec(FFmpeg -i old.mp3 -ab 64 mp3 newfile.mp3)
And
exec(ffmpeg -i old.mp3 -acodec libmp3lame -ab 48k new.mp3)
Please, help me.
Above both command is different:
Option Description
-ab bitrate : set audio bitrate (in kbit/s)
-acodec codec : force audio codec ('copy' to copy stream)
That's why In the first command set audio stream in 64 bit, and in the second command is do the stream copy to copy.
I hope this helps.

ffmpeg compresses upto 32 kbps only

I have created a PHP code which compresses mp3 while uploaded to 32kbps bit rate I have referred this thread
How to compress or convert to low quality Mp3 file from PHP
used this code
exec("ffmpeg -i inputfile.mp3 -ab 24000 outputfile.mp3")
but the problem is I can't compress more than 32kbps .my code instruct to compress up to 24kbps but after execution, I can see the output file is 32kbps. can anyone tell what should I do so that I can compress more than 32kbps .or is there any limitation of ffmpeg ??
The reason you cant achieve lower then 32kbps is because of the sample rate most likely is still 44100-Hz meaning larger stream size, you have a few options 44100-Hz, 22050-Hz, and 11025-Hz as valid frequency's.
Try (very low quality):
ffmpeg -i inputfile.mp3 -acodec libmp3lame -b:a 8k -ac 1 -ar 11025 outputfile.mp3
-b:a = audio bitrate
-ar = sample rate

ffmpeg-php and shell_exec

I'm using ffmpeg-php for uploading videos and converting videos from
"ogv", "mp4", "avi", "flv", "ogg",
"mpg", "wmv", "asf" and "mov"
formats to
"flv" , "ogg" and "flv" formats.
I'm doing this by:
$command1='ffmpeg -i '.$Source." -ar 44100 -ab 128k -s wvga -aspect 4:3 -f FLV -y ".$dest;
$command2="ffmpeg -i ".$Source." -acodec libfaac -ab 128k -ac 2 -vcodec libx264 -vpre slow -threads 10 -s wvga -aspect 4:3 -f mp4 -y ".$dest;
$command3="ffmpeg -i ".$Source." -acodec libvorbis -ab 128k -ac 2 -vcodec libtheora -threads 10 -s wvga -aspect 4:3 -f ogg -y ".$dest;
#shell_exec($command1.";".$command2.";".$command3);
When applying those commands on .ogv videos it works fine but when applying on .MOV it does not work and no errors displays although when I paste the command into the terminal it works fine.
Hint: Script is running by cron job.
is there any suggestions for this problem?
Most likely the script is running out of time before the conversion takes place.
Increase the execution time of your scripts.
Although its not a recommend solution for production. You might want to run background processes to do the conversion and use the PHP script just to upload the video.
What happens when you run the problem part outside of a crontab?
are you saving the output of your crontab entry to files? i.e.
59 12 1 1 * { myPhpScript ; } > /tmp/myPhpScript.log 2>&1` ...
( The semicolon preceding the closing '}' is critical)
This captures any stdout or stderr messages to a logfile.
I hope this helps.
P.S. as you appear to be a newish user, if you get an answer that helps you please remember to mark it as accepted, and/or give it a + (or -) as a useful answer.

Categories