Mp4 video data encryption method applied to H.264 coding and related equipment

By encrypting the H.264-encoded MP4 video files using the XOR algorithm and the AES algorithm, the problem of high video privacy leakage and encryption in the existing technology is solved, and efficient and secure video encryption effect is achieved.

CN119996584APending Publication Date: 2025-05-13SHENZHEN ROADROVER TECH
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202510152867.7
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-02-11
Publication Date
2025-05-13

AI Technical Summary

Technical Problem

Existing H.264/AVC-encoded MP4 video files are usually in plain text, which can easily lead to privacy leakage, and full encryption will increase processing time and storage costs.

Method used

The XOR algorithm and AES algorithm are used to encrypt the H.264 video data. The specific steps include encrypting the header information, SPS data, PPS data and IDR image data, and writing the encrypted data to the new file in chronological order.

Benefits of technology

It realizes efficient encryption of MP4 video files, ensures the security of video privacy, and avoids the problem of increasing data length during encryption, maintaining efficiency and practicality.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119996584A_ABST
    Figure CN119996584A_ABST
Patent Text Reader

Abstract

The embodiment of the invention belongs to the technical field of digital video encryption, and relates to an mp4 video data encryption method applied to H.264 coding and related equipment, and the method comprises the steps: carrying out the XOR header encryption operation of header information according to an XOR algorithm and an XOR key, and obtaining the encrypted header information; performing XOR video frame encryption operation on the SPS data and the PPS data of the I-type video frame according to an XOR algorithm to obtain an XOR encrypted video frame; performing AES video frame encryption operation on the first 256 bytes of data of the IDR image data of the I-type video frame according to an AES algorithm and an AES key to obtain an AES encrypted video frame; and writing the P-type video frame, the B-type video frame, the encrypted header information, the XOR encrypted video frame and the AES encrypted video frame into a new file according to a time sequence to obtain an encrypted MP4 file. The XOR algorithm and the AES algorithm adopted by the invention do not generate data with extra length, the encryption process is simple and efficient to implement, and meanwhile, the method has relatively high security and practicability.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of digital video encryption technology, and in particular to an MP4 video data encryption method and related equipment applied to H.264 encoding. Background Art

[0002] With the widespread use of surveillance and recording equipment, video information security has become increasingly important.

[0003] Existing H.264 / AVC encoded MP4 video files are usually in plain text, which can easily lead to privacy leakage. Although full encryption can provide high-strength security, it will increase processing time and storage costs.

[0004] Therefore, a secure and efficient encryption scheme is needed to protect video privacy. Summary of the invention

[0005] The purpose of the embodiments of the present application is to propose an MP4 video data encryption method and related equipment applied to H.264 encoding to protect video privacy.

[0006] In order to solve the above technical problems, the embodiment of the present application provides an MP4 video data encryption method applied to H.264 encoding, which adopts the following technical solution:

[0007] Get the H.264 video data collected by the camera device;

[0008] Parsing the H.264 video data to obtain header information, I-type video frames, P-type video frames, and B-type video frames;

[0009] Initialize the XOR algorithm, XOR key, AES algorithm and AES key;

[0010] Performing an XOR header encryption operation on the header information according to the XOR algorithm and the XOR key to obtain encrypted header information;

[0011] Perform an XOR video frame encryption operation on the SPS data and the PPS data of the class I video frame according to the XOR algorithm to obtain an XOR encrypted video frame;

[0012] Performing an AES video frame encryption operation on the first 256 bytes of the IDR image data of the class I video frame according to the AES algorithm and the AES key to obtain an AES encrypted video frame;

[0013] The P-type video frame, the B-type video frame, the encrypted header information, the XOR-encrypted video frame, and the AES-encrypted video frame are written into a new file in chronological order to obtain an encrypted MP4 file.

[0014] Furthermore, the AES key may be any one of 128 bits, 192 bits or 256 bits.

[0015] Furthermore, the step of parsing the H.264 video data to obtain header information, class I video frames, class P video frames, and class B video frames specifically includes the following steps:

[0016] Identifying a NAL unit from a bitstream of the H.264 video data;

[0017] The SPS data and the PPS data are identified according to a type parameter of the NAL unit.

[0018] Further, the step of identifying the NAL unit from the bit stream of the H.264 video data specifically includes the following steps:

[0019] Determine whether the bit stream contains 0x00000001 or 0x000001;

