CN106817584A - A kind of MJPEG compressions implementation method and FPGA based on FPGA - Google Patents
A kind of MJPEG compressions implementation method and FPGA based on FPGA Download PDFInfo
- Publication number
- CN106817584A CN106817584A CN201611207295.5A CN201611207295A CN106817584A CN 106817584 A CN106817584 A CN 106817584A CN 201611207295 A CN201611207295 A CN 201611207295A CN 106817584 A CN106817584 A CN 106817584A
- Authority
- CN
- China
- Prior art keywords
- video data
- data stream
- fpga
- module
- discrete cosine
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Pending
Links
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04N—PICTORIAL COMMUNICATION, e.g. TELEVISION
- H04N19/00—Methods or arrangements for coding, decoding, compressing or decompressing digital video signals
- H04N19/10—Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding
- H04N19/102—Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding characterised by the element, parameter or selection affected or controlled by the adaptive coding
- H04N19/124—Quantisation
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04N—PICTORIAL COMMUNICATION, e.g. TELEVISION
- H04N19/00—Methods or arrangements for coding, decoding, compressing or decompressing digital video signals
- H04N19/10—Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding
- H04N19/134—Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using adaptive coding characterised by the element, parameter or criterion affecting or controlling the adaptive coding
- H04N19/157—Assigned coding mode, i.e. the coding mode being predefined or preselected to be further used for selection of another element or parameter
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04N—PICTORIAL COMMUNICATION, e.g. TELEVISION
- H04N19/00—Methods or arrangements for coding, decoding, compressing or decompressing digital video signals
- H04N19/48—Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using compressed domain processing techniques other than decoding, e.g. modification of transform coefficients, variable length coding [VLC] data or run-length data
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04N—PICTORIAL COMMUNICATION, e.g. TELEVISION
- H04N19/00—Methods or arrangements for coding, decoding, compressing or decompressing digital video signals
- H04N19/70—Methods or arrangements for coding, decoding, compressing or decompressing digital video signals characterised by syntax aspects related to video coding, e.g. related to compression standards
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04N—PICTORIAL COMMUNICATION, e.g. TELEVISION
- H04N19/00—Methods or arrangements for coding, decoding, compressing or decompressing digital video signals
- H04N19/85—Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using pre-processing or post-processing specially adapted for video compression
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04N—PICTORIAL COMMUNICATION, e.g. TELEVISION
- H04N19/00—Methods or arrangements for coding, decoding, compressing or decompressing digital video signals
- H04N19/90—Methods or arrangements for coding, decoding, compressing or decompressing digital video signals using coding techniques not provided for in groups H04N19/10-H04N19/85, e.g. fractals
- H04N19/91—Entropy coding, e.g. variable length coding [VLC] or arithmetic coding
Landscapes
- Engineering & Computer Science (AREA)
- Multimedia (AREA)
- Signal Processing (AREA)
- Compression Or Coding Systems Of Tv Signals (AREA)
Abstract
Description
技术领域technical field
本发明涉及视频图像处理领域,尤其涉及一种基于FPGA的MJPEG压缩实现方法和FPGA。The invention relates to the field of video image processing, in particular to an FPGA-based MJPEG compression implementation method and the FPGA.
背景技术Background technique
在视频图像传输系统中,大量视频图像数据流的传输称为系统瓶颈;通过MJPEG压缩算法,可以大大减少视频图像数据传输时所需要的存储空间和网络带宽。由于MJPEG压缩算法比较复杂,现有的MJPEG压缩算法一般是采用软件来实现;但是算法的实时性和可扩展性都受到很大限制,尤其是对多路高分辨率、高帧率视频图像数据流压缩处理,如1080p60f、4k60f。In the video image transmission system, the transmission of a large number of video image data streams is called the system bottleneck; through the MJPEG compression algorithm, the storage space and network bandwidth required for video image data transmission can be greatly reduced. Due to the complexity of the MJPEG compression algorithm, the existing MJPEG compression algorithm is generally implemented by software; however, the real-time and scalability of the algorithm are greatly limited, especially for multi-channel high-resolution, high frame rate video image data. Stream compression processing, such as 1080p60f, 4k60f.
发明内容Contents of the invention
本发明旨在解决现有技术MJPEG压缩算法实现实时性和可扩展性差的问题。The invention aims to solve the problem of poor real-time performance and scalability of the MJPEG compression algorithm in the prior art.
为解决上述技术问题,本发明提供一种基于FPGA的MJPEG压缩实现方法,包括:For solving the problems of the technologies described above, the present invention provides a kind of FPGA-based MJPEG compression implementation method, comprising:
对缓存的视频数据流进行离散余弦变换;Discrete cosine transform is performed on the buffered video data stream;
将经过离散余弦变换后的所述视频数据流进行Z变换;Performing Z-transformation on the video data stream after the discrete cosine transform;
将经过Z变换的所述视频数据流进行量化,并对量化后的所述视频数据流进行行程编码;Quantizing the Z-transformed video data stream, and performing run-length encoding on the quantized video data stream;
对经过行程编码后的所述视频数据流按照熵的大小进行编码,压缩所述视频数据流的大小。Encoding the video data stream after length-length coding according to the size of entropy, compressing the size of the video data stream.
可选的,所述对经过行程编码后的所述视频数据流按照熵的大小进行编码包括:对经过行程编码后的所述视频数据流进行哈夫曼编码。Optionally, said encoding the video data stream after the length-length encoding according to the size of entropy includes: performing Huffman encoding on the video data stream after the length-length encoding.
可选的,所述将经过Z变换的视频数据流进行量化包括:Optionally, said quantizing the Z-transformed video data stream includes:
根据预存的量化系数的倒数,对相应的视频数据流进行量化。Quantize the corresponding video data stream according to the reciprocal of the pre-stored quantization coefficient.
可选的,在所述对缓存的视频数据流进行离散余弦变换之前,还包括:Optionally, before performing the discrete cosine transform on the cached video data stream, it also includes:
判断所述缓存的视频数据流是否为YCbCr格式,若否,则将所述视频数据流转成YCbCr格式。Judging whether the buffered video data stream is in YCbCr format, if not, converting the video data stream into YCbCr format.
可选的,在所述对缓存的视频数据流进行离散余弦变换之前,还包括:Optionally, before performing the discrete cosine transform on the cached video data stream, it also includes:
将所述YCbCr格式的视频数据流中的YY分量和CbCr分量分别缓存。Separately buffer the YY component and the CbCr component in the video data stream in the YCbCr format.
本发明还提供一种FPGA,包括:The present invention also provides a kind of FPGA, comprising:
离散余弦变换模块,用于对缓存的视频数据流进行离散余弦变换;Discrete cosine transform module, for carrying out discrete cosine transform to the video data stream of cache;
Z变换模块,用于将经过离散余弦变换后的所述视频数据流进行Z变换;Z transformation module, for performing Z transformation on the video data stream after discrete cosine transformation;
量化模块,用于将经过Z变换的视频数据流进行量化;Quantization module, used for quantizing the video data stream through Z transformation;
第一编码模块,用于对量化后的所述视频数据流进行行程编码;A first encoding module, configured to perform run-length encoding on the quantized video data stream;
第二编码模块,用于对经过行程编码后的所述视频数据流按照熵的大小进行编码,压缩所述视频数据流的大小。The second encoding module is configured to encode the video data stream after the length-length encoding according to the size of entropy, and compress the size of the video data stream.
可选的,所述第二编码模块还用于:对经过行程编码后的所述视频数据流进行哈夫曼编码。Optionally, the second coding module is further configured to: perform Huffman coding on the video data stream after length-length coding.
可选的,所述量化模块还用于:Optionally, the quantization module is also used for:
根据预存的量化系数的倒数,对相应的视频数据流进行量化。Quantize the corresponding video data stream according to the reciprocal of the pre-stored quantization coefficient.
可选的,还包括转换模块,用于:Optionally, a conversion module is also included for:
在所述离散余弦变换模块将所述缓存的视频数据流进行离散余弦变换之前,判断所述视频数据流是否为YCbCr格式,若否,则将所述视频数据流转成YCbCr格式。Before the discrete cosine transform module performs discrete cosine transform on the buffered video data stream, it is judged whether the video data stream is in YCbCr format, and if not, the video data stream is converted into YCbCr format.
可选的,还包括缓存模块,用于将所述YCbCr格式的视频数据流中的YY分量和CbCr分量分别缓存。Optionally, a caching module is also included, configured to respectively cache the YY component and the CbCr component in the video data stream in the YCbCr format.
本发明的有益效果是:The beneficial effects of the present invention are:
本发明实施例提供了一种基于FPGA的MJPEG压缩实现方法和FPGA,对缓存的视频数据流进行离散余弦变换,然后再将视频数据流进行Z变换,将经过Z变换的视频数据流进行量化,然后对视频数据流进行行程编码,以及哈夫曼编码,进一步压缩视频数据流的大小。经过本发明的实施,利用FPGA具有丰富的可编程逻辑资源的特点,在FPGA上实现MJPEG压缩,保证了压缩的实时性和可扩展性。The embodiment of the present invention provides an FPGA-based MJPEG compression implementation method and an FPGA to perform discrete cosine transform on the cached video data stream, and then perform Z-transform on the video data stream to quantize the Z-transformed video data stream, Then run-length encoding and Huffman encoding are performed on the video data stream to further compress the size of the video data stream. Through the implementation of the present invention, the MJPEG compression is realized on the FPGA by utilizing the feature that the FPGA has rich programmable logic resources, which ensures the real-time performance and scalability of the compression.
附图说明Description of drawings
图1为本发明实施例一的基于FPGA的MJPEG压缩方法流程图;Fig. 1 is the MJPEG compression method flowchart based on FPGA of the embodiment of the present invention one;
图2为本发明实施例二的FPGA组成示意图;Fig. 2 is the FPGA composition schematic diagram of embodiment two of the present invention;
图3为本发明实施例三的基于FPGA的MJPEG压缩系统组成示意图。FIG. 3 is a schematic diagram of the composition of the FPGA-based MJPEG compression system according to Embodiment 3 of the present invention.
具体实施方式detailed description
下面通过具体实施方式结合附图对本发明实施例作进一步详细说明。Embodiments of the present invention will be further described in detail below through specific implementation methods in conjunction with the accompanying drawings.
实施例一:Embodiment one:
本实施例提供一种基于FPGA的MJPEG压缩方法,请参见图1,具体包括:The present embodiment provides a kind of MJPEG compression method based on FPGA, please refer to Fig. 1, specifically comprise:
S101、对缓存的视频数据流进行离散余弦变换;S101. Perform discrete cosine transform on the buffered video data stream;
S102、将经过离散余弦变换的视频数据流进行Z变换;S102. Performing Z-transformation on the discrete cosine transformed video data stream;
S103、将经过Z变换的视频数据流进行量化,并对量化后的所述视频数据流进行行程编码,压缩视频数据流的大小。S103. Quantize the Z-transformed video data stream, and perform run-length encoding on the quantized video data stream to compress the size of the video data stream.
从信息论的角度来说,压缩就是去掉信息中的冗余,保留不确定的信息,用一种更接近信息本质的描述来代替原有冗余的描述。压缩主要分为两类:有损压缩和无损压缩,其中,如果丢失个别的数据不会造成太大的影响,这时忽略他们是个好注意,这就是有损压缩。有损压缩广泛应用于动画、声音和图像文件中,典型的代表就是影碟文件格式的MPEG、音乐文件格式mp3和图像文件格式jpg。本实施例中的MJPEG同样是一种有损压缩。在另一些情况中,则可能会要求压缩数据必须准确无误,便有了无损压缩格式,比如常见的zip、rar等等。From the perspective of information theory, compression is to remove redundancy in information, retain uncertain information, and replace the original redundant description with a description that is closer to the essence of information. Compression is mainly divided into two categories: lossy compression and lossless compression. Among them, if the loss of individual data does not cause much impact, it is a good idea to ignore them at this time. This is lossy compression. Lossy compression is widely used in animation, sound and image files, typical representatives are MPEG in video disc file format, mp3 in music file format and jpg in image file format. MJPEG in this embodiment is also a kind of lossy compression. In other cases, it may be required that the compressed data must be accurate, and then there are lossless compression formats, such as common zip, rar, and so on.
在本实施例中,由于MJPEG压缩方法是以宏块MB=8*8bits为基本单元来进行的,因此对输入的视频数据流需要先进行缓存。输入的视频数据流按照地址递增顺序依次进行缓存,在本实施例中,以输入视频流格式为1080p60f,采样率YCbCr为4:2:2为例,缓存的大小应该为1920*8=15360@24bits。在按照地址递增顺序将将视频数据流进行缓存时,当写地址超过13455后即写满两个MB,即可以开始缓存的视频数据流的读取。然后,当写地址超过15359之后,即写满了8行,则按照原有MB读地址写入数据。且写地址与读地址之间应该保持一定程度上的间隙,避免缓存被写满而导致数据丢失。其中,间隙GAP的范围可以设定为大于等于128。In this embodiment, since the MJPEG compression method uses macroblock MB=8*8bits as the basic unit, the input video data stream needs to be buffered first. The input video data stream is cached sequentially according to the increasing order of addresses. In this embodiment, the input video stream format is 1080p60f, and the sampling rate YCbCr is 4:2:2 as an example. The size of the cache should be 1920*8=15360@ 24bits. When the video data stream is cached according to the increasing order of addresses, when the write address exceeds 13455, two MB are filled, and the buffered video data stream can be read. Then, when the write address exceeds 15359, that is, 8 rows are filled, write data according to the original MB read address. And there should be a certain gap between the write address and the read address to avoid data loss caused by the cache being filled. Wherein, the range of the gap GAP can be set to be greater than or equal to 128.
因此,当缓存数据超过了13455之后,就可以继续进行后续的处理过程,后续各处理流程可以在单位时间即MB内处理完输入的MB数据,以满足实时处理的要求。Therefore, when the cached data exceeds 13455, the subsequent processing can be continued, and each subsequent processing flow can process the input MB data within unit time, that is, MB, to meet the requirement of real-time processing.
在本实施例中,对缓存的视频数据流进行离散余弦变换。视频图像数据相互之间具有一定的相关性,这种相关性在时域观测不够直观,通过离散余弦变换DCT,可以去掉其相关性,从频域来观测视频图像数据。视频图像数据经过DCT变换后的输出频谱是二维的,左上角区域为低频区,右下角区域为高频区。In this embodiment, discrete cosine transform is performed on the buffered video data stream. The video image data has a certain correlation with each other. This correlation is not intuitive enough to observe in the time domain. Through the discrete cosine transform (DCT), the correlation can be removed, and the video image data can be observed from the frequency domain. The output spectrum of video image data after DCT transformation is two-dimensional, the area in the upper left corner is the low frequency area, and the area in the lower right corner is the high frequency area.
之后,经过DCT变换之后,再对视频数据流进行Z变换,Z变换是将DCT变换的输出按Z形扫描,将低频数据串接起来。将经过DCT变换的视频数据流进行Z变换,以一个MB为基本单元,采用乒乓存储的方式,先顺序写入,再按特定地址读出即可。Afterwards, after the DCT transformation, Z transformation is performed on the video data stream. The Z transformation is to scan the output of the DCT transformation in a Z-shape and concatenate the low-frequency data. Z-transform the DCT-transformed video data stream, take one MB as the basic unit, adopt the ping-pong storage method, write in order first, and then read out according to a specific address.
然后,对经过Z变换的视频数据流进行量化。量化后剩下的都是低频区数据,高频区数据大多变成0,基于此可以进行进一步的图像压缩过程。量化等级0~255一共256个,在本实施例中,将经过Z变换的视频数据流进行量化可以包括:根据预存的量化系数的倒数,对对应的视频数据流进行量化。量化时,将量化系数的倒数与经过Z变换的视频数据流相乘。其中,不同地址的视频数据流,其相应的量化系数也是不同的。Then, quantize the Z-transformed video data stream. After quantization, all the data in the low-frequency area is left, and most of the data in the high-frequency area becomes 0. Based on this, further image compression can be performed. There are 256 quantization levels ranging from 0 to 255. In this embodiment, quantizing the Z-transformed video data stream may include: quantizing the corresponding video data stream according to the reciprocal of the pre-stored quantization coefficient. During quantization, the inverse of the quantization coefficient is multiplied by the Z-transformed video data stream. Wherein, the corresponding quantization coefficients of the video data streams at different addresses are also different.
经过量化后的视频数据流会出现大量为零的数据,即大量的连零串,对于连零串的信息,仅需要记录其为零的个数即可,这样可以很大程度的减小数据传输带宽。在本实施例中,通过行程编码(Run-Length Encoding,RLE),就可以实现将连续全零的信息仅记录其个数,从而达到压缩视频数据流的大小的目的。The quantized video data stream will have a large number of zero data, that is, a large number of zero strings. For the zero string information, only the number of zeros needs to be recorded, which can greatly reduce the data transmission bandwidth. In this embodiment, through Run-Length Encoding (RLE), it is possible to record only the number of consecutive all-zero information, thereby achieving the purpose of compressing the size of the video data stream.
此外,在本实施例中,在对量化后的视频数据流进行行程编码之后,还可以包括:对经过行程编码后的视频数据流按照熵的大小进行编码。为了进一步减小数据传输带宽,按照信息量的大小为输入视频数据流分配码字,这样编码后得到的视频数据流传输带宽可以降到更低。在经过RLE编码之后,按照熵的大小进行编码,即用长码编码熵较大的数据,用短码编码熵较小的数据。在本实施例中,可以采用哈夫曼编码进行熵编码,哈夫曼编码所需要的码字可以预先存储在码表中。此外,还可以采用算术编码等其他的压缩编码方式。In addition, in this embodiment, after performing run-length encoding on the quantized video data stream, it may further include: encoding the video data stream after the run-length encoding according to the magnitude of entropy. In order to further reduce the data transmission bandwidth, codewords are assigned to the input video data stream according to the amount of information, so that the video data stream transmission bandwidth obtained after encoding can be reduced to a lower level. After RLE encoding, encoding is performed according to the size of entropy, that is, long codes are used to encode data with larger entropy, and short codes are used to encode data with smaller entropy. In this embodiment, Huffman coding can be used for entropy coding, and the codewords required by Huffman coding can be stored in a code table in advance. In addition, other compression coding methods such as arithmetic coding may also be used.
此外,对哈夫曼编码后的码流进行bit padding和BYTE Stuffer,同时添加JFIFGEN Header。In addition, bit padding and BYTE Stuffer are performed on the code stream after Huffman encoding, and JFIFGEN Header is added at the same time.
此外,在本实施例中,在对缓存的视频数据流进行离散余弦变换之前,还可以包括:判断缓存的视频数据流是否为YCbCr格式,若否,则将视频数据流转成YCbCr格式。In addition, in this embodiment, before performing discrete cosine transform on the buffered video data stream, it may also include: judging whether the buffered video data stream is in YCbCr format, and if not, converting the video data stream into YCbCr format.
当输出视频数据流的采样率为4:2:2时,为了并行处理视频流中的YY和Cb和Cr分量,可以在对缓存的视频数据流进行离散余弦变换之前,将YCbCr格式的视频数据流中的YY分量和CbCr分量分别缓存。在此之后,就可以将YY分量和CbCr分量分别进行处理,从而实现了视频数据流的并行处理。When the sampling rate of the output video data stream is 4:2:2, in order to process the YY, Cb and Cr components in the video stream in parallel, before performing discrete cosine transform on the buffered video data stream, the video data in YCbCr format The YY component and CbCr component in the stream are buffered separately. After that, the YY component and the CbCr component can be processed separately, thereby realizing the parallel processing of the video data stream.
本实施例提供了一种基于FPGA的MJPEG压缩实现方法,对缓存的视频数据流进行离散余弦变换,然后再将视频数据流进行Z变换,将经过Z变换的视频数据流进行量化,然后对视频数据流进行行程编码、哈夫曼编码,进一步压缩视频数据流的大小。经过本发明的实施,利用FPGA具有丰富的可编程资源的特点,在FPGA上实现MJPEG压缩,保证了压缩的实时性和可扩展性。This embodiment provides a method for implementing MJPEG compression based on FPGA, which performs discrete cosine transform on the cached video data stream, then performs Z transform on the video data stream, quantizes the Z-transformed video data stream, and then converts the video data stream Run-length encoding and Huffman encoding are performed on the data stream to further compress the size of the video data stream. Through the implementation of the present invention, the MJPEG compression is realized on the FPGA by utilizing the feature of rich programmable resources of the FPGA, which ensures the real-time performance and scalability of the compression.
第二实施例second embodiment
本实施例提供一种FPGA,请参见图1,具体包括:This embodiment provides an FPGA, please refer to Figure 1, specifically including:
离散余弦变换模块101,用于对缓存的视频数据流进行离散余弦变换;Discrete cosine transform module 101, is used for carrying out discrete cosine transform to the video data stream of cache;
Z变换模块102,用于将经过离散余弦变换后的视频数据流进行Z变换;Z transformation module 102, for carrying out Z transformation to the video data stream after discrete cosine transformation;
量化模块103,用于将经过Z变换的视频数据流进行量化;A quantization module 103, configured to quantize the Z-transformed video data stream;
第一编码模块104,用于对量化后的视频数据流进行行程编码,压缩视频数据流的大小。The first encoding module 104 is configured to perform run-length encoding on the quantized video data stream to compress the size of the video data stream.
在本实施例中,由于MJPEG压缩方法是以宏块MB=8*8bits为基本单元来进行的,因此对输入的视频数据流需要先进行缓存。输入的视频数据流按照地址递增顺序依次进行缓存,在本实施例中,以输入视频流格式为1080p60f,采样率YCbCr为4:2:2为例,缓存的大小应该为1920*8=15360@24bits。在按照地址递增顺序将将视频数据流进行缓存时,当写地址超过13455后即写满两个MB,即可以开始缓存的视频数据流的读取。然后,当写地址超过15359之后,即写满了8行,则按照原有MB读地址写入数据。且写地址与读地址之间应该保持一定程度上的间隙,避免缓存被写满而导致数据丢失。其中,间隙GAP的范围可以设定为大于等于128。In this embodiment, since the MJPEG compression method uses macroblock MB=8*8bits as the basic unit, the input video data stream needs to be buffered first. The input video data stream is cached sequentially according to the increasing order of addresses. In this embodiment, the input video stream format is 1080p60f, and the sampling rate YCbCr is 4:2:2 as an example. The size of the cache should be 1920*8=15360@ 24bits. When the video data stream is cached according to the increasing order of addresses, when the write address exceeds 13455, two MB are filled, and the buffered video data stream can be read. Then, when the write address exceeds 15359, that is, 8 rows are filled, write data according to the original MB read address. And there should be a certain gap between the write address and the read address to avoid data loss caused by the cache being filled. Wherein, the range of the gap GAP can be set to be greater than or equal to 128.
因此,当缓存数据超过了13455之后,就可以继续进行后续的处理过程,后续各处理流程可以在单位时间即MB内处理完输入的MB数据,以满足实时处理的要求。Therefore, when the cached data exceeds 13455, the subsequent processing can be continued, and each subsequent processing flow can process the input MB data within unit time, that is, MB, to meet the requirement of real-time processing.
在本实施例中,对缓存的视频数据流进行离散余弦变换。视频图像数据相互之间具有一定的相关性,这种相关性在时域观测不够直观,通过离散余弦变换DCT,可以去掉其相关性,从频域来观测视频图像数据。视频图像数据经过DCT变换后的输出频谱是二维的,左上角区域为低频区,右下角区域为高频区。In this embodiment, discrete cosine transform is performed on the buffered video data stream. The video image data has a certain correlation with each other. This correlation is not intuitive enough to observe in the time domain. Through the discrete cosine transform (DCT), the correlation can be removed, and the video image data can be observed from the frequency domain. The output spectrum of video image data after DCT transformation is two-dimensional, the area in the upper left corner is the low frequency area, and the area in the lower right corner is the high frequency area.
之后,经过DCT变换之后,再对视频数据流进行Z变换,Z变换是将DCT变换的输出按Z形扫描,将低频数据串接起来。将经过DCT变换的视频数据流进行Z变换,以一个MB为基本单元,采用乒乓存储的方式,先顺序写入,再按特定地址读出即可。Afterwards, after the DCT transformation, Z transformation is performed on the video data stream. The Z transformation is to scan the output of the DCT transformation in a Z-shape and concatenate the low-frequency data. Z-transform the DCT-transformed video data stream, take one MB as the basic unit, adopt the ping-pong storage method, write in order first, and then read out according to a specific address.
然后,对经过Z变换的视频数据流进行量化。量化后剩下的都是低频区数据,高频区数据大多变成0,基于此可以进行进一步的图像压缩过程。量化等级0~255一共256个,在本实施例中,量化模块103还可以用于:根据预存的量化系数的倒数,对对应的视频数据流进行量化。量化时,将量化系数的倒数与经过Z变换的视频数据流相乘。其中,不同地址的视频数据流,其相应的量化系数也是不同的。Then, quantize the Z-transformed video data stream. After quantization, all the data in the low-frequency area is left, and most of the data in the high-frequency area becomes 0. Based on this, further image compression can be performed. There are 256 quantization levels 0-255 in total. In this embodiment, the quantization module 103 can also be used to quantize the corresponding video data stream according to the reciprocal of the pre-stored quantization coefficient. During quantization, the inverse of the quantization coefficient is multiplied by the Z-transformed video data stream. Wherein, the corresponding quantization coefficients of the video data streams at different addresses are also different.
经过量化后的视频数据流会出现大量为零的数据,即大量的连零串,对于连零串的信息,仅需要记录其为零的个数即可,这样可以很大程度的减小数据传输带宽。在本实施例中,通过行程编码RLE,就可以实现将连续全零的信息仅记录其个数,从而达到压缩视频数据流的大小的目的。The quantized video data stream will have a large number of zero data, that is, a large number of zero strings. For the zero string information, only the number of zeros needs to be recorded, which can greatly reduce the data transmission bandwidth. In this embodiment, through the length-length encoding RLE, only the number of consecutive all-zero information can be recorded, thereby achieving the purpose of compressing the size of the video data stream.
此外,在本实施例中,还可以包括第二编码模块105,用于对经过行程编码后的视频数据流按照熵的大小进行编码。为了进一步减小数据传输带宽,按照信息量的大小为输入视频数据流分配码字,这样编码后得到的视频数据流传输带宽可以降到更低。在经过RLE编码之后,按照熵的大小进行编码,即用长码编码熵较大的数据,用短码编码熵较小的数据。在本实施例中,可以采用哈夫曼编码进行熵编码,哈夫曼编码所需要的码字可以预先存储在码表中。In addition, in this embodiment, a second encoding module 105 may also be included, configured to encode the length-length encoded video data stream according to the size of entropy. In order to further reduce the data transmission bandwidth, codewords are assigned to the input video data stream according to the amount of information, so that the video data stream transmission bandwidth obtained after encoding can be reduced to a lower level. After RLE encoding, encoding is performed according to the size of entropy, that is, long codes are used to encode data with larger entropy, and short codes are used to encode data with smaller entropy. In this embodiment, Huffman coding can be used for entropy coding, and the codewords required by Huffman coding can be stored in a code table in advance.
此外,对哈夫曼编码后的码流bit padding和BYTE Stuffer同时添加JFIF GENHeader,从而进一步完善了整个视频数据流的MJPEG压缩。In addition, JFIF GENHeader is added to the bit padding and BYTE Stuffer of the Huffman-encoded code stream, thereby further improving the MJPEG compression of the entire video data stream.
此外,在本实施例中,还可以包括转换模块106,用于在对缓存的视频数据流进行离散余弦变换之前,判断缓存的视频数据流是否为YCbCr格式,若否,则将视频数据流转成YCbCr格式。In addition, in this embodiment, a conversion module 106 may also be included, which is used to determine whether the buffered video data stream is in the YCbCr format before performing discrete cosine transform on the buffered video data stream, and if not, convert the video data stream into YCbCr format.
当输出视频数据流的采样率为4:2:2时,为了并行处理视频流中的YY和Cb和Cr分量,在本实施例中还可以包括缓存模块107,用于将YCbCr格式的视频数据流中的YY分量和CbCr分量分别缓存。在此之后,就可以将YY分量和CbCr分量分别进行处理,从而实现了视频数据流的并行处理。When the sampling rate of the output video data stream is 4:2:2, in order to process the YY and Cb and Cr components in the video stream in parallel, a cache module 107 can also be included in this embodiment for converting the video data in the YCbCr format The YY component and CbCr component in the stream are buffered separately. After that, the YY component and the CbCr component can be processed separately, thereby realizing the parallel processing of the video data stream.
本实施例提供了一种FPGA,对缓存的视频数据流进行离散余弦变换,然后再将视频数据流进行Z变换,将经过Z变换的视频数据流进行量化,然后对视频数据流进行行程编码和哈夫曼编码,进一步压缩视频数据流的大小。经过本发明的实施,利用FPGA具有丰富的可编程资源的特点,在FPGA上实现MJPEG压缩,保证了压缩的实时性和可扩展性。This embodiment provides an FPGA, which performs discrete cosine transform on the buffered video data stream, then performs Z-transform on the video data stream, quantizes the Z-transformed video data stream, and then performs run-length encoding and Huffman coding further compresses the size of the video data stream. Through the implementation of the present invention, the MJPEG compression is realized on the FPGA by utilizing the feature of rich programmable resources of the FPGA, which ensures the real-time performance and scalability of the compression.
实施例三Embodiment three
本实施例提供一种基于FPGA的MJPEG压缩系统,请参考图3,包括:The present embodiment provides a kind of MJPEG compression system based on FPGA, please refer to Fig. 3, comprise:
1)缓存模块1071) cache module 107
由于MJPEG压缩算法是以宏块MB=8*8bits为基本单元进行处理的,因此对输入视频流需要先进行缓存;缓存大小为1920*8@24bits=15360@24bits。Since the MJPEG compression algorithm uses macroblock MB=8*8bits as the basic unit for processing, the input video stream needs to be cached first; the cache size is 1920*8@24bits=15360@24bits.
输入视频流首先按地址递增顺序依次缓存到缓存模块107,当缓存模块107写地址超过13455后即已写满2个MB,后续模块开始按MB读取数据;当缓存模块107写地址超过15359后即写满8行,则按照原有MB读地址顺序写入数据,且写地址与读地址必须保持GAP>=128间隙,避免输入缓存模块107被充满导致数据丢失。The input video stream is first buffered to the cache module 107 in order of increasing address, and when the write address of the cache module 107 exceeds 13455, 2 MB is full, and the subsequent modules start to read data by MB; when the write address of the cache module 107 exceeds 15359 That is, if 8 lines are filled, write data in the order of the original MB read address, and the write address and read address must maintain a gap of GAP>=128 to avoid data loss caused by the input buffer module 107 being filled.
由上述可知,当缓存模块107填充数据超过13455后,MJPEG后续的核心运算模块等即可以开始流水处理;后续各子模块在单位时间即MB内处理完输入的MB数据,以满足实时处理的要求。As can be seen from the above, when the cache module 107 is filled with data exceeding 13455, the subsequent core operation modules of MJPEG, etc. can start pipeline processing; subsequent sub-modules process the input MB data within unit time, that is, MB, to meet the requirements of real-time processing .
2)转换模块1062) conversion module 106
该模块主要实现将RGB格式的视频数据流转换成YCbCr格式的视频数据流,如果输入为YCbCr格式,则该模块可以bypass。This module mainly converts the video data stream in RGB format into the video data stream in YCbCr format. If the input is in YCbCr format, this module can bypass.
3)DCT模块1013) DCT module 101
由于输入视频流采样率为4:2:2,为了并行处理视频流中的YY和CbCr分量,缓存模块107需要2个,一个用于缓存YY分量,另一个用于CbCr分量。当缓存超过2个MB后,以1个MB为基本单元,按行扫描读取Y分量的值,进行DCT变换;以2个MB为基本单元,按行扫描2次依次读取Cb值和Cr值,进行DCT变换;这样在2个MB即128个时钟周期内,DCT模块101可以并行处理YCbCr4:2:2。Since the sampling rate of the input video stream is 4:2:2, in order to process the YY and CbCr components in the video stream in parallel, two cache modules 107 are needed, one for caching the YY component and the other for the CbCr component. When the cache exceeds 2 MB, take 1 MB as the basic unit, read the value of the Y component by row scanning, and perform DCT transformation; take 2 MB as the basic unit, and read the Cb value and Cr by row scanning twice value, DCT conversion is performed; in this way, within 2 MB, that is, 128 clock cycles, the DCT module 101 can process YCbCr4:2:2 in parallel.
4)Z变换模块1024) Z transformation module 102
对DCT模块101输出的MB进行Z变换,以1个MB为基本单元,采用乒乓存储的方式,先顺序写入,在按特定地址读出即可。Perform Z transformation on the MB output by the DCT module 101, take 1 MB as the basic unit, adopt the ping-pong storage method, first write in order, and then read out according to a specific address.
5)量化模块1035) quantization module 103
量化等级0~255共256个,Q值存储模块存储的是量化系数的倒数;在进行Q量化时,先按照预定的量化等级即读地址,读出量化系数,然后与输入数据相乘即可。There are 256 quantization levels from 0 to 255, and the Q value storage module stores the reciprocal of the quantization coefficient; when performing Q quantization, first read the address according to the predetermined quantization level, read out the quantization coefficient, and then multiply it with the input data .
6)第一编码模块1046) The first coding module 104
经过量化后的视频流会出现大量连零串,对连零串信息只需要记录其个数即可,这样可以减小数据传输带宽;RLE编码以MB为基本单元,输出为变长的MB。The quantized video stream will have a large number of consecutive zeros, and the number of consecutive zeros only needs to be recorded, which can reduce the data transmission bandwidth; RLE encoding uses MB as the basic unit, and the output is variable-length MB.
7)轮询模块1087) Polling module 108
为满足实时处理的要求,核心运算模块采用的是全速流水处理,这样第一编码模块104输出的变长MB共2路:YY和CbCr;在进入第二编码模块105前,需要将并行数据流转换为串行数据流。In order to meet the requirements of real-time processing, the core computing module adopts full-speed pipeline processing, so that the variable-length MB output by the first encoding module 104 has 2 paths: YY and CbCr; before entering the second encoding module 105, parallel data streams need to be Convert to a serial data stream.
8)第二编码模块1058) The second encoding module 105
为进一步减小数据传输带宽,需要对轮询模块输出的串行变长MB进行熵编码,即哈夫曼编码,按照信息量的大小为输入视频数据流分配码字,这样编码后得到的视频数据流传输带宽降到最低;哈夫曼编码所需要的码字预先存储在码表中。In order to further reduce the data transmission bandwidth, it is necessary to perform entropy coding on the serial variable-length MB output by the polling module, that is, Huffman coding, and allocate codewords for the input video data stream according to the size of the information volume, so that the video obtained after coding The data stream transmission bandwidth is reduced to the minimum; the code words required by Huffman coding are pre-stored in the code table.
9)字节填充模块109&JFIF GEN模块1109) Byte stuffing module 109 & JFIF GEN module 110
对哈夫曼编码后的码流进行bit padding和BYTE Stuffer同时添加JFIF GENHeader,即完成了整个输入视频流的MJPEG压缩。Perform bit padding and BYTE Stuffer on the Huffman-encoded code stream and add JFIF GENHeader at the same time, which completes the MJPEG compression of the entire input video stream.
上述简述以视频流1080p60f采样率4:2:2为例,如果采样率为4:4:4,则只需要进行相应的扩展即可;如果输入视频流为RGB格式,只需要打开转换模块106即可。The above brief description takes the video stream 1080p60f sampling rate 4:2:2 as an example. If the sampling rate is 4:4:4, you only need to expand accordingly; if the input video stream is in RGB format, you only need to open the conversion module 106 is enough.
显然,本领域的技术人员应该明白,上述本发明实施例的各模块或各步骤可以用通用的计算装置来实现,它们可以集中在单个的计算装置上,或者分布在多个计算装置所组成的网络上,可选地,它们可以用计算装置可执行的程序代码来实现,从而,可以将它们存储在计算机存储介质(ROM/RAM、磁碟、光盘)中由计算装置来执行,并且在某些情况下,可以以不同于此处的顺序执行所示出或描述的步骤,或者将它们分别制作成各个集成电路模块,或者将它们中的多个模块或步骤制作成单个集成电路模块来实现。所以,本发明不限制于任何特定的硬件和软件结合。Obviously, those skilled in the art should understand that each module or each step of the above-mentioned embodiments of the present invention can be realized by a general-purpose computing device, and they can be concentrated on a single computing device, or distributed across multiple computing devices. Optionally, they can be implemented with executable program codes of computing devices, thus, they can be stored in computer storage media (ROM/RAM, magnetic disks, optical disks) to be executed by computing devices, and in some In some cases, the steps shown or described can be performed in a different order than here, or they can be fabricated into individual integrated circuit modules, or multiple modules or steps can be fabricated into a single integrated circuit module for implementation. . Therefore, the present invention is not limited to any specific combination of hardware and software.
以上内容是结合具体的实施方式对本发明实施例所作的进一步详细说明,不能认定本发明的具体实施只局限于这些说明。对于本发明所属技术领域的普通技术人员来说,在不脱离本发明构思的前提下,还可以做出若干简单推演或替换,都应当视为属于本发明的保护范围。The above content is a further detailed description of the embodiments of the present invention in conjunction with specific implementation modes, and it cannot be assumed that the specific implementation of the present invention is limited to these descriptions. For those of ordinary skill in the technical field of the present invention, without departing from the concept of the present invention, some simple deduction or replacement can be made, which should be regarded as belonging to the protection scope of the present invention.
Claims (10)
Priority Applications (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201611207295.5A CN106817584A (en) | 2016-12-23 | 2016-12-23 | A kind of MJPEG compressions implementation method and FPGA based on FPGA |
Applications Claiming Priority (1)
| Application Number | Priority Date | Filing Date | Title |
|---|---|---|---|
| CN201611207295.5A CN106817584A (en) | 2016-12-23 | 2016-12-23 | A kind of MJPEG compressions implementation method and FPGA based on FPGA |
Publications (1)
| Publication Number | Publication Date |
|---|---|
| CN106817584A true CN106817584A (en) | 2017-06-09 |
Family
ID=59110640
Family Applications (1)
| Application Number | Title | Priority Date | Filing Date |
|---|---|---|---|
| CN201611207295.5A Pending CN106817584A (en) | 2016-12-23 | 2016-12-23 | A kind of MJPEG compressions implementation method and FPGA based on FPGA |
Country Status (1)
| Country | Link |
|---|---|
| CN (1) | CN106817584A (en) |
Cited By (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN108832935A (en) * | 2018-05-31 | 2018-11-16 | 郑州云海信息技术有限公司 | A kind of RLE algorithm implementation method, system, equipment and computer storage medium |
| CN110313178A (en) * | 2018-04-04 | 2019-10-08 | 深圳市大疆创新科技有限公司 | Code device and system |
| CN111726634A (en) * | 2020-07-01 | 2020-09-29 | 成都傅立叶电子科技有限公司 | High-resolution video image compression transmission method and system based on FPGA |
| CN113365016A (en) * | 2020-03-05 | 2021-09-07 | 阿里巴巴集团控股有限公司 | Real-time map image data acquisition system and method |
| CN114157871A (en) * | 2021-11-25 | 2022-03-08 | 北京澜景科技有限公司 | Video encoding and decoding method, device, equipment and storage medium |
Citations (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| KR100746484B1 (en) * | 2006-11-02 | 2007-08-03 | 김응수 | Remote water quality monitoring system using water flea activity measurement using CD camera |
| CN101094401A (en) * | 2006-06-23 | 2007-12-26 | 深圳安凯微电子技术有限公司 | Image compression / decompression method and system |
| US20090003690A1 (en) * | 2007-06-28 | 2009-01-01 | Yueguang Jiao | Method and system for processing image at high speed |
| CN201893860U (en) * | 2010-11-30 | 2011-07-06 | 杭州荣耀科技有限公司 | High definition film camera |
| CN104883518A (en) * | 2015-05-11 | 2015-09-02 | 杭州奕霖传感科技有限公司 | Low-cost small-sized thermal infrared imager |
-
2016
- 2016-12-23 CN CN201611207295.5A patent/CN106817584A/en active Pending
Patent Citations (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN101094401A (en) * | 2006-06-23 | 2007-12-26 | 深圳安凯微电子技术有限公司 | Image compression / decompression method and system |
| KR100746484B1 (en) * | 2006-11-02 | 2007-08-03 | 김응수 | Remote water quality monitoring system using water flea activity measurement using CD camera |
| US20090003690A1 (en) * | 2007-06-28 | 2009-01-01 | Yueguang Jiao | Method and system for processing image at high speed |
| CN201893860U (en) * | 2010-11-30 | 2011-07-06 | 杭州荣耀科技有限公司 | High definition film camera |
| CN104883518A (en) * | 2015-05-11 | 2015-09-02 | 杭州奕霖传感科技有限公司 | Low-cost small-sized thermal infrared imager |
Non-Patent Citations (1)
| Title |
|---|
| 包宋建等: "基于XC2S600E的MJPEG编码器研究与实现", 《重庆文理学院学报(自然科学版)》 * |
Cited By (5)
| Publication number | Priority date | Publication date | Assignee | Title |
|---|---|---|---|---|
| CN110313178A (en) * | 2018-04-04 | 2019-10-08 | 深圳市大疆创新科技有限公司 | Code device and system |
| CN108832935A (en) * | 2018-05-31 | 2018-11-16 | 郑州云海信息技术有限公司 | A kind of RLE algorithm implementation method, system, equipment and computer storage medium |
| CN113365016A (en) * | 2020-03-05 | 2021-09-07 | 阿里巴巴集团控股有限公司 | Real-time map image data acquisition system and method |
| CN111726634A (en) * | 2020-07-01 | 2020-09-29 | 成都傅立叶电子科技有限公司 | High-resolution video image compression transmission method and system based on FPGA |
| CN114157871A (en) * | 2021-11-25 | 2022-03-08 | 北京澜景科技有限公司 | Video encoding and decoding method, device, equipment and storage medium |
Similar Documents
| Publication | Publication Date | Title |
|---|---|---|
| TWI431948B (en) | Efficient coding and decoding of transform blocks | |
| US8874531B2 (en) | Methods and systems for encoding/decoding files and transmissions thereof | |
| RU2433479C2 (en) | Adaptive coding and decoding wide-range coefficients | |
| US8578058B2 (en) | Real-time multi-block lossless recompression | |
| CN106817584A (en) | A kind of MJPEG compressions implementation method and FPGA based on FPGA | |
| CN1366778A (en) | Video compression | |
| CN103873877A (en) | Image transmission method and device for remote desktop | |
| BR112021001807A2 (en) | entropy encoding for signal enhancement encoding | |
| TW201406161A (en) | Improving decoder performance through quantization control | |
| CN104704825A (en) | Lossless compression of segmented image data | |
| US8682091B2 (en) | Real-time image compression | |
| Mahmud | An improved data compression method for general data | |
| CN112822488B (en) | Video encoding and decoding system, method, device, terminal and medium based on block recombination | |
| JP7147075B2 (en) | Compression across multiple images | |
| JP2014521273A (en) | Method and apparatus for encoding an image | |
| TW201528786A (en) | Decoder, encoder, and the method for using the same | |
| Ravi et al. | A study of various Data Compression Techniques | |
| Rao et al. | Evaluation of lossless compression techniques | |
| Hussin et al. | A comparative study on improvement of image compression method using hybrid DCT-DWT techniques with Huffman encoding for wireless sensor network application | |
| CN100399833C (en) | High-speed image compression device using last non-zero detection circuit | |
| CN104219521A (en) | Image compression architecture and method for reducing memory requirement | |
| CN101777366B (en) | Stroke compression method and device based on RLE principle | |
| Thakur et al. | Design of image compression algorithm using MATLAB | |
| CN100391250C (en) | Progressive joint image expert group decoding device and method | |
| CN104702952B (en) | A kind of image data compression method |
Legal Events
| Date | Code | Title | Description |
|---|---|---|---|
| PB01 | Publication | ||
| PB01 | Publication | ||
| SE01 | Entry into force of request for substantive examination | ||
| SE01 | Entry into force of request for substantive examination | ||
| RJ01 | Rejection of invention patent application after publication | ||
| RJ01 | Rejection of invention patent application after publication |
Application publication date: 20170609 |