本文介绍了互动与从.NET程序的ffmpeg - 写输入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 在参考 这 的问题,你可以看到我成功地运行和接收从节目数据In reference to this question, as you can see I managed to run and receive data from the program.不过,我没能提交数据给它,比如,同时转换的文件,pressing ①立即停止转换并停止该程序。我需要我的应用程序,支持停止过程很好,我想这应该通过传递此参数FFmpeg的应用程序来完成,因为我希望它采取的所有未收集资源照顾或任何灰尘会留下,如果我只想去使用 process.Kill()However I didn't manage to submit data to it, for instance, while converting a file, pressing q immediately stop conversion and stops the program.I need my application to support stopping the process as well, and I think this should be done by passing this parameter to the ffmpeg app, since I want it to take care of all uncollected resource or whatever dust it would leave behind if I would just go and use process.Kill()下面是我已经试过:static int lineCount = 0;static bool flag;static void process_ErrorDataReceived(object sender, DataReceivedEventArgs e){ Console.WriteLine("Error ({1:m:s:fff}: {0})", lineCount++, DateTime.Now); if (e.Data != null && string.Equals(e.Data,"Press [q] to stop, [?] for help")) flag = true; if (flag) { flag = false; Console.WriteLine("Stopping ({0:m:s:fff})...", DateTime.Now); process.CancelErrorRead(); process.CancelOutputRead(); process.StandardInput.WriteLine("q"); } Console.WriteLine(e.Data); Console.WriteLine();}不过,这并不做任何事情,似乎一旦转换已经要求,我对它没有任何控制的任何更多的,我只能从它接收输出。运行它作为独立的并允许我当然互动。But it doesn't do anything, seems that once the conversion has been requested, I have no control on it any more, I can only receive output from it. Running it as stand alone does allow me interaction of course.我缺少的是在这里,它是一个不同的把戏提交输出或code $ p中$ pvious答案是错的,或者我应该选择不同的方法?What am I missing here, is it a different trick in submitting the output or the code in previous answer is wrong, or I should have chosen a different approach?有关您的关注, RedirectStandardInput 是请注意:你可以在看answer我的previous问题,ffmpeg的交互方式不同,我想谁知道答案的人会(也许我错了)的人与ffmpeg的经验。NOTE: as you can see in the answer of my previous question, ffmpeg interacts differently, I think the one who knows the answer will be (maybe I'm wrong) someone with experience in ffmpeg.推荐答案使用的WriteLine('Q'); 而不是写('Q ');:)我试图从Cygwin的bash shell中运行ffmpeg的,看到我输入后的输入q 。所以....I tried to run ffmpeg from cygwin bash shell and saw that I had to type an enter after 'q'. So.... static void process_ErrorDataReceived(object sender, DataReceivedEventArgs e) { Console.WriteLine("Error line: {0} ({1:m:s:fff})", lineCount++, DateTime.Now); Console.WriteLine(e.Data); Console.WriteLine(); if (lineCount == 5) process.StandardInput.WriteLine("q"); }随着股市 C:\ Documents和Settings \所有用户\ Documents \我的音乐\示例音乐\贝多芬第九号交响曲(谐谑曲).WMA的1212457字节没有 process.StandardInput.WriteLine 将打印61行的标准错误,1号线在标准输出上,并创建MP3文件。添加退出,并打印数量stderr上线的少了,没事就stdout和一个更小的MP3文件。without the process.StandardInput.WriteLine it prints 61 lines on stderr, 1 line on stdout and creates mp3 file of 1212457 bytes.add the quit and it prints less number of lines on stderr, nothing on stdout and a much smaller mp3 file.请注意,它周围留有mp3文件。Note that it does leave the mp3 file around.所以。看到你的评论,你已经尝试过此之后..After seeing your comment that you already tried this..我刚刚复查。该行为很奇怪。I just rechecked. The behavior is strange.首先,我试了我必须一看,5日线sterr发送Q \ N创建一个更小的文件,但略有不同的大小在不同的运行 - 160K和220K之间。First I retried what I had and saw that sending "q\n" on the 5th line to sterr creates a much smaller file, though slightly different sizes in different runs -- between 160K and 220K.接下来我注释掉 Console.WriteLine 希望这会令ffmpeg的退出速度更快。相反,现在的ffmpeg的没有停止在所有的和完全一样的字节数,1212457字节创建完整的文件。此行为是符合你的观察Next I commented out Console.WriteLine hoping it will make ffmpeg quit faster. On the contrary, ffmpeg now did not stop at all and created the full file with exact same byte count, 1,212,457 bytes. This behavior is consistent with your observation最后, WriteLines 到位,我抽Q \ N每行标准错误之后的第五。巨大的惊喜!记录40错误行后,Finally, with WriteLines in place, I pumped "q\n" on every line to stderr after the fifth. Big surprise! After logging 40 error lines,Unhandled Exception: System.InvalidOperationException: StandardIn has not been redirected. at System.Diagnostics.Process.get_StandardInput() at StandAlone.Program.process_ErrorDataReceived(Object sender, DataReceivedEventArgs e) in C:\[..]\StandAlone\Program.cs:line 171 at System.Diagnostics.Process.ErrorReadNotifyUser(String data) 不重定向?的而你告诉我,我发后的 35行的到它的输入?Not redirected? And you are telling me after I sent 35 lines to its input?有些事情不太对劲......闻起来像一个bug。Something is not quite right...smells like a bug.更新窗口从这里建立(静态),解决了我的问题,我用一些构建从非官方的网站明显。Updating the windows builds from here (static) solved my issue, I used some builds from an unofficial website apparently. 这篇关于互动与从.NET程序的ffmpeg - 写输入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云!
08-23 05:10