[0020] If 0x00000001 or 0x000001 appears, the NAL unit is identified;

[0021] If 0x00000001 or 0x000001 does not appear, the NAL unit is not recognized.

[0022] Further, the step of identifying the SPS data and the PPS data according to the type parameter of the NAL unit specifically includes the following steps:

[0023] Using the parameters of the NAL unit with type parameter 7 as the SPS data;

[0024] The parameters of the NAL unit whose type parameter is 8 are used as the PPS data.

[0025] In order to solve the above technical problems, the embodiment of the present application also provides an MP4 video data encryption device applied to H.264 encoding, which adopts the following technical solution:

[0026] The video data acquisition module is used to acquire the H.264 video data collected by the camera device;

[0027] A parsing module, used for parsing the H.264 video data to obtain header information, I-type video frames, P-type video frames and B-type video frames;

[0028] Initialization module, used to initialize XOR algorithm, XOR key, AES algorithm and AES key;

[0029] An XOR header encryption module is used to perform an XOR header encryption operation on the header information according to the XOR algorithm and the XOR key to obtain encrypted header information;

[0030] An XOR video frame encryption module is used to perform an XOR video frame encryption operation on the SPS data and the PPS data of the class I video frame according to the XOR algorithm to obtain an XOR encrypted video frame;

[0031] An AES video frame encryption module is used to perform an AES video frame encryption operation on the first 256 bytes of the IDR image data of the class I video frame according to the AES algorithm and the AES key to obtain an AES encrypted video frame;

[0032] The file writing module is used to write the P-type video frame, the B-type video frame, the encrypted header information, the XOR encrypted video frame and the AES encrypted video frame into a new file in chronological order to obtain an encrypted MP4 file.

[0033] Furthermore, the AES key may be any one of 128 bits, 192 bits or 256 bits.

[0034] Furthermore, the parsing module includes:

[0035] A NAL unit identification submodule, used for identifying a NAL unit from a bit stream of the H.264 video data;

[0036] A data identification submodule is used to identify the SPS data and the PPS data according to the type parameter of the NAL unit.

[0037] In order to solve the above technical problems, the embodiment of the present application further provides a computer device, which adopts the following technical solution:

[0038] It comprises a memory and a processor, wherein the memory stores computer-readable instructions, and when the processor executes the computer-readable instructions, the steps of the above-mentioned method for encrypting mp4 video data applied to H.264 encoding are implemented.

[0039] In order to solve the above technical problems, the embodiment of the present application further provides a computer-readable storage medium, which adopts the following technical solution:

[0040] The computer-readable storage medium stores computer-readable instructions, and when the computer-readable instructions are executed by the processor, the steps of the above-mentioned method for encrypting mp4 video data applied to H.264 encoding are implemented.

[0041] The present application provides an MP4 video data encryption method applied to H.264 encoding, comprising: acquiring H.264 video data collected by a camera device; parsing the H.264 video data to obtain header information, a class I video frame, a class P video frame, and a class B video frame; initializing an XOR algorithm, an XOR key, an AES algorithm, and an AES key; performing an XOR header encryption operation on the header information according to the XOR algorithm and the XOR key to obtain the encrypted header information; performing an XOR video frame encryption operation on the SPS data and the PPS data of the class I video frame according to the XOR algorithm to obtain an XOR encrypted video frame; performing an AES video frame encryption operation on the first 256 bytes of IDR image data of the class I video frame according to the AES algorithm and the AES key to obtain an AES encrypted video frame; writing the class P video frame, the class B video frame, the encrypted header information, the XOR encrypted video frame, and the AES encrypted video frame into a new file in chronological order to obtain an encrypted MP4 file. Compared with the prior art, the XOR algorithm and AES algorithm encryption adopted in the present application do not generate data of extra length, and the encryption process is simple and efficient, while having high security and practicality. BRIEF DESCRIPTION OF THE DRAWINGS

[0042] In order to more clearly illustrate the scheme in the present application, a brief introduction is given below to the drawings required for use in the description of the embodiments of the present application. Obviously, the drawings described below are some embodiments of the present application. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.

[0043] Figure 1 is an exemplary system architecture diagram to which the present application may be applied;

[0044] Figure 2 It is a flow chart of an implementation method of an MP4 video data encryption method applied to H.264 encoding provided in an embodiment of the present application;

