By default, there is no category for reading and writing videos in. Net. It is very troublesome to perform video operations. I have used online code before and it is very uncomfortable to use. AForge.. Net encapsulates ffmpeg, But it references a little more dll, and does not provide the seek method, and cannot jump to the specified frame.. Net is modified based on the FFMPEG encapsulation to obtain the Geb. video. the FFMPEG library is now shared.
The main functions are as follows:
L read video files and obtain video parameters;
L read frames;
L search for frames;
L write a video file.
With these functions, you can write a simple video player. Of course, Video Transcoding and other functions can also be used. On this basis, video analysis, video synthesis, and video editing can all be performed.
License: LGPL v3 license (AFoege. Net license, after all, is modified from it). Source Code: https://github.com/xiaotie/GebVideoFFMPEG
Demo:
Download the code: Geb. Video. FFMPEG. Demo
Reads video files and obtains video parameters.
_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;
Read the next frame:
ImageRgb24 img = _reader.ReadVideoFrame();
Search frame:
// Specify the frame number Int64 idx = _ reader. frameCount * 2/3; // jump to the key frame near the specified frame. true means to jump to the key frame, and false means to jump to any Frame _ reader. seek (idx, true );
Write video files
VideoFileWriter _ writer = new VideoFileWriter (); _ writer. open ("output. avi ", _ reader. width, _ reader. height, _ reader. frameRate, VideoCodec. MPEG4); // demo code for processing 100 frames for (int I = 0; I <100; I ++) {ImageRgb24 img = _ reader. readVideoFrame (); if (img = null) break; _ writer. writeVideoFrame (img); img. dispose ();} _ writer. close ();
Do not forget to Close () when not in use ().