一、PHP实现转换
在做视频网站的时候,最头痛的问题可能是格式转换、视频缩略图等。下面我将用PHP实现这一些功能。PHP是没有自带视频的函数,所以会用到第三方的软件工具来实现。
?
二、什么是FFmpeg
FFmpeg是一个开源免费跨平台的视频和音频流方案,属于自由软件,采用LGPL或GPL许可证(依据你选择的组件)。它提供了录制、转换以及流化音视频的完整解决方案。它包含了非常先进的音频/视频编解码库libavcodec,为了保证高可移植性和编解码质量,libavcodec里很多codec都是从头开发的。
FFmpeg在Linux平台下开发,但它同样也可以在其它操作系统环境中编译运行,包括Windows、Mac OS X等。
这个项目最早由Fabrice Bellard发起,现在由Michael Niedermayer维护。许多FFmpeg的开发人员都来自MPlayer项目,而且当前FFmpeg也是放在MPlayer项目组的服务器上。项目的名称来自MPEG视频编码标准,前面的"FF“代表"Fast Forward“。更多详情》
?
?三、生成缩略图
?
?
?
四、工具类与软件下载
4.1 图片处理工具类如下
1 /**2 * 图片处理工具3 *4 * Project: BoBo Manage System5 * This is NOT a freeware, use is subject to license terms!6 *7 * Site: http://www.bobo123.cn8 *9 * $Id: ImageHelper.class.php 269 2011-03-08 00:44:01Z wgw8299 $10 *11 * Copyright ? 2007-2012 Bobo123.CN Developer Team. All Rights Reserved.12 */13 class ImageHelper { 14 15 16 var $type; 17 18 19 /*实际宽度*/ 20 var $width; 21 22 /*实际高度*/ 23 var $height; 24 25 /*改变后的宽度*/26 var $resize_width; 27 28 /*改变后的高度*/ 29 var $resize_height; 30 31 /*是否裁图*/32 var $cut; 33 34 /*源图象*/ 35 var $srcimg; 36 37 /*目标图象地址*/ 38 var $dstimg; 39 40 /*临时创建的图象*/ 41 var $im; 42 43 function resizeimage($img, $wid, $hei,$c,$dstpath) { 44 45 $this->srcimg = $img; 46 $this->resize_width = $wid; 47 $this->resize_height = $hei; 48 $this->cut = $c; 49 50 /*图片的类型*/ 51 $this->type = strtolower(substr(strrchr($this->srcimg,"."),1)); 52 53 /*初始化图象*/ 54 $this->initi_img(); 55 56 /*目标图象地址*/57 $this -> dst_img($dstpath); 58 59 60 $this->width = imagesx($this->im); 61 $this->height = imagesy($this->im); 62 63 /*生成图象*/64 $this->newimg(); 65 66 ImageDestroy ($this->im); 67 } 68 69 function newimg() { 70 71 /*改变后的图象的比例*/ 72 $resize_ratio = ($this->resize_width)/($this->resize_height); 73 74 /*实际图象的比例*/ 75 $ratio = ($this->width)/($this->height); 76 77 78 if(($this->cut)=="1") { 79 /*裁图高度优先*/ 80 if($ratio>=$resize_ratio){ 81 $newimg = imagecreatetruecolor($this->resize_width,$this->resize_height); 82 imagecopyresampled($newimg, $this->im, 0, 0, 0, 0,
吐了个 "CAO" !
吐个槽吧,看都看了
PHP1.CN | 中国最专业的PHP中文社区 | json解析格式化 | PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved PHP1.CN 第一PHP社区 版权所有 京ICP备19059560号-4