为phpcms写的一个视频上传格式转换_bat批处理方式

为phpcms写的ffmpeg转换视频,大家可以改造改造用到自己的项目中去,因为php执行exec函数不是很容易,权限不好设置,失败率高等缺点,决定用php写一个批处理文件,然后让windows计划任务定时执行.主要代码段就是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;
$bat = PHPCMS_ROOT."change.bat";
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;
		$fromFile = str_replace("/","\\",$fromFile);
		//$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";
		$image =  PHPCMS_ROOT.UPLOAD_URL.$filename1.".jpg";
		$flvWith = 320;	
		$flvHeight = 240;
set_time_limit(0);
$execshell = "$mpeg -i $fromFile -y -ab 28 -ar 22050 -b 200000 -r 24 -s $flvWith*$flvHeight $flvName";
$execshell .= "\n$mpeg -i $fromFile -ss 00:00:01 -t 00:00:02 -f image2 -vframes 10 $image";
		//exec("$mpeg -i $fromFile -y -ab 28 -ar 22050 -b 200000 -r 24 -s $flvWith*$flvHeight $flvName",$mStatus,$status);
		//add tuzwu
		$cmdshell = "\necho waiting……\n";
		$cmdshell .= "if NOT exist $flvName $execshell";
		$delshell = str_replace("/","\\",$fromFile);
		$cmdshell .= "\ndel $delshell";

		echo $filename.'|'.UPLOAD_URL.$filename1.".flv";
		echo '$'.UPLOAD_URL.$filename1.".jpg";
		file_put_contents($bat, $cmdshell, FILE_APPEND);
		 }
		else{
		exit($filename.'|'.$fileurl);
		}
	}
	else
	{
		if (isset($_FILES["Filedata"])) {
			echo $_FILES["Filedata"]["error"];
			exit;
		}
	}	
}
else 
{
	include template('phpcms','flash_upload');
}
?>


