Implementation of Avi-based network video monitoring and Storage System

Source: Internet
Author: User
Tags bmp image

Abstract: A video stream compression Solution Using Xvid for AVI file storage is proposed and implemented. The network video monitoring server uses Xvid to encode the collected video images, the storage system stores compressed video streams in the general AVI file format for retrieval and query.

Key words: Avi; Xvid video codecs; video storage; video playback

How to Design Recording System in Network Camera Video Server Based on Avi

Li qunlin

(College of electrical and Information Engineering of Hunan University, Changsha 410082)

Abstract: A rcording system in a Network camera video server which is designed with AVI files, the video server uses the Xvid MPEG-4 video codec to compress image data, then the recording system saves the compressed video data in AVI files for query later.

Keywords: Avi; Xvid MPEG-4 video codec; video record; video play

1. Introduction to the Network Video Monitoring System
With the development of Internet and broadband network technology, multimedia content services with video and audio will soon become the mainstream. At the same time, the proposal of various efficient compression and decompression algorithms makes it possible to transmit multimedia information over the network. Network Video Monitoring is widely used in many occasions with Its intuitive, convenient, and rich information.

 

Figure 1 Network Video Monitoring System Structure

The network video monitoring system is a system based on the client/server model. It consists of a video server and a client. The Video Server is an embedded system consisting of saa7113, pnx1301, and rtl8139. saa7113 can collect videos. pnx1301 is the core of the system and processes video data, such as video encoding, alarm detection, and cloud mirror control. rtl8139 is responsible for data transmission and data interaction with the client through the network.

The client is a general computer that selectively connects to one or more servers. After authentication, the client can send commands to the monitoring server to obtain compressed video streams and other measurement data from the monitoring server, to achieve remote video monitoring.

The system uses the Xvid video decoder to compress image data. Because Xvid is open source code, it can be transplanted to the PSOs Operating System of pnx1301 to encode image data; the client computer receives compressed video data from the network and uses the same version of XviD decoder for decoding to obtain the image data.

2. XviD video compression format
2.1. XviD features
Xvid supports multiple encoding modes. In addition to the original single-reevaluate fixed-code-stream compression (1-pass CBR), Xvid provides the following encoding modes: single-weight mode dynamic bitstream compression, single-weight (Quantization) mode dynamic bitstream compression, and two (2-pass) Dynamic bitstream compression modes including external control and internal control.

The motion detection feature of XviD allows you to allocate more space, higher code streams, and lower quantization ranges to motion images that require high code streams to keep the details of the images; for static images that do not contain too much motion information, the allocation budget is reduced. This is the core content of XviD as the second generation of MPEG4 encoding.

Xvid supports dynamic key frame (I-frame interval) and B-frame, that is, bidirectional prediction frame. In addition, it supports the options of mental visual brightness correction and cast table. Image optimization and decoding.

2.2. Implementation of XviD encoding/Decoding
The Xvid source code consists of xvidcore, VFW, and dshow, which can be compiled using Microsoft Visual C ++ and NASM. This article uses Microsoft Visual C ++ 2003.net and the NASM-0.98.39 to compile successfully, where compiling the dshow project also requires the installation of DirectX 9.0 SDK.

The xvidcore project generates the API function library of the Xvid decoder: xvidcore. DLL; the installation file of the Xvid decoder generated by the VFW project in Windows: xvidvfw. DLL and XviD. INF; dshow to generate Xvid to register the file in Windows: XviD. ax.

 

Figure 2 procedure of calling the Xvid Library Function

Because the Xvid encoding section in this article is implemented in pnx1301, only the Decoding Section of XviD is described here.

1) load the xvidcore. dll library function

The Xvid API function needs to load the xvidcore. dll library and contain the VFW. h and XviD. h header files. The method for calling the API function is as follows:

Hinstance m_hdll = loadlibrary ("xvidcore. dll ");

Xvid_global_func = (INT (_ cdecl *) (void *, Int, void *, void *) getprocaddress (m_hdll, "xvid_global ");

Xvid_decore_func = (INT (_ cdecl *) (void *, Int, void *, void *) getprocaddress (m_hdll, "xvid_decore ");

2) initialize the decoder

Xvid_global_func (0, xvid_gbl_init, & init, null );

3) create a decoder

Int length = xvid_decore_func (0, xvid_dec_create, & create, null );

4) result output settings

The xvid_dec_frame_t structure is the main parameter for decoding. The output part needs to set the output buffer, step size, and output type. When the color depth is 24 bits, the data step size in RGB format is three times the image width.

Frame. Output. Plane [0] = ostream;

Frame. Output. stride [0] = calc_bi_stride (width, 24 );

Frame. Output. CSP = xvid_csp_vflip | xvid_csp_bgr;

5) decoding

Int length = xvid_decore_func (dhandle, xvid_dec_decode, & frame, & stats );

3. Use AVI format to store videos
AVI (short for audio video interleaved) is a type of riff (short for resource Interchange File Format) file format, used in audio and video capture, editing, playback, and other applications. Normally, an AVI file can contain multiple different types of media streams (in typical cases, there is an audio stream and a video stream ), however, AVI files containing a single audio stream or a single video stream are also valid. Avi is the most basic and commonly used media file format in windows.

