zoukankan      html  css  js  c++  java
  • c#中调用Ffmpeg转换视频格式的问题

    我的目的是调用ffmpeg转化.avs文件为.flv文件,参数这些是没有问题的,我在命令行里面运行可以成功转换视频格式. 现在我把它写成一个函数在程序里面调用,就出问题了:(

    public int ConvertVideoToFLV()
    {
    int re = 999;

    Process p = new Process();//建立外部调用线程
    p.StartInfo.FileName = @"f:\flv\ffmpeg.rev10464\ffmpeg.exe";//调用外部程序的绝对路径
    p.StartInfo.Arguments = "-y -i sss.avs -ab 56 -b 500k programout.flv";//参数(FFMPEG参数)
    p.StartInfo.UseShellExecute = false;//不使用操作系统外壳程序启动线程

    p.StartInfo.RedirectStandardInput = true;
    p.StartInfo.RedirectStandardOutput = true;

    p.StartInfo.RedirectStandardError = true;//把外部程序错误输出写到StandardError流中

    p.StartInfo.CreateNoWindow = false;//不创建进程窗口
    p.ErrorDataReceived = new DataReceivedEventHandler(Output);//FFMPEG输出流时候把流的处理过程转移到Output
    p.Start();//启动线程
    p.BeginErrorReadLine();//开始异步读取

    p.WaitForExit();//阻塞等待进程结束
    p.Close();//关闭进程
    p.Dispose();//释放资源

    return re;
    }

    调试以后发现程序运行很正常,但就是不进行实际的转换. 我对进程使用也不是很熟悉, 请高人指点一下哪里出了问题!
    网友回复:你没有使用操作系统外壳程序启动,我想是这样的,你设置成使用操作系统外壳程序启动程序
    可能是转换过程需要视频解码之类什么的!!
    网友回复:帮LZ顶
    网友回复:“/”应用程序中的服务器错误。
    要重定向 IO 流,Process 对象必须将 UseShellExecute 属性设置为 False。


    说明: 执行当前 Web 请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的具体信息。

    异常具体信息: System.InvalidOperationException: 要重定向 IO 流,Process 对象必须将 UseShellExecute 属性设置为 False。

    设置成true以后会报错成这样...
    网友回复:我查看了进程,发现函数调用的时候ffmpeg.exe进程已经运行,但是cpu显示为0,根本没有执行转换. 高手看看是什么原因引起的,多谢!
    网友回复:解决了. 是需要设置一个工作目录~ 结贴
    网友回复:public static string VideoConvertFlv(string FromName, string WidthAndHeight, string ExportName)
    {

    string ffmpeg = HttpContext.Current.Server.MapPath("~/FLV/ffmpeg.exe");
    string Command =" -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 = ffmpeg;
    p.StartInfo.Arguments = Command;
    p.StartInfo.WorkingDirectory = HttpContext.Current.Server.MapPath("~/FLV/");
    p.StartInfo.UseShellExecute = false;
    p.StartInfo.RedirectStandardInput = true;
    p.StartInfo.RedirectStandardOutput = true;
    p.StartInfo.RedirectStandardError = true;
    p.StartInfo.CreateNoWindow = false;
    //开始执行
    p.Start();
    p.BeginErrorReadLine();
    p.WaitForExit();
    p.Close();
    p.Dispose();
    //p.StandardInput.WriteLine(Command);
    //p.StandardInput.WriteLine("Exit ");
    return ExportName;
    }

    protected void Button1_Click(object sender, EventArgs e)
    {

    strFile = HttpContext.Current.Server.MapPath("~/FLV/祝福劲牌(大碟版).mpg"); ;
    VideoConvertFlv(strFile, "480*360", "zh.flv");
    VideoConvertImg(strFile, "480*360", "zh.jpg");
    }

    http://hi.baidu.com/honfei/blog/item/d636cf4eabf0000cb2de0574.html

  • 相关阅读:
    深入浅出HTTP请求(转自http://www.cnblogs.com/yin-jingyu/archive/2011/08/01/2123548.html)
    IOS定位
    webView(简单的浏览器)
    Get&Post登录
    IOS多媒体
    IOS VFL屏幕自适应
    IOS中在自定义控件(非视图控制器)的视图跳转中 代理方法与代码块的比较
    单例设计的定义
    动画
    多线程
  • 原文地址:https://www.cnblogs.com/wangpei/p/1350214.html
Copyright © 2011-2022 走看看