Video coding method and device, video decoding method and device and terminal equipment
By converting video data to MJPEG format and adding decoding parameters, the method allows efficient video encoding and decoding on resource-constrained devices, addressing the high-cost and high-power consumption issues of existing standards.
Patent Information
- Application Number
- CN202411090426.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-09
- Publication Date
- 2024-12-03
AI Technical Summary
Existing video coding standards require high-performance CPUs and GPUs for high-resolution and high-frame-rate video processing, leading to increased hardware costs and power consumption, limiting the accessibility and popularity of video applications.
Convert video data to MJPEG format using the libjpeg library and add a private message header with decoding parameters, allowing encoding and decoding on devices with limited resources without losing picture quality.
Enables video encoding and decoding on devices with limited resources while maintaining video quality, reducing hardware costs and power consumption.
Smart Images

Figure CN119071492A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of signal processing, and in particular to a method for video encoding and decoding. Background Art
[0002] In recent years, with the increasing demand for video compression efficiency, existing video coding standards (such as VP8, VP9, H.264, H.265) have adopted more complex coding technologies, which are more computationally intensive, especially when processing high-resolution and high-frame-rate video content, requiring higher-performance CPUs and GPUs. However, high-performance CPUs and GPUs not only increase hardware costs, but also increase the power consumption of encoding and decoding.
[0003] In this context, with the growth of computer users and the development of emerging technologies, reducing the reliance on high-performance CPUs and GPUs has become a development direction. By optimizing encoding algorithms and using more efficient computing methods, video encoding and decoding can be run using software on ordinary computers, thereby reducing hardware costs and power consumption, improving the popularity and accessibility of video encoding and decoding, and further promoting the application and development of video applications in a wider range of fields. Summary of the invention
[0004] The embodiments of the present invention provide a method, apparatus and terminal device for video encoding and video decoding, which can perform video encoding and video decoding on a device with limited resources, reduce hardware cost and power consumption, and thus improve the popularity and accessibility of video applications.
[0005] An embodiment of the present invention provides a video encoding method, including:
[0006] Acquire first video data to be encoded;
[0007] Converting the first video data to be encoded into first MJPEG format video data;
[0008] A private first message header is added before the first MJPEG format video data to generate encoded video data; wherein, the first message header is a decoding parameter when decoding the data, and the first message header includes eight bytes, the first and second bytes of the first message header are the first video header identifier, the third and fourth bytes of the first message header are the first video width, the fifth and sixth bytes of the first message header are the first video height, and the seventh and eighth bytes of the first message header are the first video data MJPEG length.
[0009] Further, converting the first video data to be encoded into first MJPEG format video data includes:
[0010] Converting the first video data to be encoded into first YUV420 format video data;
[0011] Convert the first YUV420 format video data into the first RGB888 format video data by using a conversion algorithm;
[0012] The first RGB888 format video data is converted into the first MJPEG format video data through the libjpeg library.
[0013] Furthermore, information of the first video header identifier, the first video width, the first video height, and the first video data MJPEG length is filled into the first message header in the following manner:
[0014] Fill the preset byte information into the first and second bytes of the message header;
[0015] From the first video data, obtain byte information of the first video width and byte information of the first video height;
[0016] Fill the byte information of the first video width into the third and fourth bytes of the message header;
[0017] Fill the high byte information of the first video into the fifth and sixth bytes of the message header;
[0018] Obtain the number of bytes of the first MJPEG data from the first MJPEG format video data;
[0019] The number of bytes of the first MJPEG data is used as the MJPEG length of the first video data, and is filled into the seventh and eighth bytes of the first message header.
[0020] Based on the above method embodiment, the present invention provides a corresponding device embodiment, including: a module for acquiring video data to be encoded, a module for converting the first video data format, and a video encoding module;
[0021] A module for acquiring video data to be encoded, used for acquiring first video data to be encoded;
[0022] A first video data format conversion module, used for converting the first video data to be encoded into first MJPEG format video data;
[0023] The video encoding module is used to add a private first message header before the first MJPEG format video data to generate encoded video data; wherein, the first message header is a decoding parameter when decoding the data, and the first message header includes eight bytes, the first and second bytes of the first message header are the first video header identifier, the third and fourth bytes of the first message header are the first video width, the fifth and sixth bytes of the first message header are the first video height, and the seventh and eighth bytes of the first message header are the first video data MJPEG length.
[0024] Based on the above-mentioned method embodiment, the present invention provides a corresponding terminal device embodiment, including: a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor. When the processor executes the computer program, the steps of the video encoding method as described in the present invention are implemented.
[0025] An embodiment of the present invention provides a video decoding method, including:
[0026] Acquire second video data to be decoded; wherein the second video data to be decoded is encoded by the video encoding method described in any one of the method embodiments of the present invention;
[0027] Acquire second header information from the second video data to be decoded, and obtain a second video header identifier, a second video width, a second video height, and a second video data MJPEG length according to the position of bytes in the second header information;
[0028] According to the MJPEG length of the second video data, byte data corresponding to the MJPEG length of the second video data is obtained from the video data to be decoded as the second MJPEG format video data;
[0029] The second MJPEG format video data is converted into second video data.
[0030] Further, converting the second MJPEG format video data into second video data includes:
[0031] Decode the second MJPEG format video data into the second RGB888 format video data through the libjpeg library;
[0032] Convert the second RGB888 format video data into the second YUV420 format video data by using a conversion algorithm;
[0033] The second YUV420 format video data is decoded to obtain second video data.
[0034] Further, the second message header information is obtained from the second video data to be decoded, and the second video header identifier, the second video width, the second video height and the second video data MJPEG length are obtained according to the position of the bytes in the second message header information, including:
[0035] Reading byte information from the second video data to be decoded according to a length of two bytes;
[0036] Compare the two bytes of information read each time with the first video header identifier;
[0037] If the two bytes of information read match the first video header identifier, the two bytes of information are used as the second message header information, and the positions of the two bytes are used as the first and second bytes of the starting position;
[0038] Read the information at the third and fourth byte positions of the starting position, and use the information at the third and fourth byte positions as the second video width;
[0039] Read the information of the fifth and sixth byte positions of the starting position, and use the information of the fifth and sixth byte positions as the second video height;
[0040] The information at the seventh and eighth byte positions of the starting position is read, and the information at the seventh and eighth byte positions is used as the second video data MJPEG length.
[0041] Based on the above method embodiment, the present invention provides a corresponding device embodiment, including: a to-be-decoded video data acquisition module, a video decoding module, and a second video data format conversion module;
[0042] A module for acquiring video data to be decoded, used for acquiring second video data to be decoded; wherein the second video data to be decoded is encoded by the video encoding method described in any one of the method embodiments of the present invention;
[0043] The video decoding module includes: a message header information reading submodule and a video data interception submodule;
[0044] The message header information reading submodule is used to obtain the second message header information from the second video data to be decoded, and obtain the second video header identifier, the second video width, the second video height and the second video data MJPEG length according to the position of the bytes in the second message header information;
[0045] The video data interception submodule is used to obtain byte data corresponding to the MJPEG length of the second video data from the video data to be decoded according to the MJPEG length of the second video data as the second MJPEG format video data;
[0046] The second video data format conversion module is used to convert the second MJPEG format video data into second video data.
[0047] Based on the above-mentioned method embodiment, the present invention provides a corresponding terminal device embodiment, including: a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor. When the processor executes the computer program, the steps of the video decoding method described in the present invention are implemented.
[0048] Compared with the prior art, the beneficial effects of the embodiment of this solution are:
[0049] The present invention provides a video encoding and decoding method. First, in the video encoding process, video data to be encoded is converted into MJPEG format data. Through the MJPEG format, each frame of the video can be compressed independently without losing picture quality due to compression. At the same time, the encoding and decoding process of the MJPEG format is relatively simple and has low hardware requirements. Therefore, the encoding and decoding operation can be performed on a device with limited resources. Next, preset decoding parameters are set for the MJPEG format data, wherein the first and second bytes of the preset decoding parameters are video header identifiers, the third and fourth bytes are video widths, the fifth and sixth bytes are video heights, and the seventh and eighth bytes are video data MJPEG lengths. The setting of the decoding parameters can realize data format recognition, video size recognition, and video length recognition during the decoding process. Subsequently, the decoding parameters are combined with the MJPEG format data for transmission. In the video decoding process, the decoding parameters are extracted from the video data to be decoded. Through the MJPEG length of the video data in the decoding parameters, the decoder can obtain byte data of corresponding length from the video data to be decoded. The decoder obtains the decoded MJPEG format data and converts it into the original video data format to complete the decoding process.
[0050] In summary, the present invention realizes video encoding and decoding by converting video data into MJPEG format data and setting preset decoding parameters. This method is suitable for scenarios where video encoding and decoding need to be performed on devices with limited resources, while ensuring that the video picture quality is not lost. BRIEF DESCRIPTION OF THE DRAWINGS
[0051] Figure 1 is a flowchart of a video encoding method provided by an embodiment of the present invention;
[0052] Figure 2 is a flowchart of a video decoding method provided by an embodiment of the present invention;
[0053] Figure 3 is a structural schematic diagram of a video encoding device provided by an embodiment of the present invention;
[0054] Figure 4 is a structural schematic diagram of another video encoding device provided by an embodiment of the present invention;
[0055] Figure 5 is a structural diagram of a video decoding device provided by an embodiment of the present invention;
[0056] Figure 6 It is a structural schematic diagram of another video decoding device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0057] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0058] In the description of the present invention, it should be understood that the terms "first" and "second" are only used for descriptive purposes and cannot be understood as indicating or implying relative importance or implicitly indicating the number of the indicated technical features.
[0059] like Figure 1 As shown, an embodiment of the present invention provides a video encoding method, which at least includes the following steps:
[0060] Step S101: obtaining first video data to be encoded;
[0061] In step S101, the computer obtains original unencoded video data as video data to be encoded. The video data is usually a series of continuous video frames, each frame consisting of image data and related time information.
[0062] Step S102: converting the first video data to be encoded into first MJPEG format video data;
[0063] In a preferred embodiment, converting the first video data to be encoded into first MJPEG format video data includes:
[0064] Converting the first video data to be encoded into first YUV420 format video data;
[0065] Convert the first YUV420 format video data into the first RGB888 format video data by using a conversion algorithm;
[0066] The first RGB888 format video data is converted into the first MJPEG format video data through the libjpeg library.
[0067] For step S102, assuming that the video data to be encoded is the "input.mp4" video file, first, use a video processing library (such as FFmpeg) to convert the "input.mp4" video file into YUV420 format video data. YUV420 is a common color encoding format, in which Y represents the brightness component (Luma), and U and V represent the chrominance component (Chroma); secondly, since most image processing libraries and compression algorithms require image data in RGB format, it is necessary to convert the YUV value of each pixel into the corresponding RGB value through a conversion algorithm to realize the conversion of YUV420 format video data into RGB888 format video data; finally, the computer calls the function provided by the libjpeg library to compress the converted RGB888 format video data to generate MJPEG format video data.
[0068] It should be noted that libjpeg is a widely used JPEG image compression library that can convert RGB image data into JPEG compression format, and can also decompress JPEG format image data and restore it to RGB image data. MJPEG decomposes the video into a series of independent JPEG image frames, each frame is a separate JPEG compressed image, and there is no need to consider the relationship with other frames. When encoding or decoding video data in MJPEG format, each frame can be encoded or decoded separately, without the need for complex intra-frame compression calculations such as motion estimation and motion compensation. Therefore, one of the advantages of MJPEG is that the encoding and decoding process is simple and the amount of calculation is low, making MJPEG suitable for low-performance devices and application scenarios with high real-time requirements.
[0069] Step S103: Add a private first message header before the first MJPEG format video data to generate encoded video data; wherein, the first message header is a decoding parameter when decoding the data, and the first message header includes eight bytes, the first and second bytes of the first message header are the first video header identifier, the third and fourth bytes of the first message header are the first video width, the fifth and sixth bytes of the first message header are the first video height, and the seventh and eighth bytes of the first message header are the first video data MJPEG length.
[0070] In a preferred embodiment, the information of the first video header identifier, the first video width, the first video height and the first video data MJPEG length is filled into the first message header in the following manner:
[0071] Fill the preset byte information into the first and second bytes of the message header;
[0072] From the first video data, obtain byte information of the first video width and byte information of the first video height;
[0073] Fill the byte information of the first video width into the third and fourth bytes of the message header;
[0074] Fill the high byte information of the first video into the fifth and sixth bytes of the message header;
[0075] Obtain the number of bytes of the first MJPEG data from the first MJPEG format video data;
[0076] The number of bytes of the first MJPEG data is used as the MJPEG length of the first video data, and is filled into the seventh and eighth bytes of the first message header.
[0077] For step S103, the MJPEG format video data is obtained through step S102, and a private message header is added before the MJPEG format video data. The message header consists of 8 bytes and is used to store decoding parameters. First, the values of each field in the message header need to be determined. The first and second bytes of the message header are used to store the video identification header. The information of the video identification header is fixed byte information. In this embodiment, the 2 bytes of information of the video identification header are pre-set to 0x005c. Then, the video width and video height information can be obtained from the video data to be encoded, and the video width information is stored in the third and fourth bytes in the form of bytes, and the video height information is stored in the fifth and sixth bytes in the form of bytes. Finally, the length is obtained by calculating the number of bytes of the MJPEG format video data to be encoded, and the length information is stored in the seventh and eighth bytes in the form of bytes. Through the above steps, the decoding parameters are filled into the message header, and the message header is added to the front of the MJPEG format video data to be encoded to generate the encoded video data. This encoded video data contains a private message header, which can be used as a decoding parameter when decoding the video.
[0078] like Figure 3 As shown, based on the above method embodiment, a corresponding device embodiment is provided;
[0079] An embodiment of the present invention provides a video encoding device, comprising: a module for acquiring video data to be encoded, a module for converting a first video data format, and a video encoding module;
[0080] A module for acquiring video data to be encoded, used for acquiring first video data to be encoded;
[0081] A first video data format conversion module, used for converting the first video data to be encoded into first MJPEG format video data;
[0082] The video encoding module is used to add a private first message header before the first MJPEG format video data to generate encoded video data; wherein, the first message header is a decoding parameter when decoding the data, and the first message header includes eight bytes, the first and second bytes of the first message header are the first video header identifier, the third and fourth bytes of the first message header are the first video width, the fifth and sixth bytes of the first message header are the first video height, and the seventh and eighth bytes of the first message header are the first video data MJPEG length.
[0083] like Figure 4 As shown, an embodiment of the present invention provides another video encoding device;
[0084] In a preferred embodiment, the first video data format conversion module includes: a first YUV format conversion submodule, a first RGB format conversion submodule, and a first MJPEG format conversion submodule;
[0085] A first YUV format conversion submodule, used for converting the first video data to be encoded into first YUV420 format video data;
[0086] A first RGB format conversion submodule, used for converting the first YUV420 format video data into the first RGB888 format video data through a conversion algorithm;
[0087] The first MJPEG format conversion submodule is used to convert the first RGB888 format video data into the first MJPEG format video data through the libjpeg library.
[0088] In a preferred embodiment, the video encoding module includes: a first information filling submodule, a first information acquisition submodule, a second information filling submodule, a third information filling submodule, a second information acquisition submodule, and a fourth information filling submodule;
[0089] A first information filling submodule, used to fill preset byte information into the first and second bytes of the message header;
[0090] A first information acquisition submodule, used to acquire byte information of a first video width and byte information of a first video height from the first video data;
[0091] A second information filling submodule, used to fill the byte information of the first video width into the third and fourth bytes of the message header;
[0092] A third information filling submodule is used to fill the high byte information of the first video into the fifth and sixth bytes of the message header;
[0093] The second information acquisition submodule is used to acquire the number of bytes of the first MJPEG data from the first MJPEG format video data;
[0094] The fourth information filling submodule is used to use the number of bytes of the first MJPEG data as the MJPEG length of the first video data, and fill it into the seventh and eighth bytes of the first message header.
[0095] It can be understood that the above-mentioned device item embodiments correspond to the method item embodiments of the present invention, and can implement the video encoding method provided by any one of the above-mentioned method item embodiments of the present invention.
[0096] It should be noted that the device embodiments described above are merely illustrative, and some or all of the modules may be selected according to actual needs to achieve the purpose of the present embodiment. In addition, in the accompanying drawings of the device embodiments provided by the present invention, the connection relationship between the modules indicates that there is a communication connection between them, which may be specifically implemented as one or more communication buses or signal lines. Those of ordinary skill in the art may understand and implement the present invention without creative work.
[0097] Based on the above-mentioned embodiment of the video encoding method, another embodiment of the present invention provides a terminal device, which includes a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor. When the processor executes the computer program, the video encoding method of any embodiment of the present invention is implemented.
[0098] Exemplarily, in this embodiment, the computer program may be divided into one or more modules, which are stored in the memory and executed by the processor to implement the present invention. The one or more module elements may be a series of computer program instruction segments capable of implementing specific functions, which are used to describe the execution process of the computer program in the terminal device.
[0099] The terminal device may be a computing device such as a desktop computer, a notebook, a PDA, a cloud server, etc. The terminal device may include, but is not limited to, a processor and a memory.
[0100] like Figure 2 As shown, an embodiment of the present invention provides a method for video decoding, the method at least comprising the following steps:
[0101] Step S201: obtaining second video data to be decoded; wherein the second video data to be decoded is encoded by the video encoding method described in any one of the method embodiments of the present invention;
[0102] For step S201, the video data to be decoded is obtained. The premise for implementing the video decoding method of the present invention is that the video data to be decoded must be the encoded video data obtained by the video encoding method of the present invention; if the video data to be encoded is not the encoded video data obtained by the video encoding method of the present invention, it is impossible to decode the video data by identifying the decoding parameters. This is because the video decoding method of the present invention relies on a private message header, which stores decoding parameters such as a video identification header, video width information, video height information, and video length information. These decoding parameters are generated according to the video encoding method of the present invention, and the encoding and decoding processes are interdependent. Therefore, if the video data obtained using other video encoding methods does not contain the private message header and decoding parameters required by the present invention, then these parameters cannot be identified to perform decoding operations.
[0103] Step S202: obtaining second message header information from the second video data to be decoded, and obtaining a second video header identifier, a second video width, a second video height, and a second video data MJPEG length according to the position of bytes in the second message header information;
[0104] In a preferred embodiment, the second header information is obtained from the second video data to be decoded, and the second video header identifier, the second video width, the second video height and the second video data MJPEG length are obtained according to the position of the bytes in the second header information, including:
[0105] Reading byte information from the second video data to be decoded according to a length of two bytes;
[0106] Compare the two bytes of information read each time with the first video header identifier;
[0107] If the two bytes of information read match the first video header identifier, the two bytes of information are used as the second message header information, and the positions of the two bytes are used as the first and second bytes of the starting position;
[0108] Read the information at the third and fourth byte positions of the starting position, and use the information at the third and fourth byte positions as the second video width;
[0109] Read the information of the fifth and sixth byte positions of the starting position, and use the information of the fifth and sixth byte positions as the second video height;
[0110] The information at the seventh and eighth byte positions of the starting position is read, and the information at the seventh and eighth byte positions is used as the second video data MJPEG length.
[0111] For step S202, byte information is read from the video data to be decoded according to the length of two bytes through a programming language, and then the two bytes of information read each time are compared with the video header identifier (0x005c). If the two bytes of information read match the video header identifier (0x005c), it proves that the two bytes are the start identifiers of the video data, and the positions of the two bytes are used as the first and second bytes of the starting position; then, the information of the third and fourth byte positions of the starting position is read, and the information of these two byte positions is used as the video width of the video to be decoded; then, the information of the fifth and sixth byte positions of the starting position is read, and the information of these two byte positions is used as the video height of the video to be decoded; finally, the information of the seventh and eighth byte positions of the starting position is read, and the information of these two byte positions is used as the MJPEG length of the second video data.
[0112] Step S203: according to the MJPEG length of the second video data, obtaining byte data corresponding to the MJPEG length of the second video data from the video data to be decoded as second MJPEG format video data;
[0113] For step S203, in order to extract the MJPEG format data of the second video data, it is necessary to extract the byte data of the corresponding MJPEG length from the byte data after the eighth byte of the starting position from the video data to be decoded according to the calibrated starting position based on the second MJPEG format video data obtained in step S202, as the MJPEG format video data to be decoded and converted.
[0114] Step S204: convert the second MJPEG format video data into second video data.
[0115] In a preferred embodiment, converting the second MJPEG format video data into the second video data includes:
[0116] Decode the second MJPEG format video data into the second RGB888 format video data through the libjpeg library;
[0117] Convert the second RGB888 format video data into the second YUV420 format video data by using a conversion algorithm;
[0118] The second YUV420 format video data is decoded to obtain second video data.
[0119] For step S204, first, the MJPEG format video data to be decoded and converted obtained in step S203 is converted into RGB888 format video data using the function provided by the libjpeg library; then, the R, G and B components of the pixel data in the RGB888 format video data are separated by a conversion algorithm. According to the sampling rule of YUV420, each pixel corresponds to a Y value, but each 4x4 pixel block shares a U and V value. By using the corresponding conversion algorithm, the values of the R, G and B components are calculated as the values of the corresponding Y, U and V components; finally, according to the video width, video height and sampling rules, the Y, U and V components are rearranged into a complete video frame; the rearranged video frame is saved as a video file, and a playable video file can be obtained.
[0120] It should be noted that after obtaining the complete video frame, the rearranged video frame can be saved into a specific video format by using different encoders. For example, FFmpeg can be used to encode the rearranged video frame into MP4 format; the x264 encoder can be used to encode the rearranged video frame into H.264 format; the libvpx encoder can be used to encode the rearranged video frame into VP9 format, etc.
[0121] like Figure 5 As shown, based on the above method embodiment, a corresponding device embodiment is provided;
[0122] An embodiment of the present invention provides a video decoding device, comprising: a to-be-decoded video data acquisition module, a video decoding module, and a second video data format conversion module;
[0123] A module for acquiring video data to be decoded, used for acquiring second video data to be decoded; wherein the second video data to be decoded is encoded by the video encoding method described in any one of the method embodiments of the present invention;
[0124] The video decoding module includes: a message header information reading submodule and a video data interception submodule;
[0125] The message header information reading submodule is used to obtain the second message header information from the second video data to be decoded, and obtain the second video header identifier, the second video width, the second video height and the second video data MJPEG length according to the position of the bytes in the second message header information;
[0126] The video data interception submodule is used to obtain byte data corresponding to the MJPEG length of the second video data from the video data to be decoded according to the MJPEG length of the second video data as the second MJPEG format video data;
[0127] The second video data format conversion module is used to convert the second MJPEG format video data into second video data.
[0128] like Figure 6 As shown, an embodiment of the present invention provides another video decoding device;
[0129] In a preferred embodiment, the second video data format conversion module includes: a second MJPEG format conversion submodule, a second RGB format conversion submodule, and a second YUV format conversion submodule;
[0130] A second MJPEG format conversion submodule is used to decode the second MJPEG format video data into second RGB888 format video data through the libjpeg library;
[0131] A second RGB format conversion submodule, used for converting the second RGB888 format video data into the second YUV420 format video data through a conversion algorithm;
[0132] The second YUV format conversion submodule is used to decode the second YUV420 format video data to obtain second video data.
[0133] In a preferred embodiment, the message header information reading submodule includes: a byte reading unit, a byte comparison unit, a start position determination unit, a video width determination unit, a video height determination unit, and an MJPEG length determination unit;
[0134] A byte reading unit, used for reading byte information from the second video data to be decoded according to a length of two bytes;
[0135] A byte comparison unit, used for comparing the two bytes of information read each time with the first video header identifier;
[0136] a starting position determining unit, configured to use the two bytes of information read as second message header information if the two bytes of information match the first video header identifier, and use the positions of the two bytes as the first and second bytes of the starting position;
[0137] A video width determination unit, used for reading information at the third and fourth byte positions of the starting position, and using the information at the third and fourth byte positions as the second video width;
[0138] A video height determination unit, used for reading information at the fifth and sixth byte positions of the starting position, and using the information at the fifth and sixth byte positions as the second video height;
[0139] The MJPEG length determination unit is used to read the information at the seventh and eighth byte positions of the starting position, and use the information at the seventh and eighth byte positions as the MJPEG length of the second video data.
[0140] It can be understood that the above-mentioned device item embodiments correspond to the method item embodiments of the present invention, and can implement the video decoding method provided by any one of the above-mentioned method item embodiments of the present invention.
[0141] It should be noted that the device embodiments described above are merely illustrative, and some or all of the modules may be selected according to actual needs to achieve the purpose of the present embodiment. In addition, in the accompanying drawings of the device embodiments provided by the present invention, the connection relationship between the modules indicates that there is a communication connection between them, which may be specifically implemented as one or more communication buses or signal lines. Those of ordinary skill in the art may understand and implement the present invention without creative work.
[0142] Based on the above-mentioned embodiment of the video decoding method, another embodiment of the present invention provides a terminal device, which includes a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor. When the processor executes the computer program, the video decoding method of any embodiment of the present invention is implemented.
[0143] Exemplarily, in this embodiment, the computer program may be divided into one or more modules, which are stored in the memory and executed by the processor to implement the present invention. The one or more module elements may be a series of computer program instruction segments capable of implementing specific functions, which are used to describe the execution process of the computer program in the terminal device.
[0144] The terminal device may be a computing device such as a desktop computer, a notebook, a PDA, a cloud server, etc. The terminal device may include, but is not limited to, a processor and a memory.
[0145] The above is a preferred embodiment of the present invention. It should be pointed out that a person skilled in the art can make several improvements and modifications without departing from the principle of the present invention. These improvements and modifications are also considered to be within the scope of protection of the present invention.
Claims
1. A video encoding method, characterized in that: include: Acquire first video data to be encoded; Converting the first video data to be encoded into first MJPEG format video data; A private first message header is added before the first MJPEG format video data to generate encoded video data; wherein, the first message header is a decoding parameter when decoding the data, the first message header includes eight bytes, the first and second bytes of the first message header are the first video header identifier, the third and fourth bytes of the first message header are the first video width, the fifth and sixth bytes of the first message header are the first video height, and the seventh and eighth bytes of the first message header are the first video data MJPEG length.
2. The video encoding method according to claim 1, characterized in that: Converting the first video data to be encoded into first MJPEG format video data includes: Converting the first video data to be encoded into first YUV420 format video data; Convert the first YUV420 format video data into first RGB888 format video data by using a conversion algorithm; The first RGB888 format video data is converted into first MJPEG format video data through the libjpeg library.
3. The video encoding method according to claim 2, characterized in that: The information of the first video header identifier, the first video width, the first video height and the first video data MJPEG length is filled into the first message header in the following manner: Fill the preset byte information into the first and second bytes of the message header; From the first video data, obtain byte information of the first video width and byte information of the first video height; Filling the byte information of the first video width into the third and fourth bytes of the message header; Fill the high byte information of the first video into the fifth and sixth bytes of the message header; Obtain the number of bytes of the first MJPEG data from the first MJPEG format video data; The number of bytes of the first MJPEG data is used as the MJPEG length of the first video data, and is filled into the seventh and eighth bytes of the first message header.
4. A method for video decoding, characterized in that: include: Acquire second video data to be decoded; wherein the second video data to be decoded is encoded by the video encoding method according to any one of claims 1 to 3; Acquire second header information from the second video data to be decoded, and obtain a second video header identifier, a second video width, a second video height, and a second video data MJPEG length according to the position of bytes in the second header information; According to the MJPEG length of the second video data, byte data corresponding to the MJPEG length of the second video data is obtained from the video data to be decoded as second MJPEG format video data; The second MJPEG format video data is converted into second video data.
5. The video decoding method according to claim 4, characterized in that: Converting the second MJPEG format video data into second video data includes: Decoding the second MJPEG format video data into second RGB888 format video data through the libjpeg library; Convert the second RGB888 format video data into second YUV420 format video data by using a conversion algorithm; The second YUV420 format video data is decoded to obtain second video data.
6. The video decoding method according to claim 4, characterized in that: Obtaining second header information from the second video data to be decoded, and obtaining a second video header identifier, a second video width, a second video height, and a second video data MJPEG length according to the position of bytes in the second header information, including: Reading byte information from the second video data to be decoded according to a length of two bytes; Compare the two bytes of information read each time with the first video header identifier; If the two bytes of information read match the first video header identifier, the two bytes of information are used as the second message header information, and the positions of the two bytes are used as the first and second bytes of the starting position; Read the information at the third and fourth byte positions of the starting position, and use the information at the third and fourth byte positions as the second video width; Read the information of the fifth and sixth byte positions of the starting position, and use the information of the fifth and sixth byte positions as the second video height; The information at the seventh and eighth byte positions of the starting position is read, and the information at the seventh and eighth byte positions is used as the second video data MJPEG length.
7. A video encoding device, characterized in that: include: A module for acquiring video data to be encoded, a module for converting the first video data format, and a video encoding module; The to-be-encoded video data acquisition module is used to acquire the first video data to be encoded; The first video data format conversion module is used to convert the first video data to be encoded into first MJPEG format video data; The video encoding module is used to add a private first message header in front of the first MJPEG format video data to generate encoded video data; wherein, the first message header is a decoding parameter when decoding data, the first message header includes eight bytes, the first and second bytes of the first message header are the first video header identifier, the third and fourth bytes of the first message header are the first video width, the fifth and sixth bytes of the first message header are the first video height, and the seventh and eighth bytes of the first message header are the first video data MJPEG length.
8. A video decoding device, characterized in that: include: A module for acquiring video data to be decoded, a video decoding module, and a second video data format conversion module; The to-be-decoded video data acquisition module is used to acquire the second video data to be decoded; wherein the second video data to be decoded is encoded by the video encoding method according to any one of claims 1 to 3; The video decoding module includes: a message header information reading submodule and a video data interception submodule; The message header information reading submodule is used to obtain the second message header information from the second video data to be decoded, and obtain the second video header identifier, the second video width, the second video height and the second video data MJPEG length according to the position of the bytes in the second message header information; The video data interception submodule is used to obtain byte data corresponding to the MJPEG length of the second video data from the video data to be decoded according to the MJPEG length of the second video data, as the second MJPEG format video data; The second video data format conversion module is used to convert the second MJPEG format video data into second video data.
9. A terminal device, characterized in that: The method comprises a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor, wherein when the processor executes the computer program, the video encoding method according to any one of claims 1 to 3 is implemented.
10. A terminal device, characterized in that: The method comprises a processor, a memory, and a computer program stored in the memory and configured to be executed by the processor, wherein when the processor executes the computer program, the video encoding method according to any one of claims 4 to 6 is implemented.
