【发布时间】:2015-10-10 11:32:36
【问题描述】:
大家好,我已经在本地计算机上成功安装了 ffmpeg,现在我想知道在通过 php 将文件上传到服务器时如何使用它。 我希望用户上传的所有文件都转换为 swf 格式。 我还通过 php.ini 增加了我的上传限制,所以没有 upload_mx_size 的问题
直到现在我都在使用这个代码
<?php
$srcFile = "test/Sample.mp4";
$destFile = "/test/Sample22";
$ffmpegPath = "/usr/local/bin/ffmpeg";
$flvtool2Path = "/usr/local/bin/flvtool2";
// Create our FFMPEG-PHP class
$ffmpegObj = new ffmpeg_movie($srcFile);
// Save our needed variables
$srcWidth = makeMultipleTwo($ffmpegObj->getFrameWidth());
$srcHeight = makeMultipleTwo($ffmpegObj->getFrameHeight());
$srcFPS = $ffmpegObj->getFrameRate();
$srcAB = intval($ffmpegObj->getAudioBitRate()/1000);
$srcAR = $ffmpegObj->getAudioSampleRate();
$srcVB = floor($ffmpegObj->getVideoBitRate()/1000);
// Call our convert using exec() to convert to the three file types needed by HTML5
exec($ffmpegPath . " -i ". $srcFile ." -vcodec libx264 -vpre hq -vpre ipod640 -b ".$srcVB."k -bt 100k -acodec libfaac -ab " . $srcAB . "k -ac 2 -s " . $srcWidth . "x" . $srcHeight . " ".$destFile.".mp4");
exec($ffmpegPath . " -i ". $srcFile ." -vcodec libvpx -r ".$srcFPS." -b ".$srcVB."k -acodec libvorbis -ab " . $srcAB . " -ac 2 -f webm -g 30 -s " . $srcWidth . "x" . $srcHeight . " ".$destFile.".webm");
exec($ffmpegPath . " -i ". $srcFile ." -vcodec libtheora -r ".$srcFPS." -b ".$srcVB."k -acodec libvorbis -ab " . $srcAB . "k -ac 2 -s " . $srcWidth . "x" . $srcHeight . " ".$destFile.".ogv");
?>
不知道这是否好用,但是当我刷新此页面时,它会起作用,页面显示
"Fatal error: Class 'ffmpeg_movie' not found in C:\xampp\htdocs\video\videoupload.php on line 9"
我已检查文件 sample.mp4 是否存在于测试文件夹中 请帮我上传视频文件并通过ffmpeg lib将其转换为swf格式
【问题讨论】: