如何调用ffmpeg.exe的音频文件转换成Windows Azure上? [英] How to call ffmpeg.exe to convert audio files on Windows Azure?

查看:99
本文介绍了如何调用ffmpeg.exe的音频文件转换成Windows Azure上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行Windows Azure上的Web角色获得AAC音频文件(通过串的base64上传),并将其存储到BLOB。它现在正常工作。

I run a Web Role on Windows Azure to receive AAC audio files (uploaded by base64 string) and store them into blob. it works fine by now.

接下来,我也有将它们转换成MP3和存储的MP3到一滴了。我决定使用类似的 ffmpeg.exe -i的路径的.AAC的路径的.MP3

Next, I also have to convert them into MP3 and store the MP3s into blob too. I decided to use something like ffmpeg.exe -i path.aac path.mp3.

存在的问题是:


  1. 如何拨打外部ffmpeg.exe 的Web角色的Web服务中?

  2. 这将是在路径

  1. How to call external ffmpeg.exe inside a web service of a web role?
  2. what would be the path?

请帮助我,如果你知道。谢谢你在前进。

Please help me if you know. Thank you in advance.

推荐答案

我建议你使用的本地存储资源您webrole在那里你可以从Blob存储下载AAC文件,并将它们转换为MP3。然后上传回Blob存储。

I suggest that you use a Local Storage Resource for your webrole where you can download the AAC files from the blob storage, and have them converted to MP3. Then upload back to blob storage.

旁注是,您还可以使用 Path.GetTempFileName()以为您的AAC / MP3文件的获取临时文件名,但我不鼓励这样做(即使我以前做过的话)。

Side note is that you can also use the Path.GetTempFileName() to get a temporary file name for your AAC / MP3 files, but I don't encourage to do so (even if I've done it before).

对于实际工作的ffmpeg运行,你可能要浏览的code为 AzureVideoConv ,我'已经建立前一段时间。你会发现很多有用的code那里。

As for the actuall ffmpeg running, you might want to browse the code for AzureVideoConv, which I've built some time ago. You will find a lot of useful code there.

下面是实际的ffmpeg调用(注意,我从一个Blob存储下载exe文件,以避免腹胀我的天蓝色包装与外部exe文件,并在需要时轻松地更新ffmpeg.exe)的样本:

Here is a sample of the actual ffmpeg call (note that I download the exe from a blob storage, to avoid bloating my azure package with external exe files, and to easily update the ffmpeg.exe when required):

        internal void ConvertFile(string inputFileName, Guid taskID)
    {
        string tmpName = string.Format(
            "{0}\\{1}.flv",
            Path.GetTempPath(), inputFileName.Substring(inputFileName.LastIndexOf("\\")+1));
        ProcessStartInfo psi = new ProcessStartInfo();
        psi.FileName = this._processorExecutable;
        psi.Arguments = string.Format(@"-i ""{0}"" -y ""{1}""", inputFileName, tmpName);
        psi.CreateNoWindow = true;
        psi.ErrorDialog = false;
        psi.UseShellExecute = false;
        psi.WindowStyle = ProcessWindowStyle.Hidden;
        psi.RedirectStandardOutput = true;
        psi.RedirectStandardInput = false;
        psi.RedirectStandardError = true;
        try
        {
            // Start the process with the info we specified.
            // Call WaitForExit and then the using statement will close.
            using (Process exeProcess = Process.Start(psi))
            {
                exeProcess.PriorityClass = ProcessPriorityClass.High;
                string outString = string.Empty;
                // use ansynchronous reading for at least one of the streams
                // to avoid deadlock
                exeProcess.OutputDataReceived += (s, e) => {
                    outString += e.Data;
                };
                exeProcess.BeginOutputReadLine();
                // now read the StandardError stream to the end
                // this will cause our main thread to wait for the
                // stream to close (which is when ffmpeg quits)
                string errString = exeProcess.StandardError.ReadToEnd();
                Trace.WriteLine(outString);
                Trace.TraceError(errString);
                byte[] fileBytes = File.ReadAllBytes(tmpName);
                if (fileBytes.Length > 0)
                {
                    this._sSystem.SaveOutputFile(
                        fileBytes, 
                        tmpName.Substring(tmpName.LastIndexOf("\\")+1),
                        taskID
                        );
                }
            }
        }
        catch (Exception e)
        {
            Trace.TraceError(e.Message);
        }
    }

注意在项目的最后检查使用的Windows Azure SDK 1.3

NOTE the last check in of the project is using Windows Azure SDK 1.3

这篇关于如何调用ffmpeg.exe的音频文件转换成Windows Azure上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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