生成的bat文件内容大致如下,路径没问题的都是可以正确执行的.
echo waiting……
if NOT exist D:/apmserv/www/htdocs/whco-op/uploadfile/2009/0828/20090828052250502.flv D:/apmserv/www/htdocs/whco-op/FFmpeg/ffmpeg.exe -i D:\apmserv\www\htdocs\whco-op\uploadfile\2009\0828\20090828052250502.wmv -y -ab 28 -ar 22050 -b 200000 -r 24 -s 320*240 D:/apmserv/www/htdocs/whco-op/uploadfile/2009/0828/20090828052250502.flv
D:/apmserv/www/htdocs/whco-op/FFmpeg/ffmpeg.exe -i D:\apmserv\www\htdocs\whco-op\uploadfile\2009\0828\20090828052250502.wmv -ss 00:00:01 -t 00:00:02 -f image2 -vframes 10 D:/apmserv/www/htdocs/whco-op/uploadfile/2009/0828/20090828052250502.jpg
del D:\apmserv\www\htdocs\whco-op\uploadfile\2009\0828\20090828052250502.wmv
echo waiting……
if NOT exist D:/apmserv/www/htdocs/whco-op/uploadfile/2009/0828/20090828052411950.flv D:/apmserv/www/htdocs/whco-op/FFmpeg/ffmpeg.exe -i D:\apmserv\www\htdocs\whco-op\uploadfile\2009\0828\20090828052411950.wmv -y -ab 28 -ar 22050 -b 200000 -r 24 -s 320*240 D:/apmserv/www/htdocs/whco-op/uploadfile/2009/0828/20090828052411950.flv
D:/apmserv/www/htdocs/whco-op/FFmpeg/ffmpeg.exe -i D:\apmserv\www\htdocs\whco-op\uploadfile\2009\0828\20090828052411950.wmv -ss 00:00:01 -t 00:00:02 -f image2 -vframes 10 D:/apmserv/www/htdocs/whco-op/uploadfile/2009/0828/20090828052411950.jpg
del D:\apmserv\www\htdocs\whco-op\uploadfile\2009\0828\20090828052411950.wmv
echo waiting……
if NOT exist D:/apmserv/www/htdocs/whco-op/uploadfile/2009/0828/20090828052429304.flv D:/apmserv/www/htdocs/whco-op/FFmpeg/ffmpeg.exe -i D:\apmserv\www\htdocs\whco-op\uploadfile\2009\0828\20090828052429304.wmv -y -ab 28 -ar 22050 -b 200000 -r 24 -s 320*240 D:/apmserv/www/htdocs/whco-op/uploadfile/2009/0828/20090828052429304.flv
D:/apmserv/www/htdocs/whco-op/FFmpeg/ffmpeg.exe -i D:\apmserv\www\htdocs\whco-op\uploadfile\2009\0828\20090828052429304.wmv -ss 00:00:01 -t 00:00:02 -f image2 -vframes 10 D:/apmserv/www/htdocs/whco-op/uploadfile/2009/0828/20090828052429304.jpg
del D:\apmserv\www\htdocs\whco-op\uploadfile\2009\0828\20090828052429304.wmv
echo waiting……
if NOT exist D:/apmserv/www/htdocs/whco-op/uploadfile/2009/0828/20090828052520539.flv D:/apmserv/www/htdocs/whco-op/FFmpeg/ffmpeg.exe -i D:\apmserv\www\htdocs\whco-op\uploadfile\2009\0828\20090828052520539.wmv -y -ab 28 -ar 22050 -b 200000 -r 24 -s 320*240 D:/apmserv/www/htdocs/whco-op/uploadfile/2009/0828/20090828052520539.flv
D:/apmserv/www/htdocs/whco-op/FFmpeg/ffmpeg.exe -i D:\apmserv\www\htdocs\whco-op\uploadfile\2009\0828\20090828052520539.wmv -ss 00:00:01 -t 00:00:02 -f image2 -vframes 10 D:/apmserv/www/htdocs/whco-op/uploadfile/2009/0828/20090828052520539.jpg
del D:\apmserv\www\htdocs\whco-op\uploadfile\2009\0828\20090828052520539.wmv
echo waiting……
if NOT exist D:/apmserv/www/htdocs/whco-op/uploadfile/2009/0828/20090828052612619.flv D:/apmserv/www/htdocs/whco-op/FFmpeg/ffmpeg.exe -i D:\apmserv\www\htdocs\whco-op\uploadfile\2009\0828\20090828052612619.wmv -y -ab 28 -ar 22050 -b 200000 -r 24 -s 320*240 D:/apmserv/www/htdocs/whco-op/uploadfile/2009/0828/20090828052612619.flv
D:/apmserv/www/htdocs/whco-op/FFmpeg/ffmpeg.exe -i D:\apmserv\www\htdocs\whco-op\uploadfile\2009\0828\20090828052612619.wmv -ss 00:00:01 -t 00:00:02 -f image2 -vframes 10 D:/apmserv/www/htdocs/whco-op/uploadfile/2009/0828/20090828052612619.jpg
del D:\apmserv\www\htdocs\whco-op\uploadfile\2009\0828\20090828052612619.wmv
echo waiting……
if NOT exist D:/apmserv/www/htdocs/whco-op/uploadfile/2009/0828/20090828052936684.flv D:/apmserv/www/htdocs/whco-op/FFmpeg/ffmpeg.exe -i D:\apmserv\www\htdocs\whco-op\uploadfile\2009\0828\20090828052936684.wmv -y -ab 28 -ar 22050 -b 200000 -r 24 -s 320*240 D:/apmserv/www/htdocs/whco-op/uploadfile/2009/0828/20090828052936684.flv
D:/apmserv/www/htdocs/whco-op/FFmpeg/ffmpeg.exe -i D:\apmserv\www\htdocs\whco-op\uploadfile\2009\0828\20090828052936684.wmv -ss 00:00:01 -t 00:00:02 -f image2 -vframes 10 D:/apmserv/www/htdocs/whco-op/uploadfile/2009/0828/20090828052936684.jpg
del D:\apmserv\www\htdocs\whco-op\uploadfile\2009\0828\20090828052936684.wmv
echo waiting……
if NOT exist D:/apmserv/www/htdocs/whco-op/uploadfile/2009/0828/20090828053044674.flv D:/apmserv/www/htdocs/whco-op/FFmpeg/ffmpeg.exe -i D:\apmserv\www\htdocs\whco-op\uploadfile\2009\0828\20090828053044674.wmv -y -ab 28 -ar 22050 -b 200000 -r 24 -s 320*240 D:/apmserv/www/htdocs/whco-op/uploadfile/2009/0828/20090828053044674.flv
D:/apmserv/www/htdocs/whco-op/FFmpeg/ffmpeg.exe -i D:\apmserv\www\htdocs\whco-op\uploadfile\2009\0828\20090828053044674.wmv -ss 00:00:01 -t 00:00:02 -f image2 -vframes 10 D:/apmserv/www/htdocs/whco-op/uploadfile/2009/0828/20090828053044674.jpg
del D:\apmserv\www\htdocs\whco-op\uploadfile\2009\0828\20090828053044674.wmv
echo waiting……
if NOT exist D:/apmserv/www/htdocs/whco-op/uploadfile/2009/0828/20090828053121852.flv D:/apmserv/www/htdocs/whco-op/FFmpeg/ffmpeg.exe -i D:\apmserv\www\htdocs\whco-op\uploadfile\2009\0828\20090828053121852.wmv -y -ab 28 -ar 22050 -b 200000 -r 24 -s 320*240 D:/apmserv/www/htdocs/whco-op/uploadfile/2009/0828/20090828053121852.flv
D:/apmserv/www/htdocs/whco-op/FFmpeg/ffmpeg.exe -i D:\apmserv\www\htdocs\whco-op\uploadfile\2009\0828\20090828053121852.wmv -ss 00:00:01 -t 00:00:02 -f image2 -vframes 10 D:/apmserv/www/htdocs/whco-op/uploadfile/2009/0828/20090828053121852.jpg
del D:\apmserv\www\htdocs\whco-op\uploadfile\2009\0828\20090828053121852.wmv
echo waiting……
if NOT exist D:/apmserv/www/htdocs/whco-op/uploadfile/2009/0828/20090828053241237.flv D:/apmserv/www/htdocs/whco-op/FFmpeg/ffmpeg.exe -i D:\apmserv\www\htdocs\whco-op\uploadfile\2009\0828\20090828053241237.wmv -y -ab 28 -ar 22050 -b 200000 -r 24 -s 320*240 D:/apmserv/www/htdocs/whco-op/uploadfile/2009/0828/20090828053241237.flv
D:/apmserv/www/htdocs/whco-op/FFmpeg/ffmpeg.exe -i D:\apmserv\www\htdocs\whco-op\uploadfile\2009\0828\20090828053241237.wmv -ss 00:00:01 -t 00:00:02 -f image2 -vframes 10 D:/apmserv/www/htdocs/whco-op/uploadfile/2009/0828/20090828053241237.jpg
del D:\apmserv\www\htdocs\whco-op\uploadfile\2009\0828\20090828053241237.wmv
echo waiting……
if NOT exist D:/apmserv/www/htdocs/whco-op/uploadfile/2009/0828/20090828053308696.flv D:/apmserv/www/htdocs/whco-op/FFmpeg/ffmpeg.exe -i D:\apmserv\www\htdocs\whco-op\uploadfile\2009\0828\20090828053308696.wmv -y -ab 28 -ar 22050 -b 200000 -r 24 -s 320*240 D:/apmserv/www/htdocs/whco-op/uploadfile/2009/0828/20090828053308696.flv
D:/apmserv/www/htdocs/whco-op/FFmpeg/ffmpeg.exe -i D:\apmserv\www\htdocs\whco-op\uploadfile\2009\0828\20090828053308696.wmv -ss 00:00:01 -t 00:00:02 -f image2 -vframes 10 D:/apmserv/www/htdocs/whco-op/uploadfile/2009/0828/20090828053308696.jpg
del D:\apmserv\www\htdocs\whco-op\uploadfile\2009\0828\20090828053308696.wmv
echo waiting……
if NOT exist D:/apmserv/www/htdocs/whco-op/uploadfile/2009/0828/20090828053323525.flv D:/apmserv/www/htdocs/whco-op/FFmpeg/ffmpeg.exe -i D:\apmserv\www\htdocs\whco-op\uploadfile\2009\0828\20090828053323525.wmv -y -ab 28 -ar 22050 -b 200000 -r 24 -s 320*240 D:/apmserv/www/htdocs/whco-op/uploadfile/2009/0828/20090828053323525.flv
D:/apmserv/www/htdocs/whco-op/FFmpeg/ffmpeg.exe -i D:\apmserv\www\htdocs\whco-op\uploadfile\2009\0828\20090828053323525.wmv -ss 00:00:01 -t 00:00:02 -f image2 -vframes 10 D:/apmserv/www/htdocs/whco-op/uploadfile/2009/0828/20090828053323525.jpg
del D:\apmserv\www\htdocs\whco-op\uploadfile\2009\0828\20090828053323525.wmv
echo waiting……
if NOT exist D:/apmserv/www/htdocs/whco-op/uploadfile/2009/0828/20090828053436877.flv D:/apmserv/www/htdocs/whco-op/FFmpeg/ffmpeg.exe -i D:\apmserv\www\htdocs\whco-op\uploadfile\2009\0828\20090828053436877.wmv -y -ab 28 -ar 22050 -b 200000 -r 24 -s 320*240 D:/apmserv/www/htdocs/whco-op/uploadfile/2009/0828/20090828053436877.flv
D:/apmserv/www/htdocs/whco-op/FFmpeg/ffmpeg.exe -i D:\apmserv\www\htdocs\whco-op\uploadfile\2009\0828\20090828053436877.wmv -ss 00:00:01 -t 00:00:02 -f image2 -vframes 10 D:/apmserv/www/htdocs/whco-op/uploadfile/2009/0828/20090828053436877.jpg
del D:\apmserv\www\htdocs\whco-op\uploadfile\2009\0828\20090828053436877.wmv
echo waiting……
if NOT exist G:/apmserv/www/htdocs/whco-op/uploadfile/2009/1024/20091024113321683.flv G:/apmserv/www/htdocs/whco-op/FFmpeg/ffmpeg.exe -i G:\apmserv\www\htdocs\whco-op\uploadfile\2009\1024\20091024113321683.rm -y -ab 28 -ar 22050 -b 200000 -r 24 -s 320*240 G:/apmserv/www/htdocs/whco-op/uploadfile/2009/1024/20091024113321683.flv
G:/apmserv/www/htdocs/whco-op/FFmpeg/ffmpeg.exe -i G:\apmserv\www\htdocs\whco-op\uploadfile\2009\1024\20091024113321683.rm -ss 00:00:01 -t 00:00:02 -f image2 -vframes 10 G:/apmserv/www/htdocs/whco-op/uploadfile/2009/1024/20091024113321683.jpg
del G:\apmserv\www\htdocs\whco-op\uploadfile\2009\1024\20091024113321683.rm

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