ffmpeg.exe死机 [英] ffmpeg.exe freezes

查看:89
本文介绍了ffmpeg.exe死机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Asp.Net C#Framework 4,目前正在开发视频转换应用程序.我还使用ffmpeg将所有上传的格式转换为flv.由于有时在尝试从mp4直接转换为flv时遇到的问题,我首先将上传的文件转换为mpg,然后转换为flv.但是ffmpeg在将过程转换为mpg文件后会立即冻结.当我运行任务管理器并检查进程列表时,它不使用任何CPU资源就站在那里.当我直接从任务管理器中结束ffmpeg进程时,将发生其他进程,该进程从mpg转换为flv并预览文件(jpg),并且运行平稳.由于第一过程的冻结,当我尝试从网页的文件上传表单上载时,第二过程无法启动.我感谢从现在开始的任何回应.这是我的代码:

I'm using Asp.Net C# Framework 4 and currently developing a video conversion application. I'm also using ffmpeg to convert from all uploaded formats to flv. I'm first converting uploaded file to mpg and after to flv due to problems I encountered while trying conversion directly to flv from mp4 sometimes. But ffmpeg freezes as soon as it's done with conversion process to mpg file. When I run task manager and check the processes list, it just stands there using no CPU resource. When I end the ffmpeg process directly from task manager, other process take place which converts from mpg to flv and preview file (jpg) and works smoothly. Due to freezing of first process, the second process cannot start when I try to upload from my web page's file upload form. I appreciate any response from now. Here is my code:

        string duration = "00:00:00";

        //converting video
        Process ffmpeg;
        ffmpeg = new Process();

        // convert to mpg 1st
        ffmpeg.StartInfo.Arguments = " -i \"" + Server.MapPath("static/user/vid/") + videolink + "\" -f mpeg -b 300k -ac 2 -ab 128k -ar 44K \"" + Server.MapPath("static/user/vid/") + mpglink + "\"";
        ffmpeg.StartInfo.FileName = Page.MapPath("bin/ffmpeg.exe");
        ffmpeg.StartInfo.CreateNoWindow = true;
        ffmpeg.StartInfo.UseShellExecute = false;
        ffmpeg.StartInfo.RedirectStandardOutput = true;
        ffmpeg.StartInfo.RedirectStandardError = true;
        ffmpeg.Start();

        ffmpeg.WaitForExit();
        ffmpeg.Close();


        // mpg 2 flv
        ffmpeg = new Process();
        ffmpeg.StartInfo.Arguments = " -i \"" + Server.MapPath("static/user/vid/") + mpglink + "\" -f flv -s 624x352 \"" + Server.MapPath("static/user/vid/") + flvlink + "\"";
        ffmpeg.StartInfo.FileName = Page.MapPath("bin/ffmpeg.exe");
        ffmpeg.StartInfo.CreateNoWindow = true;
        ffmpeg.StartInfo.UseShellExecute = false;
        ffmpeg.StartInfo.RedirectStandardOutput = true;
        ffmpeg.StartInfo.RedirectStandardError = true;
        ffmpeg.Start();

        ffmpeg.BeginOutputReadLine();
        string error = ffmpeg.StandardError.ReadToEnd();
        ffmpeg.WaitForExit();

        try
        {
            duration = error.Substring(error.IndexOf("Duration: ") + 10, 8);
        }
        catch
        {
        }

        if (ffmpeg.ExitCode != 0)
        {
            ltrUpload.Text = "<div class=\"resultbox-negative\" id=\"divResult\">Problem occured during upload process. Error code: " + error + "<br>" + "</div>";
            return;
        }
        ffmpeg.Close();


        // generate preview image
        ffmpeg.StartInfo.Arguments = " -i \"" + Server.MapPath("static/user/vid/") + flvlink + "\" -s 624x352 -ss 00:00:03 -an -vframes 1 -f image2 -vcodec mjpeg \"" + Server.MapPath("static/user/vid/") + flvlink.Replace(".flv", ".jpg") + "\"";
        ffmpeg.StartInfo.FileName = Page.MapPath("bin/ffmpeg.exe");
        ffmpeg.StartInfo.CreateNoWindow = true;
        ffmpeg.StartInfo.UseShellExecute = false;
        ffmpeg.StartInfo.RedirectStandardOutput = true;
        ffmpeg.StartInfo.RedirectStandardError = true;
        ffmpeg.Start();
        ffmpeg.WaitForExit();
        ffmpeg.Close();

        // deleting original file and mpg
        FileInfo fi = new FileInfo(Server.MapPath("static/user/vid/") + videolink);
        if (fi.Exists) fi.Delete();
        fi = new FileInfo(Server.MapPath("static/user/vid/") + mpglink);
        if (fi.Exists) fi.Delete();

推荐答案

我知道这是一个非常老的问题,但是如果有人因为Google搜索而来到这里,答案如下:

I know this is a very old question, but if someone gets here because of a Google search, the answer is the following:

即使您不需要,也必须阅读第一个ffmpeg进程的重定向错误输出.如果您不读取重定向的错误输出,则将导致死锁,因为您的程序将等待过程完成,但过程将等待读取已填充的错误输出流.您可以查找

You would have to read the redirected error output of the first ffmpeg process, too, even if you do not need it. It will result in a deadlock if you do not read the redirected error output because your program will wait for the process to finish, but the process waits for the filled error output stream to be read. You can look it up here.

    // convert to mpg 1st
    ffmpeg.StartInfo.Arguments = " -i \"" + Server.MapPath("static/user/vid/") + videolink + "\" -f mpeg -b 300k -ac 2 -ab 128k -ar 44K \"" + Server.MapPath("static/user/vid/") + mpglink + "\"";
    ffmpeg.StartInfo.FileName = Page.MapPath("bin/ffmpeg.exe");
    ffmpeg.StartInfo.CreateNoWindow = true;
    ffmpeg.StartInfo.UseShellExecute = false;
    ffmpeg.StartInfo.RedirectStandardOutput = true;
    ffmpeg.StartInfo.RedirectStandardError = true;
    ffmpeg.Start();

    // Use asynchronous read operations on at least one of the streams.
    // Reading both streams synchronously would generate another deadlock.
    ffmpeg.BeginOutputReadLine();
    string tmpErrorOut = ffmpeg.StandardError.ReadToEnd();

    ffmpeg.WaitForExit();
    ffmpeg.Close();

因此,您必须像第二个ffmpeg进程一样读取重定向的错误并输出流.

So you would have to read the redirected error and output streams like you did with your second ffmpeg process.

生成的图像预览部分也是如此!

这篇关于ffmpeg.exe死机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