[0045] Figure 3 It is a structural schematic diagram of an MP4 video data encryption device applied to H.264 encoding provided by an embodiment of the present application;

[0046] Figure 4 It is a structural diagram of an embodiment of a computer device according to the present application. DETAILED DESCRIPTION

[0047] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by technicians in the technical field of the present application; the terms used in the specification of the application herein are only for the purpose of describing specific embodiments and are not intended to limit the present application; the terms "including" and "having" and any variations thereof in the specification and claims of the present application and the above-mentioned drawings are intended to cover non-exclusive inclusions. The terms "first", "second", etc. in the specification and claims of the present application or the above-mentioned drawings are used to distinguish different objects, not to describe a specific order.

[0048] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.

[0049] In order to enable those skilled in the art to better understand the solution of the present application, the technical solution in the embodiments of the present application will be clearly and completely described below in conjunction with the accompanying drawings.

[0050] like Figure 1 As shown, the system architecture 100 may include a terminal device 101, a network 102 and a server 103. The terminal device 101 may be a laptop 1011, a tablet computer 1012 or a mobile phone 1013. The network 102 is used to provide a medium for a communication link between the terminal device 101 and the server 103. The network 102 may include various connection types, such as wired, wireless communication links or optical fiber cables, etc.

[0051] The user can use the terminal device 101 to interact with the server 103 through the network 102 to receive or send messages, etc. Various communication client applications can be installed on the terminal device 101, such as web browser applications, shopping applications, search applications, instant messaging tools, email clients, social platform software, etc.

[0052] The terminal device 101 can be any electronic device with a display screen and supporting web browsing. In addition to the laptop computer 1011, tablet computer 1012 or mobile phone 1013, the terminal device 101 can also be an e-book reader, an MP3 player (Moving Picture Experts Group Audio Layer III), an MP4 (Moving Picture Experts Group Audio Layer IV), a laptop computer, a desktop computer, etc.

[0053] The server 103 may be a server that provides various services, such as a background server that provides support for a web page displayed on the terminal device 101 .

[0054] It should be noted that the MP4 video data encryption method for H.264 encoding provided in the embodiment of the present application is generally executed by a server / terminal device, and accordingly, the MP4 video data encryption device for H.264 encoding is generally set in the server / terminal device.

[0055] It should be understood that Figure 1 The number of terminal devices, networks and servers in the embodiment is only for illustration. Any number of terminal devices, networks and servers may be provided according to implementation requirements.

[0056] Continue to refer Figure 2 , shows a flow chart of an embodiment of the method for encrypting mp4 video data for H.264 encoding according to the present application. The method for encrypting mp4 video data for H.264 encoding includes: step S201, step S202, step S203, step S204, step S205, step S206 and step S207.

[0057] In step S201, H.264 video data collected by a camera device is obtained;

[0058] In step S201, the H.264 video data is parsed to obtain header information, I-type video frames, P-type video frames, and B-type video frames;

[0059] In step S201, the XOR algorithm, XOR key, AES algorithm and AES key are initialized;

[0060] In step S201, an XOR header encryption operation is performed on the header information according to the XOR algorithm and the XOR key to obtain the encrypted header information;

[0061] In step S201, an XOR video frame encryption operation is performed on the SPS data and the PPS data of the class I video frame according to the XOR algorithm to obtain an XOR encrypted video frame;

[0062] In step S201, the AES video frame encryption operation is performed on the first 256 bytes of the IDR image data of the type I video frame according to the AES algorithm and the AES key to obtain an AES encrypted video frame;

[0063] In step S201, the P-type video frames, the B-type video frames, the encrypted header information, the XOR-encrypted video frames and the AES-encrypted video frames are written into a new file in chronological order to obtain an encrypted MP4 file.

[0064] In the embodiment of the present application, the user inputs a question or inquiry through their terminal device (such as a mobile phone, computer, etc.), and this input is received by the system. This inquiry text data is the specific content that the user wants the system to answer. Specifically, the inquiry text data can be "transaction data or payment data or business data or purchase data" related to a financial institution (such as a bank, etc.). The inquiry text data can also be medical data related to medical scenarios, such as personal health records, prescriptions, examination reports, etc. It should be understood that the examples of inquiry text data here are only for the convenience of understanding and are not used to limit this application.

