在asp.net中使用ffmpeg [英] Using ffmpeg in asp.net

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

问题描述

我需要一个音频转换库。在已经拉我的头发之后,我已经放弃了这样一个事实,那里没有这样的音频库。每个图书馆都有一些或另一个问题。



剩下的唯一选项是ffmpeg这是最好的,但不幸的是你不能在asp.net中使用它(不是直接我的意思)。网站上的每个用户将转换文件;会启动一个exe?我想我会尽快打服务器内存。



底线:我会尝试使用ffmpeg.exe,看看可以同时支持多少用户。



我去了ffmpeg网站,在windows下载部分我发现3个不同的版本;静态,共享和开发。



有谁知道哪个是最好的?所有包装在一个exe(静态)或dll的separely和exe小,wrt使用它在asp.net?



PS:任何一个有一个很好的图书馆在那里..如果您可以共享,将会很棒。



静态构建为每个程序提供一个独立的.exe文件(ffmpeg,ffprobe,ffplay)。



共享版本将每个库作为独立的.dll文件(avcodec,avdevice,avfilter等)和依赖于每个程序的这些库的.exe文件



开发包提供了在其他程序中使用.dll文件所需的标题和.lib / .dll.a文件。

解决方案

ffMpeg是我使用过的最好的库,但我不建议直接从asp.net调用它。



我做了什么,被接受的上传,存储在服务器上,或者S3在我的情况下,然后有一个工作者的角色(如果使用像Azure这样的东西)和持续查看和监视新文件的进程要转换。



如果您需要一个实时的解决方案,您可以更新数据库中的标志,并有一个AJAX解决方案轮询数据库以继续提供进度更新,然后转换完成后,请链接下载。



我的方法是


  1. Azure Web角色

  2. Azure Worker角色

  3. ServiceBus

WorkerRole启动并正在监视ServiceBus队列的消息。



ASP.NET站点上传和存储文件在S3或Azure
ASP.NET站点然后根据需要将信息记录在您的数据库中,并向ServiceBus队列发送消息。



WorkerRole选择并转换。



如果您需要实时监控解决方案,则需要在ASP.NET站点上使用AJAX。否则,如果需要,您可以在完成后发送电子邮件。



使用排队过程也可以帮助您加载,因为当您处于沉重的负载下时,人们只需稍等一会儿不要一切都停止。此外,您可以根据需要扩展您的工作人员角色,以平衡负载,如果一个服务器变得太多。



这是我如何从C#运行ffMpeg(您将需要更改您的要求的参数)

  String params = string.Format( -  i {0} -s 640x360 { 1},input.Path,C:\\\FilePath\\file.mp4); 

RunProcess(params);

私有字符串RunProcess(string参数)
{
//创建一个进程信息
ProcessStartInfo oInfo = new ProcessStartInfo(this._ffExe,Parameters);
oInfo.UseShellExecute = false;
oInfo.CreateNoWindow = true;
oInfo.RedirectStandardOutput = true;
oInfo.RedirectStandardError = true;

//创建输出和流程器以获取输出
string output = null; StreamReader srOutput = null;

//尝试进程
尝试
{
//运行进程
进程proc = System.Diagnostics.Process.Start(oInfo);
proc.ErrorDataReceived + = new DataReceivedEventHandler(proc_ErrorDataReceived);
proc.OutputDataReceived + = new DataReceivedEventHandler(proc_OutputDataReceived);

proc.BeginOutputReadLine();
proc.BeginErrorReadLine();

proc.WaitForExit();

proc.Close();
proc.Dispose();
}
catch(异常)
{
//捕获错误
}
finally
{
//现在,如果我们成功了,关闭了streamreader
if(srOutput!= null)
{
srOutput.Close();
srOutput.Dispose();
}
}



返回输出;
}


I needed a audio conversion library. After already pulling my hair..I have given up on the fact that there is no such audio library out there..every library out there has some or the other problem.

The only option left is ffmpeg which is the best but unfortunately you cannot use it in asp.net (not directly I mean). Every user on the website that will convert a file; will launch an exe?; I think I will hit the server memory max soon.

Bottom Line: I will try using ffmpeg.exe and see how many users it can support simultaneously.

I went to the ffmpeg website and in the windows download section I found 3 different version; static, shared and dev.

Does any one know which would be the best? All packed in one exe (static) or dll's separely and exe small, wrt using it in asp.net?

PS: any one has a good library out there..would be great if you can share.

Static builds provide one self-contained .exe file for each program (ffmpeg, ffprobe, ffplay).

Shared builds provide each library as a separate .dll file (avcodec, avdevice, avfilter, etc.), and .exe files that depend on those libraries for each program

Dev packages provide the headers and .lib/.dll.a files required to use the .dll files in other programs.

解决方案

ffMpeg is the best library out there from what I have used but I wouldn't recommend trying to call it directly from asp.net.

What I have done, is accepted the upload, stored it on the server, or S3 in my case, then have a worker role (if using something like Azure) and a process that continuously looks and monitors for new files to convert.

If you needed a realtime like solution, you could update flags in your database and have an AJAX solution to poll the database to keep providing progress updates, then a link to download once the conversion is complete.

Personally my approach would be

  1. Azure Web Roles
  2. Azure Worker Role
  3. ServiceBus

The WorkerRole starts up and is monitoring the ServiceBus Queue for messages.

The ASP.NET site uploads and stores the file in S3 or Azure The ASP.NET site then records information in your DB if needed and sends a message to the ServiceBus queue.

The WorkerRole picks this up and converts.

AJAX will be needed on the ASP.NET site if you want a realtime monitoring solution. Otherwise you could send an email when complete if needed.

Using a queuing process also helps you with load as when you are under heavy load people just wait a little longer and it doesn't grind everything to a halt. Also you can scale out your worker roles as needed to balance loads, should it ever become too much for one server.

Here is how I run ffMpeg from C# (you will need to change the parameters for your requirements)

String params = string.Format("-i {0} -s 640x360 {1}", input.Path, "C:\\FilePath\\file.mp4");

RunProcess(params);

private string RunProcess(string Parameters)
    {
        //create a process info
        ProcessStartInfo oInfo = new ProcessStartInfo(this._ffExe, Parameters);
        oInfo.UseShellExecute = false;
        oInfo.CreateNoWindow = true;
        oInfo.RedirectStandardOutput = true;
        oInfo.RedirectStandardError = true;

        //Create the output and streamreader to get the output
        string output = null; StreamReader srOutput = null;

        //try the process
        try
        {
            //run the process
            Process proc = System.Diagnostics.Process.Start(oInfo);
            proc.ErrorDataReceived += new DataReceivedEventHandler(proc_ErrorDataReceived);
            proc.OutputDataReceived += new DataReceivedEventHandler(proc_OutputDataReceived);

            proc.BeginOutputReadLine();
            proc.BeginErrorReadLine();

            proc.WaitForExit();

            proc.Close();
            proc.Dispose();
        }
        catch (Exception)
        {
            // Capture Error
        }
        finally
        {
            //now, if we succeeded, close out the streamreader
            if (srOutput != null)
            {
                srOutput.Close();
                srOutput.Dispose();
            }
        }



        return output;
    }

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

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