在YII中使用ffmpeg从mp4视频获取图像 [英] Getting image from mp4 video using ffmpeg in YII

查看:248
本文介绍了在YII中使用ffmpeg从mp4视频获取图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



在本地主机中,当我写了绝对路径,如 d:/ wamp / www / projectname / ffmpeg 像这样,它工作正常,我正在获得图像,但是当我尝试如下使用 baseurl

  $ var =http://$ _ SERVER ['HTTP_HOST']。Yii :: app ) - >要求─>的baseUrl; 
$ ffmpeg = $ var。/ ffmpeg / bin / ffmpeg.exe;

我无法从视频中获取图像。



这是我的代码

  $ var =http://。$ _ SERVER ['HTTP_HOST']。 YII ::应用程序() - >请求 - >的baseUrl; 
$ ffmpeg = $ var。/ ffmpeg / bin / ffmpeg.exe;
// $ uploaddir是我的文件上传路径
$ video = $ uploaddir。$ image_name;
//保存图像的位置
$ iname = basename($ image_name,.mp4);
$ image = $ uploaddir。'/'。$ iname .'_ img.jpg';
//截图时间为
$ interval = 5;
//截图大小pn
$ size ='640x480';
// ffmpeg命令
$ 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;
如果(!file_exists($ ffmpeg))
退出(对不起,我找不到ffmpeg.exe!);


I have written a code to get an image from an uploaded mp4 video using ffmpeg in YII.

In localhost, when i have written absolute path like d:/wamp/www/projectname/ffmpeg like this, it is working perfectly and i am getting image but when I tried like below using baseurl

$var="http://".$_SERVER['HTTP_HOST'].Yii::app()->request->baseUrl;
$ffmpeg = $var."/ffmpeg/bin/ffmpeg.exe";

I am unable to get the image from video.

Here is my code

$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);

解决方案

it is not possible to execute "http://foo.bar/ffmpeg/ffmpeg.exe", exec requires a absolute path to the binary:

/**
 * 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!");

这篇关于在YII中使用ffmpeg从mp4视频获取图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