我编写了一个代码,在 YII 中使用 ffmpeg 从上传的 mp4 视频中获取图像。
在本地主机中,当我写了像 d:/wamp/www/projectname/ffmpeg
这样的绝对路径时像这样,它工作得很好,我得到了图像,但是当我尝试像下面这样使用 baseurl
$var="http://".$_SERVER['HTTP_HOST'].Yii::app()->request->baseUrl;
$ffmpeg = $var."/ffmpeg/bin/ffmpeg.exe";
我无法从视频中获取图像。
这是我的代码
$var="http://".$_SERVER['HTTP_HOST'].Yii::app()->request->baseUrl;
$ffmpeg = $var."/ffmpeg/bin/ffmpeg.exe";
// $uploaddir is my file upload path
$video = $uploaddir.$image_name;
//where to save the image
$iname = basename($image_name, ".mp4");
$image = $uploaddir.'/'.$iname.'_img.jpg';
//time to take screenshot at
$interval = 5;
//screenshot size pn
$size = '640x480';
//ffmpeg command
$cmd="$ffmpeg -i ".$video." -ss 00:00:01.100 -f image2 -vframes 1 ".$image;
exec($cmd);
最佳答案
无法执行“http://foo.bar/ffmpeg/ffmpeg.exe”,
exec 需要二进制文件的绝对路径:
/**
* return d:/wamp/www/projectname
*/
$var = dirname(Yii::app()->getBasePath());
$ffmpeg = $var."/ffmpeg/bin/ffmpeg.exe";
if(!file_exists($ffmpeg))
exit("sorry dude, i cant find ffmpeg.exe!");
关于php - 在 YII 中使用 ffmpeg 从 mp4 视频中获取图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31243383/