现在的位置: 首页 > 综合 > 正文

自动转换flv文件

2013年11月17日 ⁄ 综合 ⁄ 共 11163字 ⁄ 字号 评论关闭

在线转化.

谁有 把其他的视频文件格式的视频,经过上传自动转化FLV格式的一种插件.提供编程接口.给我一份.

类似新浪网播客上传视频的一样. (还有上传是的哪个效果,进度条如何作的?)

或者给我个参考地址什 ...
环境:redhat as4

1。首先获取ffmpeg

很多人找不到怎么下载,其实之前ffmpeg可以通过cvs下载,不过最近他已经换成了更加强大的svn

如何使用SVN我这里不再介绍,网上还有大量的安装和使用的文章可以借鉴,这里简单罗列几个SVN辅助的软件:

SubVersion,从 http://subversion.tigris.org/ 下载,支持linux,我们这里就装这个

TortoiseSVN,从 http://tortoisesvn.tigris.org/ 下载,是很不错的SVN客户端程序,为windows外壳程序集成到windows资源管理器和文件管理系统的Subversion客户端,用起来很方便,commit动作变得就像Winrar右键压缩一样方便。

ok,那我们先装subversion,记住最好之前装过apr和apr-util,在apache.org网站能下到

wget
http://subversion.tigris.org/downloads/subversion-1.3.2.tar.gz

tar zvxf subversion-1.3.2.tar.gz
cd subversion-1.3.2
./configure --with-apr=/usr/local/apr-httpd --with-apr-util=/usr/local/apr-util-httpd/
make
make install

到此,我们就可以通过svn命令获取最新的ffmpeg了

svn checkout svn://svn.mplayerhq.hu/ffmpeg/trunk ffmpeg

你会发现在你所在的目录,自动出现一个ffmpeg的目录,就是你下载的源代码。

我们还不能这么快编译ffmpeg,应该如果要让ffmpeg支持更多格式的转换,还需做一些前期工作

2.支持mp3,linux当然是lame,下载解压

cd lame-3.96.1
./configure --enable-shared --prefix=/usr
这里推荐尽量装在/usr下,默认是装在/usr/local下。这样ffmpeg编译都能顺利的找到库文件

3.支持Ogg Vorbis:
as4自带相应的rpm包,你可以安装一下如下rpm包
libvorbis, libvorbis-devel,libogg, libogg-devel

4.支持xvid x264,现在最流行的两种高质量的压缩格式
xvid的编译安装
wget
http://downloads.xvid.org/downloads/xvidcore-1.1.0.tar.gz

tar zvxf xvidcore-1.1.0.tar.gz
./configure --prefix=/usr
make
make install

x264的获取同样是采用svn方式,看来svn取代cvs不远了
svn co svn://svn.videolan.org/x264/trunk x264
cd x264
./configure --prefix=/usr --enable-shared
make
make install

5.AC3和dts编码的支持
as4系统似乎已经支持ac3编码,编译的时候只要加--enable-a52 --enable-gpl参数就行

libdts编译参数
./configure --prefix=/usr
make
make install

6.mpg4 aac格式支持,由于服务器还针对手机用户服务,所以,类似aac,mpg4铃声格式的支持,我们也得做。这里我们安装faad2和faac就行
下载请到http://www.audiocoding.com/modules/mydownloads/

FAAD2的编译
cd faad2
autoreconf -vif
./configure --prefix=/usr --with-mp4v2 --enable-shared
make
make install

faac的编译
cd faac
chmod +x bootstrap
./bootstrap
./configure --prefix=/usr --with-mp4v2 --enable-shared
make
make install

7.支持3gp格式,这也是现在好多手机支持的格式,因为手机用户是我们的主要用户,所以也得支持编译

编译的时候加上--enable-amr_nb --enable-amr_wb参数就行,根据编译系统的提示,所以我们得下载一

些编译3gp所需得文件。

wget
http://www.3gpp.org/ftp/Specs/ar ... 6.204/26204-510.zip

解压以后把里面的文件都拷贝到libavcodec/amrwb_float

wget
http://www.3gpp.org/ftp/Specs/ar ... 6.104/26104-510.zip

解压以后把里面的文件都拷贝到libavcodec/amr_float

