如何使用 c# asp.net 为 ffmpeg 制作加载屏幕

发布于 2024-12-02 16:16:55 字数 2054 浏览 0 评论 0原文

我有这个函数,而 Debug.WriteLine 命令所在的位置就是我输出值的位置。我如何将这些数据打印到网页中,以便我可以模拟加载屏幕?我通过 *.ashx Web 服务文件从外部调用此函数。

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
            {
                string 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");

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
            {
                string 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");

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

扮仙女 2024-12-09 16:16:55

您需要将流写入某个可以通过 Web 请求读取的数据存储。您将无法像我认为您想要的那样处理此流。例如,将此数据写入缓存/数据库并让客户端不断读取。
您可以尝试一些“较新”的东西,例如 SignalR,并尝试将其流式传输到客户端,尽管这仍然需要从共享存储中读取它。因此,您的 Debug.WriteLines 将改为写入队列的方法。您的客户端将从队列中读取并删除这些消息。

如果您对实时持久连接感兴趣,请查看 Scott Hanselman 的帖子:

AsynchronousScalableWebApplicationsWithRealtimePersistentLongrunningConnectionsWithSignalR

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文