开发者

How to do make a loading screen for ffmpeg using c# asp.net

开发者 https://www.devze.com 2023-04-02 04:32 出处:网络
I have this function and where the Debug.WriteLine commands are is where I output the values.How would I get this data to print into a webpage so I can mimic a loading screen?I am calling this functio

I have this function and where the Debug.WriteLine commands are is where I output the values. How would I get this data to print into a webpage so I can mimic a loading screen? I am calling this function externally through a *.ashx web service file.

private string ConvertToFLV(string phyicalFilePath)
        {
            if (Path.GetExtension(phyicalFilePath).Equals(".flv")) return phyicalFilePath;

            var argument = string.Format(@"-i ""{0}"" -vcodec flv -f flv -r 29.97 -s 320x240 -aspect 4:3 -b 300k -g 160 -cmp dct  -subcmp dct  -mbd 2 -flags +aic+cbp+mv0+mv4 -trellis 1 -ac 1 -ar 22050 -ab 56k ""{1}""", phyicalFilePath, Path.ChangeExtension(phyicalFilePath, "flv"));
            libfaac -ar 48000 -ab 128k -coder 1 -flags +loop -cmp +chroma -partitions +parti4x4+partp8x8+partb8x8 -me_method hex -subq 6 -me_range 16 -g 250 -keyint_min 25 -sc_threshold 40 -i_qfactor 0.71 -b_strategy 1 -threads 0 {1}", phyicalFilePath, Path.ChangeExtension(phyicalFilePath, "mp4"));
            File.Delete(Path.ChangeExtension(phyicalFilePath, "flv"));

            ProcessStartInfo process = new ProcessStartInfo(ffmpegPhysicalPath, argument);
            Process proc = new Process();
            float duration = 0.00F, current = 0.00F;
            proc.StartInfo = process;
            proc.EnableRaisingEvents = false;
            proc.StartInfo.UseShellExecute = false;
            proc.StartInfo.CreateNoWindow = true;
            proc.StartInfo.RedirectStandardOutput = true;
            proc.StartInfo.RedirectStandardError = true;

            proc.Start();

            StreamReader d = proc.StandardError;

            do
            {
                stri开发者_开发技巧ng s = d.ReadLine();
                if (s.Contains("Duration: "))
                {
                    Debug.WriteLine("DURATION: " + s);

                }
                else
                {
                    if (s.Contains("frame="))
                    {
                        Debug.WriteLine("FRAME: " + s);

                    }
                }
            } while (!d.EndOfStream);


            proc.WaitForExit();

            return Path.ChangeExtension(phyicalFilePath, "flv");


You need to write your stream out to some data store that can be read by a web request. You won't be able to process this stream like I think you are wanting to. For instance, write this data out to a cache/db and have it constantly read by the client. You could try some of the 'newer' stuff like SignalR and try streaming it to the client, although this still would require reading it from a shared store. So your Debug.WriteLines would instead be a method that would write to a queue. Your client would read and remove these messages from the queue.

If you are interested in the real time persistent connections check out Scott Hanselman's posting:

AsynchronousScalableWebApplicationsWithRealtimePersistentLongrunningConnectionsWithSignalR

0

精彩评论

暂无评论...
验证码 换一张
取 消