[0065] In the embodiment of the present application, the YUV data is obtained from the camera sensor and is compressed and encoded into H.264 video frame data through hardware. The encoded H.264 data types of each frame are divided into I frame, P frame, and B frame. According to the different characteristics of the frame type data, only the I frame has the characteristics of a complete image. Therefore, the I frame data is encrypted, and the I frame is composed of concentrated NALU type data. The most critical NALU type is SPS, PPS and IDR data. The SPS and PPS data are encrypted by the XOR algorithm, and the IDR data is encrypted by the AES algorithm for the first 256 bytes of data. The encrypted file cannot be played by the player, thereby realizing the encryption operation of the MP4 file data.

[0066] In the embodiment of the present application, an MP4 encoder is initialized and the resolution, width, and refresh rate are obtained from the video configuration information, and then a byte-by-byte XOR operation is performed on the data, which involves several different steps. The following is a general description of this process:

[0067] Select a suitable encoding library and select H.264 / AVC. Set the encoder parameters, including encoding format (H.264), resolution (width and height), and frame rate (refresh rate).

[0068] Parse the recording configuration file or directly obtain information such as resolution (width and height), frame rate, etc. from the recording device.

[0069] The XOR operation is a bitwise operation. For two byte sequences of equal length, each bit is XORed. If the two bits are the same, the result is 0; if they are different, the result is 1.

[0070] In order to perform an XOR operation, you need two byte sequences of equal length. Typically, this involves XORing the video frame data with a key to achieve encryption or data hiding.

[0071] In the embodiment of the present application, the SPS and PPS data are encrypted using the XOR algorithm, a random key is selected, and the SPS and PPS data are XOR-ed with the key respectively. The advantages of this are:

[0072] (1) The XOR algorithm is simple and efficient, and can encrypt and protect SPS and PPS data to prevent illegal acquisition and decoding;

[0073] (2) The AES algorithm has strong security and can encrypt key IDR image data, making it impossible to compose a damaged image, thus improving the security of video content;

[0074] (3) Encrypting only the first 256 bytes can keep most of the image data intact, thus preserving the video quality to a certain extent;

[0075] (4) This method can effectively protect the security of video data while minimizing the impact on video quality. In practical applications, the encryption range and algorithm can be adjusted according to specific needs.

[0076] In the embodiment of the present application, H.264 / AVC encodes MP4 files. The imaging principle is to divide the image into blocks, use prediction and compression technology to reduce redundant information and use motion compensation to track image motion, and form video images frame by frame, which further improves the compression efficiency. Finally, the compressed data is encapsulated into mp4. The video frame is composed of I frame, P frame and B frame of H.264. The h.264 video content is separated from the mp4 by ffmpeg command, and the key information constituting the image is resolution, SPS, PPS and l frame, combined with the h.264 protocol and VegaH264Analyzer tool analysis.

[0077] In the embodiment of the present application, the MP4 file encoded by H.264 / AVC is composed of structural encapsulation of different boxes. By parsing the content in the video box, the NALU type of the h264 data is obtained for analysis, and only the resolution, SPS, SPS and key information of each video key frame (I frame) are modified. The bytes of the same length are encrypted by a symmetric algorithm to replace the content corresponding to the key information. This consumes relatively little CPU consumption and memory usage, does not increase the additional file size, and does not require a new video file. After replacing the key information, the video player or MP4 analysis tool cannot form an image. Thereby achieving the encryption effect and preventing the video content information from being leaked.

[0078] Correspondingly, the decryption solution is also a corresponding tool, because it does not destroy the mp4 file box structure, nor the NALU type, does not modify the PTS and DTS, but only modifies the content necessary for imaging. The tool can quickly locate the encrypted key information, perform decryption and modification on it, and realize decryption of the entire file.

[0079] In the embodiment of the present application, to encrypt the entire MP4 file, first parse out different types of boxes, and then encrypt the key video information content. The code parsing tools include ffmpeg or mp4box. This solution uses ffmpeg for parsing and then uses the algorithm for encryption, which is divided into the following six steps:

[0080] Step 1: Use ffmpeg to demux the video encoder or MP4 file to separate the audio and video data. Initialize the key using the AES256 algorithm;

[0081] Step 2: parse the key information of the video header, such as resolution, frame rate, bit rate and spspps information;

[0082] Step 3: The resolution length and width in the header information are calculated by SPSPPS using the XOR algorithm according to the data length byte by byte and filled into the new encoder header;

