2016-10-13 00:16:48 点击量:27 标签: 收藏本文
[FFmpeg]ffmpeg基于phpcms程序的在线转换视频exec函数版
程序为phpcms,你可以修改下做到你的项目中.此为在线转换,非上一版本的bat批处理版
- <?php
- require dirname(__FILE__).'/include/common.inc.php';
- if($PHPSESSID)
- {
- session_id($PHPSESSID);
- session_start();
- }
- if($auth) set_cookie('auth', $auth);
- if(!get_cookie('cookietime') && $cookietime) set_cookie('cookietime', $cookietime);
- require_once 'admin/model_field.class.php';
- $field = new model_field($modelid);
- $info = $field->get($fieldid);
- if(!$info) showmessage('指定的字段不存在!');
- $upload_allowext = $info['upload_allowext'];
- $upload_maxsize = $info['upload_maxsize']*1024;
- require_once 'attachment.class.php';
- $attachment = new attachment();
- if($dosubmit)
- {
- $aid = $attachment->upload('Filedata', $upload_allowext, $upload_maxsize);
- if($aid)
- {
- $filename = $attachment->uploadedfiles[0]['filename'];
- $fileurl = UPLOAD_URL.$attachment->uploadedfiles[0]['filepath'];
- $houzhui = $attachment->uploadedfiles[0]['fileext'];
- /* if($houzhui == 'rmvb' || $houzhui == 'rm'){
- exit($filename.'|'.$fileurl);
- }*/
- if($houzhui != 'flv')
- {
- $mpeg = PHPCMS_ROOT."FFmpeg/ffmpeg.exe";
- $fromFile = PHPCMS_ROOT.$fileurl;
- //$time = date("Y",TIME).'/'.date("md",TIME).'/';
- $file = $attachment->uploadedfiles[0]['filepath'];
- $name = explode('.',$file);
- $filename1 = $name[0];
- $flvName = PHPCMS_ROOT.UPLOAD_URL.$filename1.".flv";
- $flvWith = 320;
- $flvHeight = 240;
- set_time_limit(0);
- exec("$mpeg -i $fromFile -y -ab 28 -ar 22050 -b 200000 -r 24 -s $flvWith*$flvHeight $flvName",$mStatus,$status);
- $image = PHPCMS_ROOT.UPLOAD_URL.$filename1.".jpg";
- exec("$mpeg -i $fromFile -y -ss 00:00:01 -t 00:00:02 -f image2 -vframes 10 $image");
- if($status == 0){
- unlink(PHPCMS_ROOT.$fileurl);
- exit($filename.'|'.UPLOAD_URL.$filename1.".flv$".UPLOAD_URL.$filename1.".jpg");
- }
- else{
- exit("sorry!Conversion failed!!");
- }
- }
- else{
- exit($filename.'|'.$fileurl);
- }
- }
- else
- {
- if (isset($_FILES["Filedata"])) {
- echo $_FILES["Filedata"]["error"];
- exit;
- }
- }
- }
- else
- {
- include template('phpcms','flash_upload');
- }
- ?>
主要看思路哈.说实话,php的exec相当难用,涉及到系统权限等一大堆乱七八糟的东西.有时候真是让人崩溃,最近严重崩溃中,把以前一个项目的代码拷贝来,防止电脑挂了或者电脑没在身边的时候看看.也给大家参考下,有不对的地方还望斧正.
我们是一家提供综合软件外包与弱电工程服务的技术公司。
业务涵盖定制软件、管理系统、网站、小程序、APP、系统集成、网络布线、监控安防、门禁、机房建设及长期技术维护。
公司地址:湖北省宜昌市伍家岗区东站二路6号三峡(宜昌)大数据产业园海洋馆二楼A203室