zoukankan      html  css  js  c++  java
  • ffmpeg获取文件的总时长(mp3/mp4/flv等)

    使用ffmpeg.exe获取文件属性信息,C#中可以在进程外异步调用这个工具,如下:

    using (System.Diagnostics.Process pro = new System.Diagnostics.Process())
    {
        pro.StartInfo.UseShellExecute = false;
        pro.StartInfo.ErrorDialog = false;
        pro.StartInfo.CreateNoWindow = true;
        pro.StartInfo.RedirectStandardError = true;
        pro.StartInfo.FileName = AppDomain.CurrentDomain.BaseDirectory + "ffmpeg.exe";
        pro.StartInfo.Arguments = " -i " + fileName;
        pro.Start();
        System.IO.StreamReader errorreader = pro.StandardError;
        pro.WaitForExit(1000);
        string result = errorreader.ReadToEnd();
        if (!string.IsNullOrEmpty(result))
        {
            result = result.Substring(result.IndexOf("Duration: ") + ("Duration: ").Length, ("00:00:00").Length);
            duration = result;
        }
    }

    关于运行程序隐藏窗口的问题:

    1、首先CreateNoWindow只对那些命令行程序有效。如果:cmd.exe。 (NoWindow理解成非消息循环程序可能更恰当)

    2、如果要将CreateNoWindow设为true,那UseShellExecute必须为:false才有效。

    3、想要使WindowStyle有效,UseShellExecute必须为:true。WindowStyle只对有UI界面的程序有效。(UseShellExecue默认为:true)

    4、上述结论不是对所有程序有效,比如:calc.exe(你怎么就选中它来测试呢...),把calc.exe换成notepad.exe或Iexplore.exe或自己写个WinForm程序什么的就可以看到效果了。

    5、瞎猜的。 UseShellExecute为true时可能是调用了WndMain,而那些不听话的程序都是因为没对第四个参数:ShowCmd做处理?

    6、对于计算器这类不听话的家伙,好象只能System.Threading.Thread.Sleep(xxx)后ShowWindow了。但延迟多少时间是个问题,少了没用,多了界面会弹出来一会才隐藏。

  • 相关阅读:
    sqlserver查询某个数据库有多少个表 ,存过,函数,视图
    C# 金额转为大写金额
    C# TextBox中只能输入数字的几种常用方法(C#)
    C# 设置Excel单元格属性
    MS SQL 维护小记
    webapi demo
    远程 TeamViewer
    https://github.com/
    C# Fun 类似委托
    技术点文章收集
  • 原文地址:https://www.cnblogs.com/EasonJim/p/6255737.html
Copyright © 2011-2022 走看看