嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):813200300
本次赞助数额为: 1 元微信扫码支付:1 元
请留下您的邮箱,我们将在2小时内将文件发到您的邮箱
这个是一windows服务程序,可以通过配置指定的视频文件夹转换flv的视频为MP4格式。
此服务调用ffmpeg.exe应用程序进行视频转换
string ffmpeg = Transfrom.ffmpegtool;
string path = System.IO.Directory.GetCurrentDirectory();//Environment.CurrentDirectory
if (string.IsNullOrEmpty(ffmpeg))
{
ffmpeg = path ffmpeg;
}
else
{
//ffmpeg = ffmpeg "\\ffmpeg\\ffmpeg.exe";
}
FileLog.Error("文件路径:" ffmpeg);
//判断转换工具,转换文件是否存在
if ((!System.IO.File.Exists(ffmpeg)) || (!System.IO.File.Exists(fileName)))
{
//Log.Info("ffmpeg.exe或转换文件不存在!");
return "false";
}
//获得(.flv)文件
string flv_file = System.IO.Path.ChangeExtension(playFile, extenName);
Process p = new Process();//建立外部调用线程
try
{
//执行文件转换
p.StartInfo.FileName = ffmpeg;//要调用外部程序的绝对路径
p.StartInfo.Arguments = @"-y -i " fileName " -acodec libfaac -ab 64k -vcodec libx264 -threads 0 -coder 1 -flags loop -cmp chroma -partitions parti8x8 parti4x4 partp8x8 partb8x8 -me_method umh -subq 8 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -qcomp 0.6 -qmin 10 -qmax 51 -qdiff 4 -directpred 3 -trellis 1 -flags2 bpyramid mixed_refs wpred dct8x8 fastpskip -wpredp 2 -rc_lookahead 50 -refs 6 -bf 5 -b_strategy 2 -crf 22 " "" " -s 640x" 360 " " flv_file;
// " -i " fileName " -ab 56 -ar 22050 -b 500 -r 15 -s " widthSize "x" heightSize " " flv_file; //" -i " fileName " -ar 22050 " flv_file;//参数(这里就是FFMPEG的参数了)
p.StartInfo.UseShellExecute = false;//不使用操作系统外壳程序启动线程(一定为FALSE,详细的请看MSDN)
p.StartInfo.RedirectStandardError = true;//把外部程序错误输出写到StandardError流中(这个一定要注意,FFMPEG的所有输出信息,都为错误输出流,用StandardOutput是捕获不到任何消息的...这是我耗费了2个多月得出来的经验...mencoder就是用standardOutput来捕获的)
//p.StartInfo.CreateNoWindow = false;//不创建进程窗口
p.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.Start();//启动线程
//p.WaitForExit();//等待完成
p.StandardError.ReadToEnd();//开始同步读取
}
catch (Exception e)
{
//Log.Info("视频转码出错 Error={0}", e.ToString());
return "false";
}
finally
{
p.Close();//关闭进程
p.Dispose();//释放资源
}