[0083] Step 4: According to the video index, keep reading the mp4 file to obtain the video data, and use the filter h264_mp4toannexb to convert the video frame header format avcc into annexb data;

[0084] Step 5: Parse the video into nalu structure and parse H264 to generate I frame, P frame and B frame. According to the characteristics of I frame, the 256 bytes of data behind the NALU header of I frame are directly encrypted, thus destroying the integrity of the image.

[0085] Step 6: Write the encrypted header information and video data into a new MP4 file so that mainstream players cannot play the video normally.

[0086] In the embodiment of the present application, through the above encryption method, the mp4 video file can also be played normally through reverse decryption.

[0087] In an embodiment of the present application, a method for encrypting MP4 video data applied to H.264 encoding is provided, including: acquiring H.264 video data collected by a camera device; parsing the H.264 video data to obtain header information, class I video frames, class P video frames, and class B video frames; initializing an XOR algorithm, an XOR key, an AES algorithm, and an AES key; performing an XOR header encryption operation on the header information according to the XOR algorithm and the XOR key to obtain encrypted header information; performing an XOR video frame encryption operation on the SPS data and the PPS data of the class I video frame according to the XOR algorithm to obtain an XOR encrypted video frame; performing an AES video frame encryption operation on the first 256 bytes of IDR image data of the class I video frame according to the AES algorithm and the AES key to obtain an AES encrypted video frame; writing the class P video frame, the class B video frame, the encrypted header information, the XOR encrypted video frame, and the AES encrypted video frame into a new file in chronological order to obtain an encrypted MP4 file. Compared with the prior art, the XOR algorithm and AES algorithm encryption adopted in the present application do not generate data of extra length, and the encryption process is simple and efficient, while having high security and practicality.

[0088] In some optional implementations of the embodiments of the present application, the above-mentioned AES key can be any one of 128 bits, 192 bits or 256 bits.

[0089] In the embodiment of the present application, the SPS and PPS data are encrypted using the XOR algorithm, a random key is selected, and the SPS and PPS data are XORed with the key respectively. The first 256 bytes of the image data with the NALU type of IDR in the l frame are AES encrypted, an AES key is selected, which can be 128 bits, 192 bits or 256 bits, and the first 256 bytes of the image data are encrypted using the AES algorithm.

[0090] In some optional implementations of the embodiments of the present application, the above-mentioned step of parsing the H.264 video data to obtain header information, class I video frames, class P video frames, and class B video frames specifically includes the following steps:

[0091] Identify NAL units from a bitstream of H.264 video data;

[0092] The SPS data and the PPS data are identified according to the type parameter of the NAL unit.

[0093] In some optional implementations of the embodiments of the present application, the above step of identifying the NAL unit from the bit stream of the H.264 video data specifically includes the following steps:

[0094] Determine whether the bit stream contains 0x00000001 or 0x000001;

[0095] If 0x00000001 or 0x000001 appears, the NAL unit is recognized;

[0096] If 0x00000001 or 0x000001 is not present, the NAL unit is not recognized.

[0097] In some optional implementations of the embodiments of the present application, the above step of identifying SPS data and PPS data according to the type parameter of the NAL unit specifically includes the following steps:

[0098] The parameters of the NAL unit with type parameter 7 are used as SPS data;

[0099] The parameters of the NAL unit whose type parameter is 8 are used as PPS data.

[0100] In the embodiment of the present application, the information of the video header of the I frame encoded by h264 is parsed, and the NAL unit is read: First, the NAL unit needs to be read from the bitstream. The NALU unit is the basic data unit of H.264 encoding, which contains information such as video frames and parameter sets. The start code of the NAL unit is 0x00000001 or 0x000001, which is used to identify the start of the NAL unit.

[0101] In the embodiment of the present application, SPS (sequence parameter set) and PPS (picture parameter set) are identified: In the NAL unit, SPS and PPS contain sequence and picture level parameters respectively. These parameters are crucial for decoding video frames. The NAL unit type of SPS is 7, and the NAL unit type of PPS is 8. P frames and B frames are transition frames and predicted frames, and they cannot form pictures and be written directly into files alone.

[0102] The embodiments of the present application can acquire and process relevant data based on artificial intelligence technology. Among them, artificial intelligence (AI) is the theory, method, technology and application system that uses digital computers or machines controlled by digital computers to simulate, extend and expand human intelligence, perceive the environment, acquire knowledge and use knowledge to obtain the best results.

