用MediaInfo获取音视频信息

1.下载C#使用Mediainfo所必须的dll文件:http://pan.baidu.com/s/1nvT28Md

2.新建项目:

3.将解压后的dll文件复制到程序根目录:

4.添加引用,将MediaInfoNET.dll引入项目中

5.在所需类中引入命名空间:using MediaInfoNET;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MediaInfoNET;

namespace GetVideoDetails
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("视频信息测试:");
            //文件路径
            string videoFilePath = @"D:\myffmpeg\zuxia.wmv";
            //实例化
            MediaFile videoFile = new MediaFile(videoFilePath);

            Console.WriteLine("基本信息:");
            Console.WriteLine("完整名称:{0}", videoFile.File);
            Console.WriteLine("格式: {0}", videoFile.General.Format);
            Console.WriteLine("视频时长 : {0}", videoFile.General.DurationString);
            Console.WriteLine("视频码率(比特率) : {0}", videoFile.General.Bitrate);
            Console.WriteLine("概述: {0}", videoFile.Description);
            Console.WriteLine();
            if (videoFile.Video.Count > 0)
            {
                Console.WriteLine("视频信息:");
                Console.WriteLine("格式: {0}", videoFile.Video[0].Format);
                Console.WriteLine("码率: {0}", videoFile.Video[0].Bitrate.ToString());
                Console.WriteLine("分辨率: {0}", videoFile.Video[0].FrameSize.ToString());
                Console.WriteLine("视频概述: {0}", videoFile.Video[0].Description);
            }
            Console.WriteLine();
            if (videoFile.Audio.Count > 0)
            {
                Console.WriteLine("音频信息:");
                Console.WriteLine("格式 : {0}", videoFile.Audio[0].Format);
                Console.WriteLine("码率: {0}", videoFile.Audio[0].Bitrate.ToString());
                Console.WriteLine("声道 : {0}", videoFile.Audio[0].Channels.ToString());
                Console.WriteLine("采样率: {0}", videoFile.Audio[0].SamplingRate.ToString());
                Console.WriteLine("音频概述: {0}", videoFile.Audio[0].Description);
            }
            Console.WriteLine();

            Console.WriteLine("音频信息测试:");
            string audioFilePath = @"D:\myffmpeg\遇见.mp3";
            MediaFile audioFile = new MediaFile(audioFilePath);
            Console.WriteLine();
            Console.WriteLine("基本信息:");
            Console.WriteLine("完整名称:{0}", audioFile.File);
            Console.WriteLine("格式: {0}", audioFile.General.Format);
            Console.WriteLine("文件大小:{0}",audioFile.FileSize);
            Console.WriteLine("音频时长 : {0}", audioFile.General.DurationString);
            Console.WriteLine("视频码率(比特率) : {0}", audioFile.General.Bitrate);
            Console.WriteLine("概述: {0}", audioFile.Description);

            if (videoFile.Audio.Count > 0)
            {
                Console.WriteLine("音频信息:");
                Console.WriteLine("格式 : {0}", audioFile.Audio[0].Format);
                Console.WriteLine("码率: {0}", audioFile.Audio[0].Bitrate.ToString());
                Console.WriteLine("声道 : {0}", audioFile.Audio[0].Channels.ToString());
                Console.WriteLine("采样率: {0}", audioFile.Audio[0].SamplingRate.ToString());
                Console.WriteLine("音频概述: {0}", audioFile.Audio[0].Description);
            }
            Console.WriteLine();
            

        }
    }
}

6.用MediaInfo查看视频信息如下:

查看音频信息如下:

7.运行程序:

从结果可以看出,无论是音频还是视频都能通过MediaFile对象获取到基本信息!!

posted @ 2017-09-20 14:18  #疆先绅#  阅读(1440)  评论(0编辑  收藏  举报