好了,基本ffmpeg支持的格式,我们基本都做好前期准备了,下面是ffmpeg的编译

./configure --prefix=/usr --enable-gpl --enable-shared --enable-mp3lame --enable-amr_nb --enable-amr_wb --enable-amr_if2 --enable-libogg --enable-vorbis --enable-xvid --enable-a52 --enable-a52bin --enable-faadbin --enable-dts --enable-pp --enable-faad --enable-faac
--enable-x264 --enable-pthreads --disable-ffserver --disable-ffplay
make
make install

补充1:
关于3gp的编译,如果大家要编译--enable-amr_nb-fixed,那就不能跟--enable-amr_nb同时编译,我不大清楚这两者到底有什么区别,似乎fixed是修正版,管他呢,编译的方法:
wget
http://www.3gpp.org/ftp/Specs/ar ... 6.073/26073-510.zip

解压以后把里面的文件都拷贝到libavcodec/amr目录下

修改libavcodec/amr/makefile 找到CFLAGS = -Wall -pedantic-errors -I. $(CFLAGS_$(MODE)) -D$(VAD) 换成CFLAGS = -Wall -I. $(CFLAGS_$(MODE)) -D$(VAD) -DMMS_IO

整体编译参数就是
./configure --prefix=/usr --enable-gpl --enable-shared --enable-mp3lame --enable-amr_nb-fixed --enable-amr_wb --enable-amr_if2 --enable-libogg --enable-vorbis --enable-xvid --enable-a52 --enable-a52bin --enable-dts --enable-pp --enable-faad --enable-faadbin
--enable-faac --enable-x264 --enable-pthreads --disable-ffserver --disable-ffplay
make
make install

补充2:
有朋友说在当在cpu是x86的情况下,不能编译过去,我这里没发生过这情况,如果你真编译不过去,可以试着加上cpu=cpu

ok,一个强大的ffmpeg编译好了,不过目前管方的ffmpeg还不支持wma9和rmvb,不过网上有很多解决方法,大家去自己找找。

================================================

关于进度条的问题,我一直都无法解决.按道理新浪也不可能100%获取真实进度的吧?如果模拟的话就一大堆了,
我这里提供一UPU的类用的SOCKET协议.
[php]
<?php
/**
* UGiA PHP UPLOADER V0.2
*
* Copyright 2005 legend <legendsky@hotmail.com>
*
* This library is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation; either version 2.1 of the License, or (at
* your option) any later version.

* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.

* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
* USA.
*
* @link http://www.ugia.cn,http://sourceforge.net/projects/upu
* @copyright Copyright: 2004-2005 UGiA.CN.
* @author legend <legendsky@hotmail.com>
* @package UPU
* @version $Id: upu.class.php,v 1.2 2005/09/22 08:03:22 legend9 Exp $
*/

define('UPU_CLIENT_CHARSET', 'utf-8');
define('UPU_TEMP_PATH', '/upload/upu/temp/');
define('UPU_SAVE_PATH', '/upload/upu/files/');

define('UPU_SOCKET_ENDTAG', "/x2d/x2d/x0d/x0a");
define('UPU_CRLF', "/x0d/x0a");

define('UPU_SOCKET_CREATE_ERROR', "Socket创建失败");
define('UPU_SOCKET_BIND_ERROR', "端口绑定失败");
define('UPU_SOCKET_LISTEN_ERROR', "端口监听失败");
define('UPU_SOKET_ACCEPT_ERROR', "无法接受客户端请求");
define('UPU_CREATE_TEMP_FILE_ERROR', "创建临时文件失败");
define('UPU_FILE_TO_LARGE', "文件超过指定大小");
define('UPU_GET_TMP_FILE_SIZE_ERROR', "获取临时文件大小失败");
define('UPU_READ_TMP_FILE_ERROR', "打开临时文件失败");
define('UPU_WRITE_NEW_FILE_ERRPR', "创建新文件失败");

