如何使用 c# asp.net 为 ffmpeg 制作加载屏幕
我有这个函数,而 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要将流写入某个可以通过 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