惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

有赞技术团队
有赞技术团队
M
MIT News - Artificial intelligence
Hugging Face - Blog
Hugging Face - Blog
博客园 - 聂微东
量子位
S
SegmentFault 最新的问题
V
Visual Studio Blog
博客园 - 【当耐特】
Apple Machine Learning Research
Apple Machine Learning Research
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
小众软件
小众软件
Stack Overflow Blog
Stack Overflow Blog
Vercel News
Vercel News
D
Docker
J
Java Code Geeks
博客园 - 三生石上(FineUI控件)
博客园 - Franky
Recent Announcements
Recent Announcements
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
MongoDB | Blog
MongoDB | Blog
D
DataBreaches.Net
Y
Y Combinator Blog
云风的 BLOG
云风的 BLOG
V
V2EX

博客园 - nametmp

【转】Resource与Resx的区别 - nametmp - 博客园 异步调用过程 Winform用匿名方法新建线程的方法 enum枚举用法笔记 对C#委托的理解 对using的新认识 琐碎记录 【转贴】GridView里面的HYPERLINK数据邦定 【转贴】数据邦定语法 - nametmp - 博客园 TableAdapter、Dataset与BindingSource的关系 webform 可视化在gridview中加入其它控件 WinForm 加入登陆窗体(c#) winform 中的 datagridview 添加 progressbar列 和 calendar 列 远程删除Kaspersky(被Kaspersky搞了一天) SqlServer2000登陆角色的具体权限 终于用sqlcmd连上sqlserver2005express了 sqlserver操作摘录 [转]SQL Server 2005中的SQLCMD工具使用 [转]sqlserver2005(Express版)的配置
视频文件信息读取器
nametmp · 2008-04-22 · via 博客园 - nametmp

最近想要整理mtv,特意写了这个读取多种视频文件信息的辅助工具,包括mpg,avi,wmv,flv,rm,rmvb等。
原理:我只是做了个壳,实质是用ffmpeg.exe读取视频信息。

    public class cVideoInfo
    
{
        
private string _FileName;   //video file fullname
        private string _Info;      //all info
        private string _Name;       // vide name
        private string _Ext;        // file ext name        
        private string _Duration;
        
private string _BitRate;
        
private string _Size;
        
private string _FileSize;


        
public cVideoInfo(string FileName)
        
{           
            _FileName 
= FileName;
            _Info 
= "";
            _Name 
= FileName.Substring(FileName.LastIndexOf("\\"+ 1, FileName.LastIndexOf("."- FileName.LastIndexOf("\\"- 1);
            _Ext 
= FileName.Substring(FileName.LastIndexOf("."+ 1);
            _Duration 
= "";
            _BitRate 
= "";
            _Size 
= "";
            _FileSize 
= "";

            FileInfo fi 
= new FileInfo(_FileName);
            
if (!fi.Exists)
                
return;
            
else
                _FileSize 
= fi.Length.ToString();
            //这段代码的参考网上的
            Process p 
= new Process();//建立外部调用线程
            p.StartInfo.FileName = "ffmpeg.exe";//要调用外部程序的绝对路径
            p.StartInfo.Arguments = "-i \"" + _FileName + "\"";//参数(这里就是FFMPEG的参数了)            
            p.StartInfo.UseShellExecute = false;//不使用操作系统外壳程序启动线程(一定为FALSE,详细的请看MSDN)
            p.StartInfo.RedirectStandardError = true;//把外部程序错误输出写到StandardError流中(这个一定要注意,FFMPEG的所有输出信息,都为错误输出流,用StandardOutput是捕获不到任何消息的这是我耗费了2个多月得出来的经验mencoder就是用standardOutput来捕获的)
            p.StartInfo.CreateNoWindow = true;//不创建进程窗口
            p.ErrorDataReceived += new DataReceivedEventHandler(CatchOutputInfo);//外部程序(这里是FFMPEG)输出流时候产生的事件,这里是把流的处理过程转移到下面的方法中,详细请查阅MSDN
            p.Start();//启动线程
            p.BeginErrorReadLine();//开始异步读取
            p.WaitForExit();//阻塞等待进程结束
            p.Close();//关闭进程
            p.Dispose();//释放资源
        }


        
public string FileName
        
{
            
get
            
{
                
return _FileName;
            }

        }


        
public string Info
        
{
            
get
            
{
                
return _Info;
            }

        }


        
public string Name
        
{
            
get
            
{
                
return _Name;
            }

        }


        
public string Ext
        
{
            
get
            
{
                
return _Ext;
            }

        }

        
        
public string Duration
        
{
            
get
            
{
                
return _Duration;
            }

        }


        
public string BitRate
        
{
            
get
            
{
                
return _BitRate;
            }

        }


        
public string Size
        
{
            
get
            
{
                
return _Size;
            }

        }


        
public string FileSize
        
{
            
get
            
{
                
return _FileSize;
            }
            
        }


        
private void CatchOutputInfo(object sendProcess, DataReceivedEventArgs OutputInfo)
        
{
            
string sOutputInfo = OutputInfo.Data;
            
int iStart = 0, iEnd = 0;

            
if (!String.IsNullOrEmpty(sOutputInfo))
            
{
                _Info 
= _Info + "\r\n" + sOutputInfo;


                
//Duration ,BitRate
                if (sOutputInfo.IndexOf("Duration">= 0)
                
{
                    iStart 
= sOutputInfo.IndexOf(":"+ 1;
                    iEnd 
= sOutputInfo.IndexOf(".", iStart);
                    _Duration 
= sOutputInfo.Substring(iStart, iEnd - iStart);

                    iStart 
= sOutputInfo.IndexOf("bitrate"+ 8;
                    _BitRate 
= sOutputInfo.Substring(iStart);
                }


                
//Size
                if (sOutputInfo.IndexOf("Video">= 0)
                
{
                    
if (_Ext.Substring(0,2).ToLower() == "rm")
                    
{
                        iStart 
= sOutputInfo.IndexOf(","+ 1;
                        iEnd 
= sOutputInfo.IndexOf(",", iStart);
                    }

                    
else
                    
{
                        iStart 
= sOutputInfo.IndexOf(","+ 1;
                        iStart 
= sOutputInfo.IndexOf(",", iStart) + 1;
                        iEnd 
= sOutputInfo.IndexOf(",", iStart);
                    }

                    _Size 
= sOutputInfo.Substring(iStart, iEnd - iStart);
                }

            }

        }

    }