zoukankan      html  css  js  c++  java
  • asp.net 获取音视频时长 的方法

    http://www.evernote.com/l/AHPMEDnEd65A7ot_DbEP4C47QsPDYLhYdYg/

    日志:

     
    1.第一种方法:
     
    调用:shell32.dll ,win7下可以,window2008 r2 服务器上 不行。(原因不知道,有可能是声卡驱动没有安装?)
    //添加引用:COM组件的Microsoft Shell Controls And Automation
    引用shell32底层接口c:windowssystem32shell32.dll,vs自动转换成interop.shell32.dll(注:64位系统和32位系统生成的interop.shell32.dll不一样) 参考:http://www.stepday.com/topic/?867
     
     
                   string file = Request.Form["mp3path" ];
                    Shell32. ShellClass sh = new Shell32.ShellClass();
                    Folder dir = sh.NameSpace(Path .GetDirectoryName(file));
                    FolderItem item = dir.ParseName(Path .GetFileName(file));
                    log.Info( "file:" + file);
                    string mp3Time = "" ;
                    if (Environment .OSVersion.Version.Major >= 6)
                    {
                        mp3Time = dir.GetDetailsOf(item, 27);
                    }
                    else
                    {
                        mp3Time = dir.GetDetailsOf(item, 21);
                    }
                    sb.Append( "文件路径:" + file + " ");
                    sb.Append( "<br />");
                    sb.Append( "服务器的OSVersion.Version.Major:" + Environment.OSVersion.Version.Major);
                    sb.Append( "用Shell32.dll方式测试文件的时长:" + mp3Time);
                    sb.Append( "<br />");
     
    2.第二种方法:利用:mediainfo.dll:
     
                    MediaInfo MI = new MediaInfo();
                    MI.Open(file);
                    string s = MI.Get(StreamKind .Audio, 0, "Duration");
                    string dateTimeStr = Common.TimeHelper .GetDateTimeStr(Convert.ToInt32(s));
                    sb.Append( "用mediainfo.dll计算时长:" + dateTimeStr);
     
    一样,也是win7下没有问题,服务器上有问题。
     
    3, 第三种方法:利用:
                     //用ffmpeg.exe 获取:
                    sb.Append( "<br />");
                    string fromffmpeg = Fromffmpeg(file);
                    sb.Append( "fromffmpeg:" + fromffmpeg);
    子方法:
    private string Fromffmpeg(string fileName)
            {
                string duration = "" ;
                using (System.Diagnostics.Process pro = new System.Diagnostics. Process())
                        {
                            pro.StartInfo.UseShellExecute = false;
                            pro.StartInfo.ErrorDialog = false;
                            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;
                            }
                            return duration;
     
                        }
            }
     
     
    到此:成功!服务器ok~
     
     
  • 相关阅读:
    (转)A Recipe for Training Neural Networks
    (转)Extracting knowledge from knowledge graphs using Facebook Pytorch BigGraph.
    论文笔记:Heterogeneous Memory Enhanced Multimodal Attention Model for Video Question Answering
    论文笔记:Decoders Matter for Semantic Segmentation: Data-Dependent Decoding Enables Flexible Feature Aggregation
    论文笔记:Fast Neural Architecture Search of Compact Semantic Segmentation Models via Auxiliary Cells
    论文笔记:Prediction-Tracking-Segmentation
    论文笔记:SiamRPN++: Evolution of Siamese Visual Tracking with Very Deep Networks
    (转)AutoML for Data Augmentation
    (转)Illustrated: Efficient Neural Architecture Search ---Guide on macro and micro search strategies in ENAS
    (转)The Evolved Transformer
  • 原文地址:https://www.cnblogs.com/dudu837/p/4534350.html
Copyright © 2011-2022 走看看