PHP头条
热点:

PHP作视频网站,让程序自动实现视频格式转换、设置视频大小、生成视频缩略图


PHP做视频网站,让程序自动实现视频格式转换、设置视频大小、生成视频缩略图

一、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“。更多详情》 ?
/* 转视频?? */ $cmd="ffmpeg.exe -i tiwer_update_move.avi -ab 56 -ar 22050 -b 500 -r 15 -s 500x600 201112120089123.flv";? ? exec($cmd);? ? /*? 视频截图*/ $cmd="ffmpeg.exe -itiwer_update_move.avi -f image2 -ss 10 -s 600*500 -vframes 1 201112120089123.jpg";
exec($cmd);

?三、生成缩略图

?

include("ImageHelper.class.php"); ? /* 生成缩略图 */ $thumbnail?= new?ImageHelper();? $thumbnail->resizeimage("2012121208123.jpg", 30,30, 0, "2012121208123_small.jpg");?

?

  

?

四、工具类与软件下载

  4.1 图片处理工具类如下

复制代码
  1 /**
2 * 图片处理工具
3 *
4 * Project: BoBo Manage System
5 * This is NOT a freeware, use is subject to license terms!
6 *
7 * Site: http://www.bobo123.cn
8 *
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,
www.phpzy.comtrue/phprm/1782.htmlTechArticlePHP作视频网站,让程序自动实现视频格式转换、设置视频大小、生成视频缩略图 PHP做视频网站,让程序自动实现视频格式转换、设置视频大小、生成视频缩略图 一、PHP实现转换 在做视...

相关文章

相关频道:

PHP之友评论

今天推荐