[0103] AI basic technologies generally include sensors, dedicated AI chips, cloud computing, distributed storage, big data processing technology, operation / interaction systems, mechatronics, etc. AI software technologies mainly include computer vision technology, robotics technology, biometrics technology, speech processing technology, natural language processing technology, and machine learning / deep learning.

[0104] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through computer-readable instructions, and the computer-readable instructions can be stored in a computer-readable storage medium. When the program is executed, it can include the processes of the embodiments of the above-mentioned methods. Among them, the aforementioned storage medium can be a non-volatile storage medium such as a disk, an optical disk, a read-only memory (ROM), or a random access memory (RAM).

[0105] It should be understood that, although the steps in the flowchart of the accompanying drawings are displayed in sequence as indicated by the arrows, these steps are not necessarily executed in sequence in the order indicated by the arrows. Unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and they can be executed in other orders. Moreover, at least a part of the steps in the flowchart of the accompanying drawings may include multiple sub-steps or multiple stages, and these sub-steps or stages are not necessarily executed at the same time, but can be executed at different times, and their execution order is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a part of the sub-steps or stages of other steps.

[0106] Further references Figure 3 , as a response to the above Figure 2 The present application provides an embodiment of an mp4 video data encryption device for H.264 encoding, and the device embodiment is similar to Figure 2 Corresponding to the method embodiment shown, the device can be specifically applied to various electronic devices.

[0107] like Figure 3 As shown, the MP4 video data encryption device 200 applied to H.264 encoding in the embodiment of the present application includes:

[0108] The video data acquisition module 210 is used to acquire H.264 video data collected by the camera device;

[0109] The parsing module 220 is used to parse the H.264 video data to obtain header information, I-type video frames, P-type video frames and B-type video frames;

[0110] Initialization module 230, used to initialize the XOR algorithm, XOR key, AES algorithm and AES key;

[0111] An XOR header encryption module 240 is used to perform an XOR header encryption operation on the header information according to an XOR algorithm and an XOR key to obtain encrypted header information;

[0112] An XOR video frame encryption module 250 is used to perform an XOR video frame encryption operation on the SPS data and the PPS data of the class I video frame according to an XOR algorithm to obtain an XOR encrypted video frame;

[0113] AES video frame encryption module 260, used for performing AES video frame encryption operation on the first 256 bytes of IDR image data of the class I video frame according to the AES algorithm and the AES key to obtain an AES encrypted video frame;

[0114] The file writing module 270 is used to write the P-type video frames, the B-type video frames, the encrypted header information, the XOR encrypted video frames and the AES encrypted video frames into a new file in chronological order to obtain an encrypted MP4 file.

[0115] In an embodiment of the present application, an MP4 video data encryption device 200 for H.264 encoding is provided, including: a video data acquisition module 210, used to acquire H.264 video data collected by a camera device; a parsing module 220, used to parse the H.264 video data to obtain header information, class I video frames, class P video frames, and class B video frames; an initialization module 230, used to initialize an XOR algorithm, an XOR key, an AES algorithm, and an AES key; an XOR header encryption module 240, used to perform an XOR header encryption operation on the header information according to the XOR algorithm and the XOR key, to obtain an encrypted header. Information; XOR video frame encryption module 250, used to perform XOR video frame encryption operation on SPS data and PPS data of class I video frame according to XOR algorithm to obtain XOR encrypted video frame; AES video frame encryption module 260, used to perform AES video frame encryption operation on the first 256 bytes of IDR image data of class I video frame according to AES algorithm and AES key to obtain AES encrypted video frame; file writing module 270, used to write P class video frame, B class video frame, encrypted header information, XOR encrypted video frame and AES encrypted video frame into a new file in time sequence to obtain an encrypted MP4 file. Compared with the prior art, the XOR algorithm and AES algorithm encryption adopted in the present application do not generate data of extra length, the encryption process is simple and efficient, and has high security and practicality.

[0116] In some optional implementations of the embodiments of the present application, the above-mentioned AES key can be any one of 128 bits, 192 bits or 256 bits.

[0117] In some optional implementations of the embodiments of the present application, the above-mentioned MP4 video data encryption device 200 applied to H.264 encoding further includes:

[0118] In some optional implementations of the embodiments of the present application, the above-mentioned parsing module includes:

