Ffmpeg and opencv play and display video files, ffmpegopencv

Source: Internet
Author: User

Ffmpeg and opencv play and display video files, ffmpegopencv
Ffmpeg is based on the latest version. download it from the official website: http://ffmpeg.zeranoe.com/builds /. During compilation, configure the relevant header file and library path in VS2010. For more information about how to build opencv, see the previous blog. First, we will briefly introduce the following knowledge about video files. We usually see video files in many formats, such as avi, mkv, rmvb, mov, and mp4. These are called containers ), different container formats specify how audio and video data is organized (including other data, such as subtitles ). The container typically encapsulates video and audio tracks, also known as video streams and audio streams. The first step to play a video file is to parse (demux) according to the format of the video file) the encapsulated video streams, audio streams, and subtitles (if any) are output. The parsed data is read to the packet. Each packet stores the video frame or audio frame, call the corresponding decoder (decoder) to decode the video frames and audio frames respectively. For example, use H. the 264 encoded video and MP3 encoded audio will call the H. 264 decoder and MP3 decoder, After decoding, the original image (YUV or RGB) and audio (PCM) data are obtained, and then the image is displayed to the screen according to the synchronization time, output the sound to the sound card, and finally the video we see.
It's nice to see the following article. Reprinted part:

Some people may wonder why the decoded pFrame is not directly used for display, but is called for display after swscale () conversion?

If SDL is called directly for display without conversion, the displayed images are messy. The key issue is that the linesize stored in the decoded pFrame is not the image width, but a value larger than the width. The reason has not been carefully investigated (probably for performance reasons ). For example, if the resolution is 512x480, the linesize of the decoded video [0] is instead. The following example uses 1st rows of brightness pixels (pFrame-> data [0]). brightness data is stored from 0 to, and invalid data is stored from. Therefore, swscale () is required for conversion. After the conversion, the linesize [0] is changed to 480. It will be displayed normally.



100-line code is the simplest Video Player (SDL1.x) based on FFMPEG + SDL)

See the code below!
/* File: playvideo. cpp * Auth: sjin * Date: 20141029 x Mail: 413977243@qq.com */# include <stdio. h> # include <cv. h> # include <cxcore. h> # include Run as follows:



References: http://www.cnblogs.com/dyllove98/archive/2013/07/03/3170272.html
Http://blog.csdn.net/hsp494980719/article/details/7986400

Some avi videos cannot be opened for Opencv.

In fact, this problem is occasionally encountered. Check the problem through the following four steps (summarized by yourself)
(1) the video file path is not correct. (2) No decoder is installed. (3) If Opencv2.0 or later is used, can opencv_ffmpeg210.dll be correctly loaded? (4) although it is an AVI file, some codec, such as MJPEG Decompressor, may also be used. We need to convert it to AVI files supported by OpenCV. AVI files supported by OpenCV. For example, using the beaver nest all-around Video Converter, In the provisioning section, select the AVI-Audio_Video Interleaved (*. avi ). You can also use a format factory.

Hope to help you...

I want to use opencv programming to read the video file avi. The compilation is successful, but when the program is executed, the video avi file cannot be played.

It seems that opencv 2.0 requires the ffmpeg version to be earlier than 0.7, but it requires an old ffmpeg version. Is your ffmpeg version too new ......

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.