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

相关文章
相关标签/搜索