[0119] A NAL unit identification submodule, used to identify NAL units from a bit stream of H.264 video data;

[0120] The data identification submodule is used to identify SPS data and PPS data according to the type parameter of the NAL unit.

[0121] To solve the above technical problems, the present application also provides a computer device. Figure 4 , Figure 4 This is a basic structural block diagram of a computer device according to an embodiment of the present application.

[0122] The computer device 300 includes a memory 310, a processor 320, and a network interface 330 that are interconnected and communicated through a system bus. It should be noted that the figure only shows a computer device 300 having components 310-330, but it should be understood that it is not required to implement all the components shown, and more or fewer components can be implemented instead. Among them, those skilled in the art can understand that the computer device here is a device that can automatically perform numerical calculations and / or information processing according to pre-set or stored instructions, and its hardware includes but is not limited to microprocessors, application specific integrated circuits (Application Specific Integrated Circuit, ASIC), programmable gate arrays (Field-Programmable Gate Array, FPGA), digital processors (Digital Signal Processor, DSP), embedded devices, etc.

[0123] The computer device may be a computing device such as a desktop computer, a notebook, a PDA, a cloud server, etc. The computer device may interact with a user through a keyboard, a mouse, a remote controller, a touch pad, or a voice control device.

[0124] The memory 310 includes at least one type of readable storage medium, and the readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (for example, SD or DX memory, etc.), random access memory (RAM), static random access memory (SRAM), read-only memory (ROM), electrically erasable programmable read-only memory (EEPROM), programmable read-only memory (PROM), magnetic memory, magnetic disk, optical disk, etc. In some embodiments, the memory 310 can be an internal storage unit of the computer device 300, such as a hard disk or memory of the computer device 300. In other embodiments, the memory 310 can also be an external storage device of the computer device 300, such as a plug-in hard disk equipped on the computer device 300, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card, etc. Of course, the memory 310 can also include both the internal storage unit of the computer device 300 and its external storage device. In the embodiment of the present application, the memory 310 is generally used to store the operating system and various application software installed on the computer device 300, such as computer-readable instructions for the H.264-encoded mp4 video data encryption method, etc. In addition, the memory 310 can also be used to temporarily store various data that have been output or are to be output.

[0125] The processor 320 may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other data processing chip in some embodiments. The processor 320 is generally used to control the overall operation of the computer device 300. In the embodiment of the present application, the processor 320 is used to run the computer-readable instructions stored in the memory 310 or process data, such as running the computer-readable instructions of the mp4 video data encryption method applied to H.264 encoding.

[0126] The network interface 330 may include a wireless network interface or a wired network interface. The network interface 330 is generally used to establish a communication connection between the computer device 300 and other electronic devices.

[0127] The computer device provided in the present application adopts the XOR algorithm and AES algorithm for encryption, which does not generate data of extra length. The encryption process is simple and efficient, and has high security and practicality.

[0128] The present application also provides another embodiment, namely, providing a computer-readable storage medium, which stores computer-readable instructions, and the computer-readable instructions can be executed by at least one processor to enable the at least one processor to perform the steps of the above-mentioned method for encrypting mp4 video data applied to H.264 encoding.

[0129] The computer-readable storage medium provided in the present application uses the XOR algorithm and the AES algorithm for encryption, which does not generate data of extra length. The encryption process is simple and efficient, and has high security and practicality.

[0130] Through the description of the above implementation methods, those skilled in the art can clearly understand that the above-mentioned embodiment methods can be implemented by means of software plus a necessary general hardware platform, and of course by hardware, but in many cases the former is a better implementation method. Based on such an understanding, the technical solution of the present application, or the part that contributes to the prior art, can be embodied in the form of a software product, which is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk), and includes a number of instructions for a terminal device (which can be a mobile phone, computer, server, air conditioner, or network device, etc.) to execute the methods described in each embodiment of the present application.

[0131] Obviously, the embodiments described above are only some embodiments of the present application, rather than all embodiments. The preferred embodiments of the present application are given in the accompanying drawings, but they do not limit the patent scope of the present application. The present application can be implemented in many different forms. On the contrary, the purpose of providing these embodiments is to make the understanding of the disclosure of the present application more thorough and comprehensive. Although the present application is described in detail with reference to the aforementioned embodiments, for those skilled in the art, it is still possible to modify the technical solutions recorded in the aforementioned specific implementation methods, or to perform equivalent replacement of some of the technical features therein. Any equivalent structure made using the contents of the specification and drawings of this application, directly or indirectly used in other related technical fields, is similarly within the scope of patent protection of this application.

