给你看看我用的private void GenerateBatFile(string batfileaddress, string extname,bool genmetadata,string source_file,string dest_file,string filename_prefix)
{
FileStream fs = File.Create(batfileaddress);
fs.Flush();
fs.Close();
StreamWriter sw = new StreamWriter(batfileaddress, true); StringBuilder sb = new StringBuilder(); switch (extname)
{
case ".rm":
case ".rmvb":
sb.Append(ConfigurationManager.AppSettings["WisMencoderPath"].ToString());
sb.Append("mencoder.exe");
sb.Append(" -vf scale=320:240 -ffourcc FLV1 -of lavf -lavfopts i_certify_that_my_video_stream_does_not_use_b_frames -ovc lavc -lavcopts vcodec=flv:vbitrate=200 -srate 22050 -oac lavc -lavcopts acodec=mp3:abitrate=56 " + source_file + " -o " + dest_file); break;
default:
sb.Append( ConfigurationManager.AppSettings["FFMpegPath"].ToString());
sb.Append ("ffmpeg.exe");
sb.Append(" -i " + source_file + " -ab 56 -ar 22050 -b 500 -r 15 -s 320x240 " + dest_file);
break;
} sw.Write(sb.ToString());
sw.WriteLine("");
sb.Remove(0,sb.Length); if (genmetadata)
{
sb.Append(ConfigurationManager.AppSettings["FlvMdiPath"].ToString());
sb.Append("FlvMdi.exe");
sb.Append(" "+dest_file + " " + dest_file);
sw.Write(sb.ToString());
sw.WriteLine("");
sb.Remove(0,sb.Length);
} sb.Append(ConfigurationManager.AppSettings["FFMpegPath"].ToString());
sb.Append("FFMpeg.exe");
sb.Append(" -i " + dest_file + " -t 0.1 -s 256x192 -ss 00:00:" + ConfigurationManager.AppSettings["CutTime"].ToString() + " -y -f mjpeg " + Server.MapPath(ConfigurationManager.AppSettings["PicPath"].ToString()) + "\\" + filename_prefix + ".jpg");
sw.Write(sb.ToString());
sw.Flush();
sw.Close(); }先生成一个bat文件,
然后再Process.Start(Server.MapPath(FilePath) + newbatfilename);
{
FileStream fs = File.Create(batfileaddress);
fs.Flush();
fs.Close();
StreamWriter sw = new StreamWriter(batfileaddress, true); StringBuilder sb = new StringBuilder(); switch (extname)
{
case ".rm":
case ".rmvb":
sb.Append(ConfigurationManager.AppSettings["WisMencoderPath"].ToString());
sb.Append("mencoder.exe");
sb.Append(" -vf scale=320:240 -ffourcc FLV1 -of lavf -lavfopts i_certify_that_my_video_stream_does_not_use_b_frames -ovc lavc -lavcopts vcodec=flv:vbitrate=200 -srate 22050 -oac lavc -lavcopts acodec=mp3:abitrate=56 " + source_file + " -o " + dest_file); break;
default:
sb.Append( ConfigurationManager.AppSettings["FFMpegPath"].ToString());
sb.Append ("ffmpeg.exe");
sb.Append(" -i " + source_file + " -ab 56 -ar 22050 -b 500 -r 15 -s 320x240 " + dest_file);
break;
} sw.Write(sb.ToString());
sw.WriteLine("");
sb.Remove(0,sb.Length); if (genmetadata)
{
sb.Append(ConfigurationManager.AppSettings["FlvMdiPath"].ToString());
sb.Append("FlvMdi.exe");
sb.Append(" "+dest_file + " " + dest_file);
sw.Write(sb.ToString());
sw.WriteLine("");
sb.Remove(0,sb.Length);
} sb.Append(ConfigurationManager.AppSettings["FFMpegPath"].ToString());
sb.Append("FFMpeg.exe");
sb.Append(" -i " + dest_file + " -t 0.1 -s 256x192 -ss 00:00:" + ConfigurationManager.AppSettings["CutTime"].ToString() + " -y -f mjpeg " + Server.MapPath(ConfigurationManager.AppSettings["PicPath"].ToString()) + "\\" + filename_prefix + ".jpg");
sw.Write(sb.ToString());
sw.Flush();
sw.Close(); }先生成一个bat文件,
然后再Process.Start(Server.MapPath(FilePath) + newbatfilename);
解决方案 »
- 用户控件传值的问题
- 用户登录后online字段记录在线 退出后修改状态为离线 如何解决非正常退出和断电问题
- 重复提问:页面中就一个TextBox和Button控件,在TextBox里按回车竟然不可以直接想响Button的OnClick事件
- 动态循环 textbox 取值 然后进行批量插入工作
- 点击子表格的某一行如何知道是父表格的第几行?
- 【问一个关于DropDownList的问题】~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~``UP有分
- 我写了一个 ProsceniumBasPage 类继承 System.Web.UI.Page 然后页面类再继承这个 ProsceniumBasPage 类.但在这个类里面却不能用Session.
- 100分高分求CSS文件中用url()计算的相对路径问题!
- 关于得到DataGrid中Header和FooterTemplate中的控件值的问题
- 如何关闭模态窗口
- 分离程序代码和网页内容
- MVC,JS调用一个Action,Action里有转到其他视图的操作,转不了
public class Cmd
{
private string FileRoot; private string ExeFileName; private string ExeCommand; //private bool _IsSuccessful; private Process p; /// <summary>
/// CMD执行命令
/// </summary>
/// <returns>返回执行后的结果</returns>
public string Execute()
{
string argm=FileRoot+ExeFileName+ExeCommand;
string output;
//开始创建文件
p = new Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
try
{
//p.StandardInput.WriteLine(argm);
//p.StandardInput.WriteLine("exit");
p.StartInfo.Arguments=argm;
p.Start();
p.StandardInput.AutoFlush=true;
p.StandardInput.WriteLine(argm);
p.StandardInput.WriteLine("exit");
output=p.StandardOutput.ReadToEnd();
p.WaitForExit();
p.StandardInput.Flush();
p.StandardOutput.Close();
p.Close();
p.Dispose();
return output;
}
catch (Exception ex)
{ return ex.Message;
}
} /// <summary>
/// 要执行的文件所在的路径
/// </summary>
public string FILEROOT
{
set
{
FileRoot=value;
}
get
{
return FileRoot;
}
}
/// <summary>
/// 要执行的文件的文件名
/// </summary>
public string FILENAME
{
set
{
ExeFileName=value;
}
get
{
return ExeFileName;
}
} /// <summary>
/// 要执行的命令
/// </summary>
public string COMMAND
{
set
{
ExeCommand=value;
}
get
{
return ExeCommand;
}
}
}Cmd be = new Cmd();
be.FILEROOT = ConfigurationManager.AppSettings["FFMpegPath"].ToString(); ;
be.FILENAME = @"ffmpeg.exe";
be.COMMAND = @" -i " + tmpFilePath + FileName.Value.ToString() + ".flv -t 0.1 -s 256x192 -ss 00:00:" + ConfigurationManager.AppSettings["CutTime"].ToString() + " -y -f mjpeg " + Server.MapPath(ConfigurationManager.AppSettings["PicPath"].ToString()) + "\\" + FileName.Value.ToString() + ".jpg";
be.Execute();
可是没有反应。。
然后测试时就把。p.StartInfo.CreateNoWindow = true; true改成了false;
照理应该会把DOS命令窗口打开。。
可是我机子根本没有打开。。
请问这是什么原因啊
我搞定啦``
以下是我测试成功的代码哦``using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;/// <summary>
/// ConvertVideo 的摘要说明
/// </summary>
public class ConvertVideo
{
public ConvertVideo()
{
//
// TODO: 在此处添加构造函数逻辑
//
}
/**/
/// <summary>
/// 视频(avi,mov等等格式)转换为flv格式视频
/// </summary>
/// <param name="FromName">被转换的视频文件</param>
/// <param name="ExportName">转换flv后的文件名</param>
/// <param name="ExportName">视频大小的尺寸</param>
/// <returns></returns>
//其中System.Configuration.ConfigurationSettings.AppSettings["ffmpeg"]是存放ffmpeg.exe的路径
//bs.GetVideoFilePath() 是工作目录。比如你想把生成的文件放在E:\VideoDemo 就这样
public static string VideoConvertFlv(string FromName, string WidthAndHeight, string ExportName)
{
Base bs = new Base();
string ffmpeg = System.Configuration.ConfigurationSettings.AppSettings["ffmpeg"];
string Command = ffmpeg + " -i " + FromName + " -y -ab 56 -ar 22050 -b 500 -r 15 -s " + WidthAndHeight + " " + ExportName; ////Flv格式
//string Command = "E:\\FFmpeg\\ffmpeg.exe -i E:\\ClibDemo\\VideoPath\\admin\\a.wmv -y -ab 56 -ar 22050 -b 500 -r 15 -s 320*240 "+ ExportName;
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.WorkingDirectory = HttpContext.Current.Server.MapPath(bs.GetVideoFilePath());
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = false;
//开始执行
p.Start();
p.StandardInput.WriteLine(Command);
p.StandardInput.WriteLine("Exit") ;
return ExportName;
}
public static string VideoConvertImg(string FromName, string WidthAndHeight, string ExportName)
{
Base bs = new Base();
string ffmpeg = System.Configuration.ConfigurationSettings.AppSettings["ffmpeg"];
string Command = ffmpeg + " -i " + FromName + " -y -f image2 -t 0.001 -s " + WidthAndHeight + " " + ExportName; //获取静态图
//string Command = "E:\\FFmpeg\\ffmpeg.exe -i E:\\ClibDemo\\VideoPath\\admin\\a.wmv -y -f image2 -t 0.001 -s 300*200 " + ExportName;
System.Diagnostics.Process p = new System.Diagnostics.Process();
p.StartInfo.FileName = "cmd.exe";
p.StartInfo.WorkingDirectory = HttpContext.Current.Server.MapPath(bs.GetVideoImagePath());
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = false;
//开始执行
p.Start();
p.StandardInput.WriteLine(Command);
p.StandardInput.WriteLine("Exit");
return ExportName;
}
}
ConvertVideo.VideoConvertFlv("上传文件路径", "300*200", "Test.flv");
因为视频处理以后会有一系列的动作要执行的。
多谢
要不你发到我邮箱里也行。。
发到这里也行。。
[email protected]
谢啦
为什么用这个,是打算等待4秒后开始吗?是命令行还是应用程序项目?
可能是MAIN的主程序进程已结束,方法没进行完就被KILL掉了。
是否需要AutoResetEvent 类来让主进程在关闭前等待方法的完成?
我提个醒吧。我也看不出来。