C#經過FFmpeg得到視頻文件參數

C#經過FFmpeg得到視頻參數

 

FFmpeg簡介

FFmpeg is a complete, cross-platform solution to record, convert and stream audio and video(錄製、轉換 、音/視頻,並可將其轉換爲音/視頻流的完整的,跨平臺的j解決方案).FFmpeg的開發是基於Linux操做系統,可是能夠在大多數操做系統中編譯和使用。php

官網:http://ffmpeg.org/html

 

在windows環境下,須要用到其Windows Builds。

下載地址: http://ffmpeg.zeranoe.com/builds/windows

可根據本身的環境(32位或64位)選擇下載相應的static builds便可。app

 

解壓下載後的包會發現,裏面都是.exe文件。咱們在.net中用FFmpeg只能利用命令參數的形式來執行這些文件,爲咱們服務,極爲不便。若是有一個能在.net環境中以對象的方式調用ffmpeg.exe的包裝類就行了。還真有,php有,C#的也有,如:ide

http://nolovelust.com/post/Another-Simple-C-Wrapper-For-FFmpeg.aspxpost

具體的可到這個網頁下載,ffmpeg.exe的包裝類使用。若是對ffmpeg.exe在C#中的調用感興趣,可學習下其源碼。學習

 

使用很是簡單,以下解析視頻的相關信息:

 1 /**
2 * 支持視頻格式:mpeg,mpg,avi,dat,mkv,rmvb,rm,mov.
3 *不支持:wmv
4 * **/
5
6 VideoEncoder.Encoder enc =new VideoEncoder.Encoder();
7 //ffmpeg.exe的路徑,程序會在執行目錄(....FFmpeg測試\bin\Debug)下找此文件,
8 enc.FFmpegPath ="ffmpeg.exe";
9 //視頻路徑
10 string videoFilePath ="d:\\純粹瑜伽-混合課程.avi";
11 VideoFile videoFile =new VideoFile(videoFilePath);
12
13 enc.GetVideoInfo(videoFile);
14
15 TimeSpan totaotp = videoFile.Duration;
16 string totalTime =string.Format("{0:00}:{1:00}:{2:00}", (int)totaotp.TotalHours, totaotp.Minutes, totaotp.Seconds);
17
18 Console.WriteLine("時間長度:{0}",totalTime);
19 Console.WriteLine("高度:{0}",videoFile.Height);
20 Console.WriteLine("寬度:{0}", videoFile.Width);
21 Console.WriteLine("數據速率:{0}",videoFile.VideoBitRate);
22 Console.WriteLine("數據格式:{0}", videoFile.VideoFormat);
23 Console.WriteLine("比特率:{0}", videoFile.BitRate);//平均混合碼率
24 Console.WriteLine("文件路徑:{0}", videoFile.Path);
25
26 Console.ReadKey();

 

輸出:測試

 

 

實例源碼:FFmpeg測試ui

相關文章
相關標籤/搜索