Use Geb. Video. FFMPEG in. Net to operate Video files

Source: Internet
Author: User

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 ().

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.