3.1. AVI video file structure

Figure 3 structure of the AVI file

'Avih ': file information (in avifileinfo format), 'strh': data stream information (in avistreaminfo format), and 'strf': format information (in bitmapinfo format ).

3.2. Install the Xvid Decoder
To use the Xvid decoder in Windows, you must install the Xvid decoder. To install xvidcore, you must first mention the three xvidcore files generated by the xvidcore and VFW projects. DLL, xvidvfw. DLL and XviD. INF, right-click XviD. select the "Install" command for the INF file.

3.3. Storing AVI Video Files
Microsoft provides an API to read and write AVI files. To use these library functions, you must load the vfw32.lib Library and the VFW. h header file in the program. All operations on AVI files in this article use functions in this library.

To compress data streams, you can use the avisaveoptions and avimakecompressedstream functions to select the video codecs installed in the operating system. This step is not required because the encoded Xvid data stream is obtained from the video server.

 

Figure 4 Avi read/write process

3.3.1. obtain raw data
First, get the length of the frame data, and then get the original data in the file.

Avistreamread (pvideostream, lframes, avistreamread_convenient, null, 0, & lsize, null );

Avistreamread (pvideostream, lframes, avistreamread_convenient, pbuffer, lsize, null, null );

The original data is compressed data. You can directly call the API function of XviD to decode the data to obtain the image data.

3.3.2. obtain data in RGB format
By using the avi api function, you can directly call the Xvid decoder to obtain data in RGB format.

1) Get the formatting information

First obtain the size of the format to determine whether the data stream is a video stream or an audio stream.

Avistreamreadformat (pvideostream, avistreamstart (pvideostream), null, & lsize );

Obtain the formatting information. If the video stream is in bitmapinfo format, you can obtain the formatting details, such as the size, compression method, color depth, and buffer size.

Avistreamreadformat (pvideostream, avistreamstart (pvideostream), pchunk, & lsize );

Lpbitmapinfo pinfo = (lpbitmapinfo) pchunk;

2) set the result information Header

Here we want to get an RGB data stream. The original data format is XviD. Here we only need to change the compression mode and buffer size of the original format. The formula for calculating the buffer size is as follows. The size of the buffer is equal to the size of BMP image data of the same size.

Lpbitmapinfoheader pbmpih = getstreamformat ();

Pbmpih-> bicompression = bi_rgb;

Pbmpih-> bisizeimage = (pbmpih-> biwidth * pbmpih-> bibitcount + 31)/32*4) * pbmpih-> biheight;

3) obtain the RGB formatted data stream. If pbmpih is empty, the original data is returned.

Pgetframe pvideoframe = avistreamgetframeopen (pvideostream, pbmpih );

4) Obtain RGB data. The obtained RGB data includes 40 bytes of image format information.

Lpbyte pimage = (lpbyte) avistreamgetframe (pvideoframe, lframes );

Pimage = pimage + sizeof (bitmapinfoheader );

3.4. AVI Video Playback
If the Xvid decoder is not installed in the operating system, the player cannot identify the AVI file in Xvid format. The solution is to use the XviD. Ax registration file generated by dshow, as shown in the preceding installation method.

The registration method is to input in the command line:

"<Path to Windows>/system/regsvr32 <path to XviD. Ax>/XviD. Ax"

For example, "C:/Windows/system/regsvr32 C:/program files/XviD. and then copy xvidcore. DLL to "<path to Windows>/system32", for example, "C:/Windows/system32 ". You can test whether the installation is successful by playing an Xvid clip to check whether the player works properly.

This article uses three methods to test the playback of XviD videos. First, use xvidcore. DLL, xvidvfw. DLL and XviD. INF, and then install XviD. INF, playing with Windows Media Player; and xvidcore. DLL and XviD. ax, register XviD. ax, playing with Windows Media Player; 3. Installing storm audio and video, using the Xvid decoder of storm audio and video, and playing with storm audio and video.

4. Conclusion
It is feasible to store video streams in Xvid format using AVI files. Most players support the AVI format. After the Xvid decoder is installed, you can choose your favorite player to play the storage records of the video monitoring system, stable and easy to use.

Source code: http://download1.csdn.net/down3/20070618/18111759279.rar

 

References
1. http://www.xvid.org/

2. How to compile Xvid with Microsoft Visual C ++ 6.0, David Carroll, 11-23-2003, http://www.discdude.net/xvid/compile.html

3. Working with AVI files, Jonathan Nix, http://www.gamedev.net/reference/programming/features/avifile/

4. Microsoft Visual C ++. NET technology insider (version 6th), translated by Pan aimin, Tsinghua University Press

Introduction
Name: Li qunlin

Gender: male

Title: graduate student

Research Direction: Measuring Technology and Instrument Testing

Zip code: 410082

Address: School of electrical and Information Engineering, Hunan University

Email: gooseli@163.com

 

This article from the csdn blog, reproduced please indicate the source: http://blog.csdn.net/gooseli/archive/2006/08/28/1131210.aspx

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.