class UPU
{
var $sPort = 1024;
var $ePort = 65536;

var $savePath = UPU_SAVE_PATH;
var $tmpPath = UPU_TEMP_PATH;

var $allowExt = "*";
var $maxFileSize = 0;

var $srvPort;
var $ipAddr;
var $processID;
var $bufferSize = 1024;

var $Boundary;
var $ContentLength = 0;
var $fileSize = 0;
var $fileInfo = array();
var $formData = array();

var $errorCode = 0;

function UPU ()
{
$this->srvPort = mt_rand($this->sPort, $this->ePort);
$this->ipAddr = $_SERVER['SERVER_NAME'];
}

function processRequest()
{
$uSocket = socket_create(AF_INET, SOCK_STREAM, SOL_TCP);
if ($uSocket < 0) return -101;

$uBind = socket_bind($uSocket, $this->ipAddr, $this->srvPort);
if ($uBind < 0) return -102;

//socket_set_blocking($uSocket);

$uListen = socket_listen($uSocket, 5);
if ($uListen < 0) return -103;

$this->writeContents($this->tmpPath . $this->processID . ".srv", $this->ipAddr.":".$this->srvPort);

$uRequest = socket_accept($uSocket);
if ($uRequest < 0) return -104;

$httpResponse = "HTTP/1.1 200 OK/r/n";
$httpResponse .= "Content-Length: 2/r/n";
$httpResponse .= "Content-Type: text/html/r/n";
$httpResponse .= "Last-Modified: " . date("r") . "/r/n";
$httpResponse .= "Accept-Ranges: bytes/r/n";
$httpResponse .= "X-Powered-By: UPU/r/n";
$httpResponse .= "Date: " . date("r") . "/r/n/r/n";

socket_write($uRequest, $httpResponse);

$neededbuffer = true;
$BufferPond = array();

$tmpFileName = $this->tmpPath . $this->processID . ".dat";

if(!$fp = fopen ($tmpFileName, "wb")) return -105;

$dataRead = 0;
while ($flag = socket_recv($uRequest, $buffer, $this->bufferSize, 0))
{

fwrite($fp, $buffer);

// buffer pond
array_push ($BufferPond, $buffer);
if (count($BufferPond) == 3)
{
$dataRead += strlen($BufferPond[0]);
array_shift($BufferPond);
}

$Contents = join("", $BufferPond);

// boundary
if (!$this->Boundary)
{
if (preg_match("/Content-Type: multipart//form-data; boundary=[-]{27}(/S+)/i", $Contents, $matchesB))
$this->Boundary = $matchesB[1];
}

// content length
if (!$this->ContentLength)
{
if (preg_match("/Content-Length: (/d+)/r/n/i", $Contents, $matchesL))
{
$this->ContentLength = $matchesL[1];

$this->writeContents($this->tmpPath . $this->processID . ".con", $this->ContentLength);

if ($this->maxFileSize && $this->ContentLength > $$maxFileSize * 1024 * 1024)
{
return -106;
break;
}
}
}

// parse
$boundary = str_repeat("-", 29) . $this->Boundary;
if (strpos($Contents, $boundary))
{
preg_match_all("/$boundary/r/nContent-Disposition: form-data; name=/"([^/"]*)/"(; filename=/"([^/"]*)/"/r/nContent-Type: (/S+))?/r/n/i", $Contents, $matchesF, PREG_OFFSET_CAPTURE);

//print_r($matchesF);

if ($matchesF)
{
for ($i = 0; $i < count($matchesF[0]); $i ++)
{
$formIndex = $this->checkFormName($matchesF[1][$i][0], $this->formData);
if ( $formIndex === -1)
{
$this->formData[] = array (
'name' => $matchesF[1][$i][0],
'type' => $matchesF[3][$i] ? "file" : "form",
'filename' => $matchesF[3][$i][0],
'content-type' => $matchesF[4][$i][0],
'offset' => $dataRead + $matchesF[0][$i][1],
'full' => $matchesF[0][$i][0]
);

if ($matchesF[3][$i])
{
$clientArray = "new Array(/"" . $matchesF[1][$i][0] . "/",/"" . $this->getBaseName($matchesF[3][$i][0]) . "/",/"" . $matchesF[4][$i][0] . "/")";
$this->writeContents($this->tmpPath . $this->processID . ".inf", $clientArray);
}
}
}
}
else
{
break;
}
}

if ($flag < 0)
{
echo socket_strerror(socket_last_error($uSocket));
break;
}
elseif ($flag == 0)
{
echo "client disconnected";
break;
}

// end of request ?
$eof = substr($buffer, -4);
$las = substr($buffer, $this->bufferSize - 4, 4);
if ($eof == UPU_SOCKET_ENDTAG || (strlen($eof) < 4 && ($las{strlen($eof) -1} == "/x0a" || $las{strlen($eof) -1} == "/x00")))
{
break;
}

$loopTime ++;
}

fclose($fp);

$msg = "ok";
socket_write($uRequest, $msg, strlen($msg));
socket_close($uRequest);
socket_close($uSocket);

//print_r($this->fileInfo);
//print_r($this->formData);

// temp file size
if (!$this->fileSize = @filesize($tmpFileName))
{
return -108;
}

// temp file read handle
if (!$readHandle = fopen($tmpFileName, "rb"))
{
return -109;
}

foreach ($this->formData as $k => $v)
{
fseek($readHandle, $v['offset'] + strlen($v['full']) + 2);
$eOffset = $k + 1 == count($this->formData)? $this->fileSize - 35 - strlen($this->Boundary) : $this->formData[$k + 1]['offset'] - 2;
$this->formData[$k]['filesize'] = $eOffset - $v['offset'] - strlen($v['full']) - 2;

if ($v['type'] == "file")
{
$extension = $this->getExtension($v['filename']);
$savepath = $this->savePath . md5($this->processID . "-" . $k) . "." . $extension;
$writeHandle = fopen($savepath, "wb");
fwrite($writeHandle, @fread($readHandle,$this->formData[$k]['filesize']));
fclose($writeHandle);
$this->formData[$k]['ext'] = $extension;
$this->formData[$k]['path'] = $savepath;
}
else
{
$this->formData[$k]['value'] = @fread($readHandle, $this->formData[$k]['filesize']);
}
}

fclose($readHandle);

$form = array();
foreach ($this->formData as $k => $v)
{
if ($v['type'] == "file")
{
$form[$v['name']] = array(
'filename' => $this->getBaseName($v['filename']),
'extension' => $v['ext'],
'clientpath' => $v['filename'],
'savepath' => realpath($v['path']),
'filetype' => $v['content-type'],
'filesize' => $v['filesize'],
'extension' => $v['ext']
);
}
else
{
$form[$v['name']] = $v['value'];
}
}

$this->writeContents($this->tmpPath . $this->processID . ".frm", serialize($form));

sleep(60);
unlink($this->tmpPath . $this->processID . ".inf");
unlink($this->tmpPath . $this->processID . ".dat");
unlink($this->tmpPath . $this->processID . ".con");
unlink($this->tmpPath . $this->processID . ".srv");
}

// get socket server ip address and port
function getSrvAddr()
{
return $this->getContents($this->tmpPath . $this->processID . ".srv");
}

// get Content Length
function getContentLength()
{
return $this->getContents($this->tmpPath . $this->processID . ".con");
}

// get file info
function getFileInfo()
{
return $this->getContents($this->tmpPath . $this->processID . ".inf");
}
// get uploaded file length
function getUploadedLength()
{
if (file_exists($this->tmpPath . $this->processID . ".dat"))
{
return filesize($this->tmpPath . $this->processID . ".dat");
}

return 0;
}

function getFormData()
{
if (file_exists($this->tmpPath . $this->processID . ".frm"))
{
return $this->getContents($this->tmpPath . $this->processID . ".frm");
}

return 0;
}

function writeContents($filename, $contents)
{
$fwriteHandle = @fopen($filename, "w");
if (!is_resource($fwriteHandle))
{
return false;
}

fwrite($fwriteHandle, $contents);
fclose($fwriteHandle);

return true;
}

function getContents($filename)
{
if (file_exists($filename))
{
$freadHandle = @fopen($filename, "r");
if (!is_resource($freadHandle))
{
return false;
}

$contents = fread($freadHandle, filesize($filename));
fclose($freadHandle);

return $contents;
}

return false;
}

function getBaseName($path)
{
$path = str_replace("//", "/", $path);
return substr($path, strrpos($path, "/") + 1);
}

function getExtension($filename)
{
return substr(strrchr($filename, '.'), 1);
}

function checkFormName($formName, $arr)
{
foreach ($arr as $k => $v)
{
if ($formName == $v['name'])
{
return $k;
}
}

return -1;
}
}
?> 

抱歉!评论已关闭.