• C#通过FFmpeg获得视频参数


     

     

    FFmpeg简介

    FFmpeg is a complete, cross-platform solution to record, convert and stream audio and video(录制、转换 、音/视频,并可将其转换为音/视频流的完整的,跨平台的j解决方案).FFmpeg的开发是基于Linux操作系统,但是可以在大多数操作系统中编译和使用。

    官网:http://ffmpeg.org/

    在windows环境下,需要用到其Windows Builds。

    下载地址: http://ffmpeg.zeranoe.com/builds/

    可根据自己的环境(32位或64位)选择下载相应的static builds即可。

    解压下载后的包会发现,里面都是.exe文件。我们在.net中用FFmpeg只能利用命令参数的形式来执行这些文件,为我们服务,极为不便。如果有一个能在.net环境中以对象的方式调用ffmpeg.exe的包装类就好了。还真有,php有,C#的也有,如:

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

    具体的可到这个网页下载,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();
    复制代码

    输出:

  • 相关阅读:
    MyEclipse 工具优化和初始化设置
    ubuntu添加软件源
    C/C++数组名与指针区别深入探索
    为什么不常见include .c文件
    [置顶] Linux学习笔记(完整版)
    linux .deb文件安装
    我们就是查拉图斯特拉所说最后的人?!
    关于Mina
    讨厌SVN
    关于对Mina的一些看法
  • 原文地址:https://www.cnblogs.com/xgbzsc/p/2729919.html
Copyright © 2020-2023  润新知