在线视频转换的问题

客户端代码:

<?
error_reporting(E_ALL);
set_time_limit(0);
ob_implicit_flush();
$server = "211.94.190.86";
echo date("Y-m-d H:i:s")." Init ftp connection, server is $server.\n";
$ftp = ftp_connect($server);
ftp_login($ftp,"viosevent ","event.vios.com");
ftp_chdir($ftp,"/uploadfile/movie/in/");
//fetch
$lst = ftp_nlist($ftp,".");
foreach ($lst as $f){
if(strtolower(substr($f,strlen($f)-5,5))==".flag"){
$f = str_ireplace(".flag","",$f);
echo date("Y-m-d H:i:s")." New file discovered: ./in/$f.\n";
ftp_get($ftp,".\\in\\".$f,"./".$f,FTP_BINARY);
echo date("Y-m-d H:i:s")." Placing FLAG file:.\\in\\$f.flag.\n";
file_put_contents(".\\in\\$f.flag"," ");
echo date("Y-m-d H:i:s")." Removing the remote flag file. .\\in\\".$f.".flag...\n";
ftp_delete($ftp,"./".$f.".flag");
ftp_delete($ftp,"./".$f."");
}

ftp_raw($ftp,"noop");
}
//send
$workdir = dir(".\\out\\");
$entrys = array();
while (false !== ($entry = $workdir->read())) {
$entrys[]=$entry;
}
$workdir->close();
foreach ($entrys as $entry){
switch ($entry){
case ".":
case "..":
break;
default:
// echo $entry;
$pinfo = pathinfo($entry);
if(isset($pinfo['extension']) and $pinfo['extension']=="flv"){
echo date("Y-m-d H:i:s")." Sending .\\out\\{$pinfo["basename"]}...";
@ftp_put($ftp,"/uploadfile/movie/out/{$pinfo["basename"]}",".\\out\\{$pinfo["basename"]}",FTP_BINARY);
echo date("Y-m-d H:i:s")." Removeing .\\out\\{$pinfo["basename"]}...";
unlink(".\\out\\{$pinfo["basename"]}");
}
break;
}
ftp_raw($ftp,"noop");
}

ftp_close($ftp);
echo date("Y-m-d H:i:s")." Job finished, closing...";
?>

服务器端代码:
<?
error_reporting(E_ALL);
set_time_limit(0);
ob_implicit_flush();

$path_src = ".\\in\\";
$path_dest = ".\\out\\";
$path_tmp = ".\\tmp\\";
/*
$default_video = array(
"filename"=>"file.avi",
"ext"=>"avi",
"width"=>"320",
"height"=>"240",
""=>"",
""=>"",
""=>"",
""=>"",
""=>"",
""=>"",
""=>"",
);
*/
if(file_exists("flvsrv.cfg.php")){
include("flvsrv.cfg.php");
}

while (true) {

$workdir = dir($path_src);
while (false !== ($entry = $workdir->read())) {
switch ($entry){
case ".":
case "..":
break;
default:
$pinfo = pathinfo($path_src.$entry);
if($pinfo['extension']=="flag"){
$fn = str_replace(".flag","",$entry);
$destfn = substr($fn,0,strripos($fn,"."));
//$video_file = unserialize(file_get_contents($path_src.$entry));
echo date("Y-m-d H:i:s")." .\\me\\mencoder {$path_src}{$fn} -o {$path_tmp}{$destfn}.flv -of lavf -oac mp3lame -lameopts abr:br=56 -srate 22050 -ovc lavc -lavcopts vcodec=flv:vbitrate=500:mbd=2:mv0:trell:v4mv:cbp:last_pred=3  -lavfopts i_certify_that_my_video_stream_does_not_use_b_frames";
exec(".\\me\\mencoder {$path_src}{$fn} -o {$path_tmp}{$destfn}.flv -of lavf -oac mp3lame -lameopts abr:br=56 -srate 22050 -ovc lavc -lavcopts vcodec=flv:vbitrate=500:mbd=2:mv0:trell:v4mv:cbp:last_pred=3  -lavfopts i_certify_that_my_video_stream_does_not_use_b_frames");
echo date("Y-m-d H:i:s")." Deleting $path_src$entry...";
echo date("Y-m-d H:i:s")." Deleting $path_src$fn...";
unlink($path_src.$entry);
unlink($path_src.$fn);
echo date("Y-m-d H:i:s")." Moving {$path_tmp}{$destfn}.flv to {$path_dest}{$destfn}.flv...";
rename("{$path_tmp}{$destfn}.flv","{$path_dest}{$destfn}.flv");
break;
}
break;
}
}
$workdir->close();

}
?>

说明:
1. 客户端登陆至FTP服务器以后,将当前的目录切换为指定的目录;
2. 客户端在FTP下载目录中寻找.flag形式的文件,删除文件末尾的.flag后缀。然后从FTP上下载视频文件(比如名字为a.avi),并且写一空文件到目录中,名字为(a.avi.flag)。
3. 如果客户端在下载目录中寻找到以.flv后缀的文件,则直接上传到服务器端去。并清空上传目录。
4. 同时在server端也有一个进程在监视这个上传目录,当发现名字后缀位.flag的文件时(比如a.avi.flag),会去找a.avi这个文件,并且调用开源的mplayer 中的 mencode 转换格式将a.avi转换成a.flv,然后传到server上面。
5. Mencode的参数很复杂,详情请看mplayer手册。

你可能感兴趣的:(PHP,ext,F#)