使用C#在文本文件中输出Ffmpeg [英] Ffmpeg output log in text file using C#

查看:139
本文介绍了使用C#在文本文件中输出Ffmpeg的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个简单的代码,用于在文件而不是控制台中创建ffmpeg日志输出。



但是此代码不会创建输出日志文件,其中相同在命令提示符下使用时的安排是有效的。有人可以帮忙吗?还需要做些什么来获取日志文件中的输出?



问候Arunava



< b>我尝试了什么:



This is a simple code to create ffmpeg log output in a file instead of console.

But this code doesn't create an output log file wherein the same arrangements when used in command prompt it works. Can anybody help in this? what more needs to be done to get the output in the log file?

Regards Arunava

What I have tried:

<pre>string fullPath = "d:";
        string fileName= "wildlife.wmv";
        string pathfile = "D:";
        process.StartInfo.Arguments = "-i \"" + fullPath + "\" + fileName + +\" 2> \"" + pathfile + "\ffmpeglog.log\"";

        process.StartInfo.UseShellExecute = false;
        process.StartInfo.RedirectStandardError = true;
        process.StartInfo.CreateNoWindow = false;
        process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
        process.Start();
        string output2 = process.StandardError.ReadToEnd();
        process.WaitForExit();
        process.Close();

推荐答案

使用调试器进行快速检查会告诉你您的参数错误,因为您的字符串中没有未反斜杠。所以代码:

A quick check with your debugger would show you that your parameters are wrong as you have unescaped backslashes in your strings. So the code:
string fullPath = "d:";
        string fileName= "wildlife.wmv";
        string pathfile = "D:";
        process.StartInfo.Arguments = "-i \"" + fullPath + "\" + fileName + +\" 2> \"" + pathfile + "\ffmpeglog.log\"";



产生字符串:


results in the string:

process.StartInfo.Arguments =  -i "d:" + fileName + +" 2> "D:fmpeglog.log"



它应该是:


It should be:

process.StartInfo.Arguments = "-i \"" + fullPath + "\\" + fileName + "\" 2> \"" + pathfile + "\\ffmpeglog.log\"";


尝试使用上面的代码,但它不起作用。当我们使用相同的代码运行ffmpeg时,我们需要在ffmpeglog.log之后删除最后的\以生成日志。

当我使用时

Tried with the above code but its not working. When we run ffmpeg with the same code we need to remove the final "\" after ffmpeglog.log to generate the log.
When I am using
" -i \"d:\\wildlife.wmv 2> \"D:\\ffmpeglog.log\""





日志不生成但无法删除\\ \\从字符串中抛出Newline常量错误。



我怎样才能使用





The log is not generating but cannot remove the "\" from the string since its throwing Newline constant error.

How can I use

" -i \"d:\\wildlife.wmv 2> \"D:\\ffmpeglog.log""





而不是之前的代码。或者我们需要对配置进行一些更改?目前的配置如下。





instead of the previous code. Or we need to make some changes in the configuration? Current configuration is as follows.

startProcess.CreateNoWindow = true;
           startProcess.ErrorDialog = false;
           startProcess.UseShellExecute = false;
           startProcess.RedirectStandardOutput = true;
           //startProcess.RedirectStandardError = false;
           startProcess.RedirectStandardError = true;
           startProcess.RedirectStandardInput = true;





请告知。



Please advise.


这篇关于使用C#在文本文件中输出Ffmpeg的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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