好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

.Net下使用 Geb.Video.FFMPEG 操作视频文件

.Net下使用 Geb.Video.FFMPEG 操作视频文件

.Net 下默认没有读写视频的类,要进行视频操作很麻烦,之前用过网上的代码,用的很不爽。 AForge.Net  对  ffmpeg  进行了封装,不过它引用的dll有点多,且没提供seek方法,无法跳到指定帧,也有点不爽,俺在 AForge.Net 对FFMPEG 封装的基础上,进行了修改,得到 Geb.Video.FFMPEG 库,现分享出来。

主要功能如下:

l 读取视频文件,获取视频参数;

l 读取帧;

l 查找帧;

l 写入视频文件。

有了这些功能,可以写一个简单的视频播放器了,当然,视频转码之类的也不在话下。在此基础上,视频分析,视频合成,视频编辑等等,都可以进行。

License:  LGPL v3 license  (AFoege.Net 的 license,毕竟是从它修改的). 源码整理后会在 Github 上发布

演示:

代码下载: Geb.Video.FFMPEG.Demo

读取视频文件,获取视频参数

_reader =  new   VideoFileReader();
_reader.Open(path);
String info  = String.Format( "  Video info:\r\n\r\n Width-{0}\r\n Height-{1}\r\n FrameCount-{2}\r\n FrameRate-{3}\r\n Codec-{4}  "  ,_reader.Width,_reader.Height,_reader.FrameCount, _reader.FrameRate, _reader.CodecName);
tbInfo.Text  = info;

读取下一帧:

ImageRgb24 img = _reader.ReadVideoFrame();

查找帧:

 //   指定帧的编号 
 Int64 idx  = _reader.FrameCount *  2  /  3  ;
  //   跳到指定帧附近的关键帧处,true 为跳到关键帧,false 为跳到任意帧 
 _reader.Seek(idx,   true );

写入视频文件

VideoFileWriter _writer =  new   VideoFileWriter();
_writer.Open(  "  output.avi  "  , _reader.Width, _reader.Height, _reader.FrameRate, VideoCodec.MPEG4);
  //   demo 代码,之处理 100 帧 
 for  ( int  i =  0 ; i <  100 ; i++ )
{
    ImageRgb24 img  =  _reader.ReadVideoFrame();
      if  (img ==  null )  break  ;
    _writer.WriteVideoFrame(img);
    img.Dispose();
}
_writer.Close(); 

不用时别忘记 Close()。

作者: xiaotie  ,  集异璧实验室(GEBLAB)

出处: http://www.cnblogs.com/xiaotie/

若标题中有“转载”字样,则本文版权归原作者所有。若无转载字样,本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.

 

分类:  [10]图像处理 ,  [23]盗乃忒尔

作者: Leo_wl

    

出处: http://www.cnblogs.com/Leo_wl/

    

本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

版权信息

查看更多关于.Net下使用 Geb.Video.FFMPEG 操作视频文件的详细内容...

  阅读:37次