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.
Related
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.
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.
I have installed ffmpeg on my server.
Now I am looking for a php library which can perform ffmpeg functionality, like retrieving video information, converting it to FLV or in any other format, and streaming video.
Please help, Thanks!
You can use below function to convert mp4 video to flv
function mp4toflv($in, $out)
{
//echo $in.' '.$out;
$thumb_stdout;
$errors;
$retval = 0;
// Delete the file if it already exists
if (file_exists($out)) { unlink($out); }
$cmd = "ffmpeg -i $in -ar 22050 -acodec libmp3lame -ab 32K -r 25 -s 320x240 -vcodec flv $out";
//$cmd = "ffmpeg -i $in -b 1024k -s 352x264 -r 25 -acodec copy $out";
//echo escapeshellcmd($cmd);
exec(escapeshellcmd($cmd));
unlink($in);
}
similarly you can also convert other video formats to flv or any other format. Below are some help to convert videos to mp4(h264)
1]. ffmpeg -i input.mp4 -vcodec libx264 output.mp4
2]. ffmpeg input.AVI -vcodec libx264 -sameq output.mp4
option 1 can use for :- (mp4,mov,flv)
option 2 can user for :- (3gp,avi,mp4,mov,flv)
execute above commands using "exec(escapeshellcmd($cmd))" where $cmd will be any from above two options.
Hope this will help someone :)
We have been using ffmpeg-php without any major problems, just make sure you are using supported ffmpeg version. If you need any special behaviour, you can always additionally wrap it using exec().
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.
I want to convert a video from one format to another using ffmpeg. I try lots of code but it does not convert the video.
For example:
exec("ffmpeg -i mickey.flv -ar 22050
-ab 32 -f avi -s 320x240 mickey.avi ");
This code does not convert the video, it does not show any error, it is loading continuously.
It is impossible to pinpoint the problem, because you are executing an external application and any number of things could be going wrong in the process.
See this question for a number of very good hints to debug exec() commands.
Display FFMPEG Error Output:
Command Line:
$command = "ffmpeg -i mickey.flv -ar 22050 -ab 32 -f avi -s 320x240 mickey.avi ";
exec($command . ' 2>&1', $output);
print_r($output);