本文实例讲述了PHP基于ffmpeg实现转换视频,截图及生成缩略图的方法。分享给大家供大家参考,具体如下:
这里把ffmpeg 和 生成缩略图整合了一下:
include("ImageResize.class.php")
//转视频
$cmd="ffmpeg.exe -i starwar.avi -ab 56 -ar 22050 -b 500 -r 15 -s 320x240 1.flv";
exec($cmd);
//视频截图
$cmd="ffmpeg.exe -i starwar.avi -f image2 -ss 10 -s 400*300 -vframes 1 1.jpg";
exec($cmd);
//生成缩略图
$thumbnail = new ImageResize();
$thumbnail->resizeimage("1.jpg", 30,30, 0, "small1.jpg");
class ImageResize {
//图片类型
var $type;
//实际宽度
var $width;
//实际高度
var $height;
//改变后的宽度
var $resize_width;
//改变后的高度
var $resize_height;
//是否裁图
var $cut;
//源图象
var $srcimg;
//目标图象地址
var $dstimg;
//临时创建的图象
var $im;
function resizeimage($img, $wid, $hei,$c,$dstpath) {
$this->srcimg = $img;
$this->resize_width = $wid;
$this->resize_height = $hei;
$this->cut = $c;
//图片的类型
$this->type = strtolower(substr(strrchr($this->srcimg,"."),1));
//初始化图象
$this->initi_img();
//目标图象地址
$this -> dst_img($dstpath);
//--
$this->width = imagesx($this->im);
$this->height = imagesy($this->im);
//生成图象
$this->newimg();
ImageDestroy ($this->im);
}
function newimg() {
//改变后的图象的比例
$resize_ratio = ($this->resize_width)/($this->resize_height);