【问题标题】:how to use ffmpeg with php and upload and compress the file如何在php中使用ffmpeg并上传和压缩文件
【发布时间】: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格式

【问题讨论】:

    标签: php video upload ffmpeg


    【解决方案1】:

    你可能缺少一个模块,使用 php -m 或 phpinfo() 来查看你是否安装了一个名为 'FFmpeg-PHP' 的模块。如果它丢失了,如果你想使用那个类,你需要安装它

    【讨论】:

    • 我已经安装了 ffmpeg 我已经通过我的 cmd 行检查了它
    • 太好了,你安装了名为'ffmpeg-php'的php模块吗?
    • 如何检查?
    • 'php -m' 从你的终端将列出已安装的模块,已安装的模块信息也包含在 phpinfo() 的输出中
    • 是的!你是对的我缺少模块我检查了我的 php.ini 。你能建议我一些可以帮助我安装模块的东西吗..
    猜你喜欢
    • 2015-09-10
    • 2012-10-18
    • 2018-04-06
    • 1970-01-01
    • 2013-09-27
    • 1970-01-01
    • 1970-01-01
    • 2011-08-09
    • 1970-01-01
    相关资源
    最近更新 更多