Claims

1. A method for encrypting MP4 video data for H.264 encoding, characterized in that: The steps include: Get the H.264 video data collected by the camera device; Parsing the H.264 video data to obtain header information, I-type video frames, P-type video frames, and B-type video frames; Initialize the XOR algorithm, XOR key, AES algorithm and AES key; Performing an XOR header encryption operation on the header information according to the XOR algorithm and the XOR key to obtain encrypted header information; Perform an XOR video frame encryption operation on the SPS data and the PPS data of the class I video frame according to the XOR algorithm to obtain an XOR encrypted video frame; Performing an AES video frame encryption operation on the first 256 bytes of the IDR image data of the class I video frame according to the AES algorithm and the AES key to obtain an AES encrypted video frame; The P-type video frame, the B-type video frame, the encrypted header information, the XOR-encrypted video frame, and the AES-encrypted video frame are written into a new file in chronological order to obtain an encrypted MP4 file.

2. The method for encrypting mp4 video data for H.264 encoding according to claim 1, characterized in that: The AES key can be any one of 128 bits, 192 bits or 256 bits.

3. The method for encrypting mp4 video data applied to H.264 encoding according to claim 1, characterized in that: The step of parsing the H.264 video data to obtain header information, I-type video frames, P-type video frames, and B-type video frames specifically includes the following steps: Identifying a NAL unit from a bitstream of the H.264 video data; The SPS data and the PPS data are identified according to a type parameter of the NAL unit.

4. The method for encrypting mp4 video data applied to H.264 encoding according to claim 3 is characterized in that: The step of identifying the NAL unit from the bit stream of the H.264 video data specifically comprises the following steps: Determine whether 0x00000001 or 0x00000 1 appears in the bit stream; If 0x00000001 or 0x00000 1 appears, the NAL unit is identified; If 0x00000001 or 0x00000 1 is not present, the NAL unit is not recognized.

5. The method for encrypting MP4 video data for H.264 encoding according to claim 3, characterized in that: The step of identifying the SPS data and the PPS data according to the type parameter of the NAL unit specifically comprises the following steps: The parameters of the NAL unit with the type parameter of 7 are used as the SPS data; The parameters of the NAL unit whose type parameter is 8 are used as the PPS data.

6. An MP4 video data encryption device for H.264 encoding, characterized in that: include: The video data acquisition module is used to acquire the H.264 video data collected by the camera device; A parsing module, used for parsing the H.264 video data to obtain header information, I-type video frames, P-type video frames and B-type video frames; An initialization module, used to initialize the XOR algorithm, XOR key, AE S algorithm and AE S key; An XOR header encryption module is used to perform an XOR header encryption operation on the header information according to the XOR algorithm and the XOR key to obtain encrypted header information; An XOR video frame encryption module is used to perform an XOR video frame encryption operation on the SPS data and the PPS data of the class I video frame according to the XOR algorithm to obtain an XOR encrypted video frame; An AES video frame encryption module, used for performing an AES video frame encryption operation on the first 256 bytes of the IDR image data of the class I video frame according to the AES algorithm and the AES key to obtain an AES encrypted video frame; The file writing module is used to write the P-type video frame, the B-type video frame, the encrypted header information, the XOR encrypted video frame and the AE S encrypted video frame into a new file in chronological order to obtain an encrypted MP4 file.

7. The MP4 video data encryption device for H.264 encoding according to claim 6, characterized in that: The AES key can be any one of 128 bits, 192 bits or 256 bits.

8. The MP4 video data encryption device for H.264 encoding according to claim 6, characterized in that: The parsing module comprises: A NAL unit identification submodule, used for identifying a NAL unit from a bit stream of the H.264 video data; A data identification submodule is used to identify the SPS data and the PPS data according to the type parameter of the NAL unit.

9. A computer device comprising a memory and a processor, characterized in that: The memory stores computer-readable instructions, and when the processor executes the computer-readable instructions, the steps of the MP4 video data encryption method applied to H.264 encoding as claimed in any one of claims 1 to 5 are implemented.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores computer-readable instructions, which, when executed by a processor, implement the steps of the MP4 video data encryption method applied to H.264 encoding as claimed in any one of claims 1 to 5.