H.264 code stream bit level encryption method, system and terminal equipment for video transmission

CN122179626APending Publication Date: 2026-06-09ANHUI UNIV
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
ANHUI UNIV
Filing Date
2026-02-06
Publication Date
2026-06-09

AI Technical Summary

Technical Problem

Existing technologies struggle to efficiently achieve real-time encrypted communication of high-resolution video on resource-constrained mobile terminals and IoT devices. Existing encryption schemes are computationally complex and difficult to adapt to resource-constrained devices.

Method used

The H.264 bit-level encryption method is adopted. Through multi-threaded parallel computing, the video data is split into multiple sub-streams. The interference factors generated by DNA encoding and chaotic system are used for scrambling and diffusion. The encryption key generation method is optimized to XOR operation to form encrypted video data.

Benefits of technology

It effectively reduces the computational load of encryption tasks, reduces transmission bandwidth requirements, improves video encryption and decryption speed, and enables real-time video encryption, decryption, and communication.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122179626A_ABST
    Figure CN122179626A_ABST
Patent Text Reader

Abstract

This invention discloses a bit-level encryption method for H.264 bitstreams for video transmission, comprising the following steps: S1, the main thread extracts and generates a standard bitstream frame by frame and stores it in a first buffer; S2, the main thread divides the standard bitstream into n sub-bitstreams according to the number of child threads; S3, the encryption key and DNA encoding are obtained, n sets of interference factors are generated, and the interference factors are placed at the end of the n sub-bitstreams respectively; each sub-bitstream is expanded bit by bit and stored in a two-dimensional parent matrix M, and the two-dimensional parent matrix M is divided into n sub-matrices of equal size according to the number of child threads; S4, the sub-matrices are scrambled and reassembled to form sub-bitstreams at the corresponding positions; S5, the scrambled sub-bitstreams are diffused by the n child threads respectively, and the diffused sub-bitstreams are stored in a second buffer to form encrypted video data. This invention effectively improves the speed of video encryption to reduce network bandwidth consumption during real-time transmission.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention belongs to the field of image encryption technology, specifically relating to a bit-level encryption method, system, and terminal device for H.264 bitstreams in video transmission. Background Technology

[0002] In recent years, with the rapid development of information technology, secure encryption technology for multimedia data has become a research hotspot. The collaborative optimization of real-time encrypted audio and video communication in high-definition, low-latency, and resource-constrained scenarios faces severe challenges. On the one hand, high-resolution video (such as 1080p@30fps or higher) has extremely high spatiotemporal redundancy and data throughput—uncompressed raw video streams can generate several GB of local storage demand per minute, and network transmission bandwidth peaks can reach hundreds of Mbps to Gbps, far exceeding the actual carrying capacity of typical home, campus, and mobile cellular networks, severely restricting its real-time performance and availability. On the other hand, to ensure content security, existing encryption schemes often employ multiple rounds of scrambling and diffusion operations, whose computational complexity increases non-linearly with resolution. While such algorithms have theoretical advantages in security, they are highly dependent on high-performance computing platforms (such as NVIDIA GPUs or high-end multi-core CPUs), making them difficult to adapt to resource-constrained mobile terminals, IoT devices, and embedded systems.

[0003] In view of the shortcomings of existing technologies, there is an urgent need to design a bit-level encryption method, system and terminal equipment for H.264 bitstreams for video transmission. Summary of the Invention

[0004] This application discloses a bit-level encryption method for H.264 bitstreams in video transmission, comprising the following steps: S1, the main thread obtains the video to be processed, extracts video data frame by frame from the video to be processed, compresses and encodes the extracted video data frame by frame to generate a standard bitstream, and stores it in the first buffer. S2, n sub-threads are generated based on the main thread. After the main thread extracts the standard bitstream from the first buffer, it divides the standard bitstream into n sub-bitstreams according to the number of sub-threads. S3, obtain the encryption key and DNA encoding, generate n sets of interference factors based on the obtained encryption key and DNA encoding using n sub-threads, and place the interference factors into the tail of n sub-code streams respectively; expand each sub-code stream bit by bit and store it in a two-dimensional parent matrix M, and divide the two-dimensional parent matrix M into n sub-matrices of equal size according to the number of sub-threads. S4, based on the n sub-threads, scramble the corresponding sub-matrixes respectively, and reassemble the scrambled sub-matrixes into sub-code streams at the corresponding positions by 8 bits per byte; S5, based on the n sub-threads, the sub-streams that have completed the scrambling operation are diffused, and the diffused sub-streams are stored in the second buffer to form encrypted video data.

[0005] As a further optimization of the above scheme, the scrambling operation on the sub-matrix and the diffusion operation on the sub-bitstream specifically include the following: Randomly arrange n sub-code streams into a sequence and record the arrangement positions of the n sub-code streams; expand the n sub-code streams containing the interference factor by bits and store them in a two-dimensional parent matrix M; divide the two-dimensional parent matrix M into n sub-matrices of equal size according to the number of sub-threads. Number the sub-streams from 1 to n. Each of the n submatrices is scrambled internally using a1 rounds; After completing the internal scrambling of the a1 round sub-matrix, perform the internal scrambling of the two-dimensional parent matrix M in round a2; Based on the n sub-threads, the corresponding sub-matrices that have completed two rounds of scrambling operations are reassembled into sub-code streams at the corresponding positions by 8 bits per byte. Perform a3 rounds of diffusion operations on the n reassembled sub-streams.

[0006] As a further optimization of the above scheme, the method for generating the encryption key includes the following: Based on the main thread, two initial parameters and two control parameters are randomly generated and marked as input parameters of the chaotic system; Based on the chaotic system iterating P times, two sets of high-dimensional chaotic random number sequences are generated. The mantissa of each set of random numbers is extracted. The mantissa is converted into a byte sequence based on byte conversion. The lower address s bytes of the byte sequence are taken, and finally converted into two sets of byte sequences. A bitwise XOR operation is performed on the two sets of byte sequences to generate an encryption key.

[0007] As a further optimization of the above scheme, the steps of storing the diffused sub-stream into a second buffer to form encrypted video data specifically include the following: The algorithm dynamically maps the starting position of the diffused sub-bitstream in the image to be processed, and then fills the corresponding area of ​​the image with the diffused sub-bitstream in sequence. The RGB three-channel values ​​of the remaining areas of the image to be processed are filled with random integers in the range [0, 255]. The RGB three-channel values ​​of the image are filled into the corresponding area and the remaining area of ​​the image by the diffused sub-bitstream, and a complete encrypted image is generated; all the generated encrypted images are merged to form encrypted video data.

[0008] As a further optimization of the above scheme, the chaotic system generates the encryption key by employing a piecewise linear chaotic mapping: Where x0∈ [0,1] and p∈(0, 0.5), they become the initial condition and the control parameter, respectively. i+1 This is the starting state for the next iteration.

[0009] As a further optimization of the above scheme, the DNA encoding is bit-transformed according to the following mapping rules: Map the byte sequence generated by any set of chaotic systems to a DNA base using 2-bit mapping. After obtaining the base sequence, perform DNA pairing A--T,CG. Generate interference factors to be processed according to the mapping rules; The sub-code stream, based on the n random sequences of the records, generates a 2-bit identifier. This identifier is then placed at the beginning of the interference factor to be processed, forming the final interference factor.

[0010] This invention also discloses a bit-level decryption method for H.264 bitstreams for video transmission, the decryption implementation method specifically including the following: The main thread creates n child threads, and each of the n child threads is assigned a decryption task; the encryption key required by the decryption task is the encryption key created when the child thread executes the encryption task; Based on the main thread, n sub-threads are generated to extract the encrypted sub-code streams of the encrypted data corresponding to each decryption task, generating n sets of encrypted sub-code streams. Perform a3 inverse diffusion operations in parallel on the generated n groups of encrypted sub-code streams; The encrypted sub-code stream that has completed the de-diffusion operation is expanded into a new two-dimensional matrix N by bits. The new two-dimensional matrix N has the same size as the two-dimensional parent matrix M. Then, a2 global de-scrambling operations are performed on the constructed new two-dimensional matrix N. After completing the global reverse scrambling operation, the new two-dimensional matrix N is divided into n sub-matrices of equal size, and a1 sub-matrix reverse scrambling operations are performed on each sub-matrix. The interference factors of the data content corresponding to all sub-matrixes that have completed the sub-matrix inverse scrambling operation are removed, merged into a standard H.264 bitstream, and decoded to form plaintext data transmission.

[0011] As a further optimization of the above scheme, the specific process of reverse diffusion includes the following: in The encryption result of the current bitstream bytes. It is the encryption key used in the diffusion process. For elements in the original bitstream, For the previous encrypted bitstream byte; For XOR operation; The specific process of reversing the scramble includes the following: in The position of the matrix element. for The position of the element after the permutation. The size of the matrix. To confuse the seeds, This is for integer modulo operations.

[0012] This invention also discloses an H.264 bit-level encryption system for video transmission, comprising: The compression encoding task creation unit is used by the main thread to obtain the video to be processed, extract video data frame by frame from the video to be processed, compress and encode the extracted video data frame by frame to generate a standard bitstream, and store it in the first buffer. The compression encoding task sub-thread unit is used to generate n sub-threads based on the main thread. After the sub-threads extract the standard bitstream from the first buffer, they divide the standard bitstream into n sub-bitstreams according to the number of sub-threads. The compression encoding task execution unit is used to obtain the encryption key and DNA encoding, generate n interference factors based on the obtained encryption key and DNA encoding using n sub-threads, and place the interference factors into the tail of n sub-bit streams respectively; expand each sub-bit stream bit by bit and store it in a two-dimensional parent matrix M, and divide the two-dimensional parent matrix M into n sub-matrices of equal size according to the number of sub-threads; The compression encoding result acquisition unit is used to perform scrambling operations on the corresponding sub-matrices of each of the n sub-threads, and reassemble the scrambled sub-matrices into sub-code streams at the corresponding positions by 8 bits per byte. The encryption result acquisition unit is used to diffuse the sub-bitstreams that have completed the scrambling operation based on the n sub-threads, and store the diffused sub-bitstreams into the second buffer to form encrypted video data.

[0013] A terminal device, characterized in that the terminal device includes a memory and a processor, wherein the memory stores a computer program that can run on the processor, and the processor executes the computer program to implement the steps of the method as described in any one of claims 1 to 8.

[0014] The present invention adopts the above-described technical solution, and compared with the prior art, it has the following beneficial effects: The present invention provides a bit-level encryption method, system, and terminal device for H.264 bitstreams in video transmission, which has the following advantages: taking the H.264 bitstream of a single frame image in the original video as the object, n encryption tasks are created, and n encryption and decryption tasks are carried out in parallel based on n sub-threads, which effectively improves the speed of video encryption and reduces the network bandwidth occupation during real-time transmission. Attached Figure Description

[0015] Other features, objects, and advantages of this application will become more apparent from the following detailed description of non-limiting embodiments with reference to the accompanying drawings: Figure 1 This is a flowchart illustrating a bit-level encryption method for H.264 bitstreams used in video transmission. Figure 2 This is a schematic diagram illustrating the process of obtaining the encryption key and interference factor required when a child thread performs an encryption task. Figure 3 This is a diagram illustrating parallel encryption using n sub-threads; Figure 4 This is a diagram illustrating the scrambling of the internal components of n submatrices; Figure 5 This is a schematic diagram of scrambling a two-dimensional parent matrix; Figure 6 It is the encrypted padding of the sub-stream; Figure 7 This is another flowchart illustrating a bit-level encryption method for H.264 bitstreams used in video transmission; Figure 8 This is a diagram illustrating the decoding of the bitstream using a self-developed decoder; Figure 9 This is a diagram showing the bitstream expanded into a matrix; Detailed Implementation

[0016] It should be understood that the specific embodiments described herein are for illustrative purposes only and are not intended to limit the scope of the invention.

[0017] To address the issues of encryption / decryption speed and network load in real-time video transmission, this invention provides a bit-level encryption method for H.264 bitstreams. This method utilizes a process of splitting and compressing the input video, employing multi-threaded parallel computation to simultaneously process different parts of a single frame's bitstream. This effectively reduces the computational load of the encryption task, decreases transmission bandwidth requirements, and improves video encryption / decryption speed, enabling real-time video encryption / decryption and real-time communication. Based on the aforementioned method of splitting and compressing the input video, the following describes the bit-level encryption method for H.264 bitstreams in real-time video transmission.

[0018] See Figure 1-9This application provides a bit-level encryption method for H.264 bitstreams for video transmission, comprising the following steps: S1, the main thread obtains the video to be processed, extracts video data frame by frame from the video to be processed, compresses and encodes the extracted video data frame by frame to generate a standard bitstream, and stores it in the first buffer; it should be noted that the present invention extracts video data frame by frame based on FFmpeg. S2, n sub-threads are generated based on the main thread. After the sub-threads extract the standard bitstream from the first buffer, they divide the standard bitstream into n sub-bitstreams according to the number of sub-threads. S3, obtain the encryption key and DNA encoding. Based on n sub-threads, generate n interference factors from the obtained encryption key according to the DNA encoding, and place the interference factors into the tail of n sub-code streams respectively. Expand each sub-code stream bit by bit and store it in a two-dimensional parent matrix M. Divide the two-dimensional parent matrix M into n sub-matrices of equal size according to the number of sub-threads. More specifically, the main thread creates n sub-threads, and the main thread calls each sub-thread to execute the encryption task. One sub-thread corresponds to one encryption task. The tail is specifically the end of the sub-code stream with the numbers ordered from left to right. S4, based on the n sub-threads, scramble the corresponding sub-matrixes respectively, and reassemble the scrambled sub-matrixes into sub-code streams at the corresponding positions by 8 bits per byte; S5, based on the n sub-threads, the sub-streams that have completed the scrambling operation are diffused, and the diffused sub-streams are stored in the second buffer to form encrypted video data.

[0019] Specifically, the scrambling operation on the submatrix and the diffusion operation on the sub-bitstream include the following: Randomly arrange n sub-code streams into a sequence and record the arrangement positions of the n sub-code streams; expand the n sub-code streams containing the interference factor by bits and store them in a two-dimensional parent matrix M; divide the two-dimensional parent matrix M into n sub-matrices of equal size according to the number of sub-threads. Each of the n submatrices undergoes a1 rounds of internal submatrix scrambling; more specifically, the internal submatrix scrambling operation refers to scrambling the bits of the bitstream data, see [link to documentation]. Figure 4 ; After completing the internal scrambling of the a1-round submatrix, the internal scrambling of the two-dimensional parent matrix M is performed in round a2; more specifically, the scrambling of the two-dimensional parent matrix M is performed on all bits within M as a whole, see [link to relevant documentation]. Figure 5 ; Based on the n sub-threads, the corresponding sub-matrices that have completed two rounds of scrambling operations are reassembled into sub-code streams at the corresponding positions by 8 bits per byte. Perform a3 rounds of diffusion operations on the n reassembled sub-streams.

[0020] In this invention, encryption is achieved by employing a1 rounds of bit-level local scrambling, a2 rounds of bit-level global scrambling, and a3 rounds of diffusion. This results in a better encryption effect, effectively disrupting the statistical distribution pattern of syntax elements in the code stream and eliminating the predictable correlation between plaintext and ciphertext.

[0021] The present invention also provides another embodiment, in which a method for randomly arranging n sub-codestreams and recording the arrangement positions of the n sub-codestreams is implemented as follows: Based on the n sub-code streams, generate n deassociation bits, and record the starting position and number of bits of the n deassociation bits in any corresponding sub-code stream to form n record codes; The n sub-code streams are reordered based on the shuffling algorithm to form a new sequence of n sub-code streams; According to the new n-part sub-code stream sequence, the n record codes are respectively placed into the new n-part sub-code stream sequence for padding. By padding, any new sub-code stream is completely filled into the corresponding sub-matrix.

[0022] For example, if there are 4 sub-threads, with the permutation {4,1,2,3}, then submatrix A stores sub-codestream 4, submatrix B stores sub-codestream 1, and so on, until all sub-codestreams are stored in the corresponding submatrix of the two-dimensional parent matrix M. Two deassociation bits are inserted at the second position of each of the sub-codestreams 1-4, and this operation is recorded, forming 4 record codes. The record code of sub-codestream 1 is incremented to the end of the bit-expanded sequence of the corresponding sub-codestream stored in submatrix B, and so on, until all record codes are incremented to the end of the bit-expanded sequence of the corresponding sub-codestream in the submatrix. It is particularly important to note that the insertion position and number of deassociation bits in this invention depend on the specific situation; and the new sequence formed after the bit-expanded insertion of the sub-codestreams into the submatrix, including the record codes, interference factors, and the reordered sub-codestreams, results in a padding that completely fills the corresponding submatrix. By adding deassociation bits and random sorting, the statistical distribution of syntax elements in the codestream can be further effectively disrupted, eliminating the predictable association between plaintext and ciphertext.

[0023] More specifically, to ensure synchronization and mutual exclusion among multiple sub-threads, a single frame bitstream is divided into n sub-bitstreams. Each sub-thread accesses one of the sub-bitstreams to perform bitstream encryption tasks, and different sub-threads process different sub-bitstreams. Specifically, see Figure 3 Create n encryption tasks, including: the main thread obtains the single frame bitstream to be encrypted, divides the single frame bitstream into n sub-bitstreams, and encrypts each sub-bitstream as an encryption task; The main thread creates n child threads. The child threads obtain the encryption key required to perform the encryption task and wait to be awakened by the main thread. More specifically, the encryption key is the key sequence shown in the diagram. The main thread wakes up n child threads to perform encryption tasks; n child threads execute encryption tasks in parallel, using multiple rounds of scrambling and diffusion to encrypt local bitstreams. Each child thread encrypts a local bitstream, and after the child thread finishes encryption, it notifies the main thread and enters a waiting state. n sub-threads encrypt n local bitstreams, and the main thread outputs the encrypted single-frame bitstream or encrypted image.

[0024] More specifically, in the above steps, the video single-frame bitstream is split into n sub-bitstreams. In one implementation, the video single-frame bitstream can be filled with an interference factor and then evenly split. The main thread calls n sub-threads, with each sub-thread encrypting one sub-bitstream. The n sub-threads perform scrambling and diffusion operations in parallel to improve encryption and decryption speed. The main thread completes video frame extraction and compression to obtain continuous multi-frame bitstreams. The main thread obtains the single-frame bitstream to be processed, wakes up the sub-threads to complete the encryption operation, and waits for the sub-threads to complete the encryption operation. After obtaining the encryption key required to perform the encryption task, the sub-threads wait to be woken up by the main thread. After completing the encryption operation, the sub-threads notify the main thread and enter a waiting state. When all n sub-threads have completed the encryption operation, the main thread processes the next frame bitstream. When all n sub-threads have completed the encryption operation, the corresponding single-frame encrypted bitstream is output. Finally, the encrypted bitstream is decompressed into a single-frame ciphertext image.

[0025] Specifically, the methods for generating encryption keys include the following: Based on the main thread, two initial parameters and two control parameters are randomly generated and marked as input parameters of the chaotic system; Based on the chaotic system iterating P times, two sets of high-dimensional chaotic random number sequences are generated. The mantissa of each set of random numbers is extracted, and the mantissa is converted into a byte sequence based on byte conversion. The lower address s bytes of the byte sequence are taken, and finally converted into two sets of byte sequences. More specifically, the present invention converts the mantissa into a byte sequence based on byte conversion and takes the lower address s bytes of the byte sequence. Specifically, this means that the high-dimensional chaotic random number generated by the chaotic system iteratively is converted from floating-point to binary, and the last 6 bytes are converted. A bitwise XOR operation is performed on the two sets of byte sequences to generate an encryption key.

[0026] More specifically, the chaotic system generates encryption keys by employing piecewise linear chaotic mappings: Where x0∈ [0,1] and p∈(0, 0.5), they become the initial condition and the control parameter, respectively. i+1 This is the starting state for the next iteration.

[0027] It should be noted that before iterating through the two sets of high-dimensional chaotic random number sequences required by actual needs, the chaotic system of the present invention performs Q iterations based on the piecewise linear chaotic mapping expression. By performing the pre-iteration, the limitations of the piecewise linear chaotic mapping expression are broken, so as to make the subsequent iteration of high-dimensional chaotic random number sequences more random, reduce the generation of feature numbers, and thus increase the difficulty of decryption. The present invention preferably designs the chaotic system to generate two sets of high-dimensional chaotic random number sequences through 10,000 iterations.

[0028] It should be noted that the encryption key is divided proportionally according to the number of child threads to form encryption subkeys and distributed accordingly.

[0029] Specifically, the steps of storing the diffused sub-stream into the second buffer to form encrypted video data include the following: The algorithm dynamically maps the starting position of the diffused sub-bitstream in the image to be processed, and then fills the corresponding area of ​​the image with the diffused sub-bitstream in sequence. Specifically, this invention provides an embodiment for illustrating how to dynamically map the starting position of the diffused sub-bitstream in the image to be processed based on an algorithm, as follows: Each pixel in any image to be processed has three channels: red, green, and blue, with a total of three values ​​in the range [0, 255]. The sum of these three values ​​is used to determine the starting position of the sub-bitstream in the image pixel. The image is constructed by overlapping three matrices, and in computer physical storage, it needs to occupy the size of three matrices. For example, if the image size is 100*100, it actually occupies 300 bytes in the computer physical address. The starting position of the bitstream in the image is calculated using the three channel values ​​of the first pixel. For example, if the sum of the three channels of the first pixel is 128, then the starting position of the bitstream is the base address of the first channel + 128 bytes.

[0030] The RGB three-channel values ​​of the remaining areas of the image to be processed are filled with random integers in the range [0, 255]; the present invention provides another embodiment, such as... Figure 6 The diagram illustrates the dynamic mapping algorithm, showing how sub-streams are filled into corresponding regions of the image. Specifically, the image is divided into regions of equal size according to the number of threads. For example, if the main thread divides the image into 4 sub-threads, the image will be divided into corresponding sub-regions. Figure 1 ,son Figure 2 ,son Figure 3 Kazuko Figure 4The sub-thread number corresponds to the sub-image. Sub-thread 1 is responsible for filling the sub-datastream it processes into the sub-image. Figure 1 Similarly, the starting position of each sub-stream in a sub-image is determined by the sum of the three channel values ​​of the first pixel of the sub-image. It should be noted that the three channels of the first pixel given in this invention are only for illustrative purposes in this embodiment. In actual operation, a comprehensive judgment needs to be made based on the sub-stream length and the size of the target image to be processed to ensure efficient execution of the encryption process; this will not be detailed here. The RGB three-channel values ​​of the image are filled into the corresponding areas and the remaining areas of the image by the diffused sub-bitstreams, and then filled with random integers to generate a complete encrypted image. All generated encrypted images are then merged to form encrypted video data. It should be noted that the random integer filling described in this invention specifically means: after all the sub-bitstreams have been filled in the image to be processed, for the remaining channel positions of the image to be processed, this invention generates random numbers in the range [0, 255] to fill the remaining parts, traversing each row and each column, skipping the positions of the already filled sub-bitstream sequences, until all channels are filled, that is, the encryption process of the current image is completed; more specifically, the numbers corresponding to the encrypted image are random, that is, the positions of the remaining channel values ​​are random values, and the more random the range [0, 255], the stronger the encryption effect, and each value in [0, 255] should preferably appear with equal probability to enhance the randomness and security of the encryption; More specifically, in the embodiments of this application, an auxiliary thread is created in the main thread for output, and encryption operations are performed through n sub-threads. The n sub-threads are assigned to process different parts of the same frame bitstream. The processed bitstream is output to the second buffer by the auxiliary thread and then decoded. Finally, the buffer space is released.

[0031] In the main thread, multiple single-frame bitstreams are stored in the first buffer queue. In the sub-thread, the single-frame bitstreams in the first buffer queue are encrypted. In the auxiliary thread, the encrypted single-frame bitstreams are output from the first buffer queue to the second buffer. The single-frame bitstreams processed by the sub-thread are marked, and the single-frame bitstreams that have completed the encryption operation are marked. Synchronization and mutual exclusion between threads are achieved through semaphores. In this embodiment, the video reading process and the encrypted bitstream output process satisfy synchronization and mutual exclusion. The reading process is performed while the processed bitstream is output and the encrypted image is displayed.

[0032] The auxiliary thread needs to output the encrypted bitstream for network transmission, and simultaneously decode and display it based on a self-developed encoder. This method embeds encrypted data into the image space in an unreadable but visual form, thus providing an intuitive transmission status feedback mechanism while ensuring the confidentiality of the original video content. It is also used for security analysis and testing, effectively balancing security and observability. A decoding diagram of the self-developed decoder is shown below. Figure 8 The decoder dynamically maps the starting position of the bitstream in the image according to the algorithm, and then fills it into the corresponding area. The RGB three channels of the remaining areas of the image are filled with random integers in the range of [0, 255]. More specifically, before decoding and displaying, the present invention copies the encrypted bitstream. By decoding the copied encrypted bitstream, it prevents the occurrence of non-standard bitstreams after decryption, and avoids the situation where there is no encrypted bitstream that can be used for decoding to fill the image.

[0033] The present invention also provides another embodiment, which first fills all channel value positions of the image to be processed with random integers, and then covers the corresponding position of the image to be processed with the first 3 bits of any sub-bit stream, until all sub-bit streams are covered, thus completing the encryption process of the current image.

[0034] Specifically, after storing the diffused sub-stream into the second buffer to form encrypted video data, the process also includes the following steps: The main thread merges n encrypted sub-streams into a single stream, stores it, and sends it to the peer device.

[0035] More specifically, after generating the encrypted image, this invention merges n sub-streams into a single stream and sends it to the peer device. The peer device in this invention refers to the local device that performs encryption or decryption. It also supports using other devices to process the encrypted image or encrypted video generated by the invention. The complete stream is sent over the network without additional padding, specifically to reduce bandwidth transmission requirements. After the peer device receives the complete stream, it displays that random values ​​need to be used to fill in the data to generate the encrypted image.

[0036] Specifically, DNA encoding undergoes bit conversion according to the following mapping rules: Map the byte sequence generated by any set of chaotic systems to a DNA base using 2-bit mapping. After obtaining the base sequence, perform DNA pairing A--T,CG. Generate interference factors to be processed according to the mapping rules; The sub-code stream, based on the n random sequences of the records, generates a 2-bit identifier. This identifier is then placed at the beginning of the interference factor to be processed, forming the final interference factor.

[0037] More specifically, this invention uses the byte sequence generated by the first group of chaotic systems, mapped to DNA bases in 2-bit order, for the description of the technical solution. This can be adapted as needed. For example, the byte sequence generated by the first group of chaotic systems consists of 2 bytes, 1001010011101101. According to the DNA base mapping, GCCATGTC, after DNA pairing, it is modified to CCGTACAG, and the final output is 0110101100010010.

[0038] Specifically, the method of placing the interference factor into the end of each of the n sub-streams includes the following: The total length of the bitstream is obtained by expanding the bits into bytes to get the total number of bytes used to represent the bitstream length. Based on the calculated total number of bytes, perform numerical conversion by bit expansion; Set a two-dimensional parent matrix with equal rows and columns. The maximum number of bytes that can be entered into the two-dimensional parent matrix is ​​not less than the number of bits corresponding to the total number of bytes representing the length of the bit stream. The two-dimensional parent matrix is ​​divided into equal-sized sub-matrices based on n sub-bitstreams, and each sub-matrix supports a maximum number of bytes to be recorded, which is no less than the number of bits corresponding to the total number of bytes representing the length of any sub-bitstream. Based on the remaining unused bits in any submatrix, the interference factors are entered sequentially until all the bits in the submatrix are filled.

[0039] For example, the size of the two-dimensional parent matrix should be the closest to 8 times the bitstream length and be a square root of that value. It must be a multiple of 8 and greater than the bitstream length. For instance, if the bitstream length is 28 bytes, requiring 224 bits, the closest number greater than 224 and a square root of that value is also a multiple of 8, which is 256. Therefore, the size of the two-dimensional parent matrix would be 16 * 16, requiring 256 / 4 = 64 bytes to fill it. If there are 4 child threads, each corresponding to a 7-byte sub-bitstream, each thread should provide 8 bytes to reach the total 256 bytes. Each thread fills with an 8-bit interference factor. Based on the recorded 2-bit flag, each thread fills with a 2-bit flag plus a 6-bit interference factor to be processed, thus filling the sub-matrix with bits. By setting the flag, the untraceability of the interference factor is improved, while also ensuring that each interference factor forms an alignment and interference effect.

[0040] As another embodiment of the present invention, a method for placing an interference factor at the end of a sub-bitstream is also provided, specifically including the following: the length of the bitstream is 7 bytes, that is, 56 bits are required. The closest number that is greater than 56 and can be squared is also a multiple of 8, which is 64. Then the number of the two-dimensional parent matrix is ​​8*8. If there are 4 sub-threads, the sub-bitstreams corresponding to the first three sub-threads are 2 bytes long, and the last sub-thread corresponds to 1 byte long. At this time, an interference factor of 1 byte long is filled in the last sub-thread.

[0041] See Figure 2 The flowchart illustrates the process of obtaining the encryption key and interference factor required for the encryption process for each sub-thread: In this embodiment, the main thread generates the encryption key and interference factor based on two sets of initial parameters and control parameters. Since the amount of data in the encryption task is significantly reduced, the main thread only needs to pre-generate enough interference factor and encryption key for a single frame of bitstream encryption. The sub-threads can then directly read these based on the starting index position. After the main thread creates n sub-threads, each sub-thread, after obtaining the encryption key and interference factor, fills the bitstream with the interference factor and expands the bitstream into a matrix. See also... Figure 9 n groups of threads each expand the bitstream data into a matrix; the sub-threads scramble the matrix data and use the encryption key to spread the converted bitstream data.

[0042] More specifically, for the scrambling algorithm used in this invention, a discretized version of the Chirikov standard map is used for matrix permutation: in The position of the matrix element. for The position of the element after the permutation. The size of the matrix. To obfuscate the seed, the scrambling operation requires first independently scrambling the parallel pairs of submatrices, and then globally scrambling the entire two-dimensional matrix in parallel.

[0043] The diffusion algorithm used in the encryption process employs... Modify the value of data elements in the bitstream, where The encryption result of the current bitstream bytes. It is the key sequence used in the diffusion process. For elements in the original bitstream, This refers to the previous encrypted bitstream byte.

[0044] In this invention, each sub-thread or process implements the scrambling of sub-streams into single-frame streams. During diffusion, although different sub-threads process different sub-streams and each sub-stream is independent, other stream elements are used as seeds to complete the diffusion operation for each sub-stream, reconstructing the connection between the sub-streams. This allows changing the value of any byte in the stream to produce completely different ciphertext even when encrypted with the same encryption key. It also makes the encryption system sensitive to plaintext to resist known / chosen plaintext attacks.

[0045] The present invention also provides another embodiment, a bit-level decryption method for H.264 bitstreams for video transmission, the decryption implementation method specifically including the following: The main thread creates n child threads, and each of the n child threads is assigned a decryption task; the encryption key required by the decryption task is the encryption key created when the child thread executes the encryption task; Based on the main thread, n sub-threads are generated to extract the encrypted sub-code streams of the encrypted data corresponding to each decryption task, generating n sets of encrypted sub-code streams. Perform a3 inverse diffusion operations in parallel on the generated n groups of encrypted sub-code streams; The encrypted sub-code stream that has completed the de-diffusion operation is expanded into a new two-dimensional matrix N by bits. The new two-dimensional matrix N has the same size as the two-dimensional parent matrix M. Then, a2 global de-scrambling operations are performed on the constructed new two-dimensional matrix N. After completing the global reverse scrambling operation, the new two-dimensional matrix N is divided into n sub-matrices of equal size, and a1 sub-matrix reverse scrambling operations are performed on each sub-matrix. The interference factors of the data content corresponding to all sub-matrixes that have completed the sub-matrix inverse scrambling operation are removed, merged into a standard H.264 bitstream, and decoded to form plaintext data transmission.

[0046] More specifically, the decryption method based on the present invention is the reverse operation of the encryption method. Based on the encryption key and interference factor generated by the encryption method, the interference factor of the data content corresponding to the sub-matrix can be removed through reverse operation including reverse diffusion and reverse scrambling, and merged into a standard H.264 bitstream. The decoded data is then used to form plaintext data transmission. The specific process is not described in detail.

[0047] It should be noted that, according to the disclosed technical solution of the encryption method, the present invention also supports decryption by the peer device. Specific decryption methods for the peer device include the following: Specifically, the decryption process on the other end includes the following: The main thread of the peer device creates n child threads, and each of the n child threads is assigned a decryption task; the encryption key of the decryption task is the encryption key created when the child thread executes the encryption task; After the main thread obtains the complete password stream to be deciphered, it splits it into n groups of encrypted sub-code streams; Perform a3 inverse diffusion operations in parallel on the generated n groups of encrypted sub-code streams; The encrypted sub-code stream that has completed the de-diffusion operation is expanded into a new two-dimensional matrix N by bits. The new two-dimensional matrix N has the same size as the two-dimensional parent matrix M. Then, a2 global de-scrambling operations are performed on the constructed new two-dimensional matrix N. After completing the global reverse scrambling operation, the new two-dimensional matrix N is divided into n sub-matrices of equal size, and a1 sub-matrix reverse scrambling operations are performed on each sub-matrix. The interference factors of the data content corresponding to all sub-matrixes that have completed the sub-matrix inverse scrambling operation are removed, merged into a standard H.264 bitstream, and decoded to form plaintext data transmission.

[0048] More specifically, the first buffer serves as the raw code stream task queue, while the second buffer can become the encryption stream task queue. If the other end is decrypting, the first buffer can become the encryption stream task queue, and the second buffer can become the decryption stream task queue. In this case, the other party's output is used as one's own input.

[0049] Specifically, the process of reverse diffusion includes the following: in The encryption result of the current bitstream bytes. It is the encryption key used in the diffusion process. For elements in the original bitstream, For the previous encrypted bitstream byte; For XOR operation; The specific process of reversing the scramble includes the following: in The position of the matrix element. for The position of the element after the permutation. The size of the matrix. To confuse the seeds, This is a modulo operation with the integer part taken down. It should be noted that since the scrambling task in the encryption task is divided into intra-block scrambling and inter-block scrambling, the element coordinates and matrix size are determined by the parent or child matrix.

[0050] This invention also discloses an H.264 bit-level encryption system for video transmission, comprising: The compression encoding task creation unit is used by the main thread to obtain the video to be processed, extract video data frame by frame from the video to be processed, compress and encode the extracted video data frame by frame to generate a standard bitstream, and store it in the first buffer. The compression encoding task sub-thread unit is used to generate n sub-threads based on the main thread. After the sub-threads extract the standard bitstream from the first buffer, they divide the standard bitstream into n sub-bitstreams according to the number of sub-threads. The compression encoding task execution unit is used to obtain the encryption key and DNA encoding, generate n interference factors based on the obtained encryption key and DNA encoding using n sub-threads, and place the interference factors into the tail of n sub-bit streams respectively; expand each sub-bit stream bit by bit and store it in a two-dimensional parent matrix M, and divide the two-dimensional parent matrix M into n sub-matrices of equal size according to the number of sub-threads; The compression encoding result acquisition unit is used to perform scrambling operations on the corresponding sub-matrices of each of the n sub-threads, and reassemble the scrambled sub-matrices into sub-code streams at the corresponding positions by 8 bits per byte. The encryption result acquisition unit is used to diffuse the sub-bitstreams that have completed the scrambling operation based on the n sub-threads, and store the diffused sub-bitstreams into the second buffer to form encrypted video data.

[0051] Specific limitations regarding the H.264 bit-level encryption system for video transmission can be found in the above description of the limitations of the H.264 bit-level encryption method for video transmission, and will not be repeated here. Each unit in the aforementioned H.264 bit-level encryption system for video transmission can be implemented entirely or partially through software, hardware, or a combination thereof. These units can be embedded in hardware or independently of the processor in a computer device, or stored in software in the memory of the computer device, so that the processor can call and execute the corresponding operations of each unit.

[0052] This application discloses a computer-readable storage medium storing a computer program, wherein the computer program, when executed by a processor, implements the methods described in the above embodiments.

[0053] This application discloses a computer program product, including a computer program, which, when executed by a processor, implements the methods described in the above embodiments.

[0054] It should be noted that, in this document, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes that element. Furthermore, it should be noted that the scope of the methods and apparatuses in the embodiments of this application is not limited to performing functions in the order shown or discussed, but may also include performing functions substantially simultaneously or in the reverse order, depending on the functions involved. For example, the described methods may be performed in a different order than described, and various steps may be added, omitted, or combined. Additionally, features described with reference to certain examples may be combined in other examples.

[0055] Through the above description of the embodiments, those skilled in the art can clearly understand that the methods of the above embodiments can be implemented by means of software plus necessary general-purpose hardware platforms. Of course, they can also be implemented by hardware, but in many cases the former is a better implementation method. Based on this understanding, the technical solution of this application, in essence, or the part that contributes to the prior art, can be embodied in the form of a computer software product. This computer software product is stored in a storage medium (such as ROM / RAM, magnetic disk, optical disk) and includes several instructions to cause a terminal (which may be a mobile phone, computer, server, or network device, etc.) to execute the methods of the various embodiments of this application.

[0056] The embodiments of this application have been described above with reference to the accompanying drawings. However, this application is not limited to the specific embodiments described above. The specific embodiments described above are merely illustrative and not restrictive. Those skilled in the art can make many other forms under the guidance of this application without departing from the spirit and scope of the claims, and all of these forms are within the protection scope of this application.

[0057] In the description of this specification, the references to terms such as "one embodiment," "some embodiments," "illustrative embodiment," "example," "specific example," or "some examples," etc., indicate that a specific feature, structure, material, or characteristic described in connection with that embodiment or example is included in at least one embodiment or example of this application. In this specification, the illustrative expressions of the above terms do not necessarily refer to the same embodiment or example. Furthermore, the specific features, structures, materials, or characteristics described may be combined in any suitable manner in one or more embodiments or examples.

[0058] Although embodiments of this application have been shown and described, those skilled in the art will understand that various changes, modifications, substitutions and alterations can be made to these embodiments without departing from the principles and spirit of this application, the scope of which is defined by the claims and their equivalents.

Claims

1. A bit-level encryption method for H.264 bitstreams for video transmission, characterized in that, Includes the following steps: S1, the main thread obtains the video to be processed, extracts video data frame by frame from the video to be processed, compresses and encodes the extracted video data frame by frame to generate a standard bitstream, and stores it in the first buffer. S2, n sub-threads are generated based on the main thread. After the main thread extracts the standard bitstream from the first buffer, it divides the standard bitstream into n sub-bitstreams according to the number of sub-threads. S3, obtain the encryption key and DNA code, generate n sets of interference factors based on the obtained encryption key and DNA code according to n sub-threads, and place the interference factors into the end of n sub-code streams respectively; Each sub-stream is expanded bit by bit and stored in a two-dimensional parent matrix M. The two-dimensional parent matrix M is then divided into n sub-matrices of equal size according to the number of sub-threads. S4, based on the n sub-threads, scramble the corresponding sub-matrixes respectively, and reassemble the scrambled sub-matrixes into sub-code streams at the corresponding positions by 8 bits per byte; S5, based on the n sub-threads, the sub-streams that have completed the scrambling operation are diffused, and the diffused sub-streams are stored in the second buffer to form encrypted video data.

2. The H.264 bit-level encryption method for video transmission according to claim 1, characterized in that, The scrambling operation on the submatrix and the diffusion operation on the sub-bitstream specifically include the following: Randomly arrange n sub-code streams into a sequence and record the arrangement positions of the n sub-code streams; expand the n sub-code streams containing the interference factor by bits and store them in a two-dimensional parent matrix M; divide the two-dimensional parent matrix M into n sub-matrices of equal size according to the number of sub-threads. Number the sub-streams from 1 to n. Each of the n submatrices is scrambled internally using a1 rounds; After completing the internal scrambling of the a1 round sub-matrix, perform the internal scrambling of the two-dimensional parent matrix M in round a2; Based on the n sub-threads, the corresponding sub-matrices that have completed two rounds of scrambling operations are reassembled into sub-code streams at the corresponding positions by 8 bits per byte. Perform a3 rounds of diffusion operations on the n reassembled sub-streams.

3. The H.264 bit-level encryption method for video transmission according to claim 1, characterized in that, The method for generating the encryption key includes the following: Based on the main thread, two initial parameters and two control parameters are randomly generated and marked as input parameters of the chaotic system; Based on the chaotic system iterating P times, two sets of high-dimensional chaotic random number sequences are generated. The mantissa of each set of random numbers is extracted. The mantissa is converted into a byte sequence based on byte conversion. The lower address s bytes of the byte sequence are taken, and finally converted into two sets of byte sequences. A bitwise XOR operation is performed on the two sets of byte sequences to generate an encryption key.

4. The H.264 bit-level encryption method for video transmission according to claim 1, characterized in that, The steps for storing the diffused sub-stream into the second buffer to form encrypted video data specifically include the following: The algorithm dynamically maps the starting position of the diffused sub-bitstream in the image to be processed, and then fills the corresponding area of ​​the image with the diffused sub-bitstream in sequence. The RGB three-channel values ​​of the remaining areas of the image to be processed are filled with random integers in the range [0, 255]. The RGB three-channel values ​​of the image are filled into the corresponding area and the remaining area of ​​the image by the diffused sub-bitstream, and a complete encrypted image is generated; all the generated encrypted images are merged to form encrypted video data.

5. A bit-level encryption method for H.264 bitstreams for video transmission according to claim 2, characterized in that, The chaotic system generates the encryption key by employing a piecewise linear chaotic mapping: Where x0∈ [0,1] and p∈(0, 0.5), they become the initial condition and the control parameter, respectively. i+1 This is the starting state for the next iteration.

6. A bit-level encryption method for H.264 bitstreams for video transmission according to claim 2, characterized in that, The DNA encoding is bit-transformed according to the following mapping rules: Map the byte sequence generated by any set of chaotic systems to a DNA base using 2-bit mapping. After obtaining the base sequence, perform DNA pairing A--T,CG. Generate interference factors to be processed according to the mapping rules; The sub-code stream, based on the n random sequences of the records, generates a 2-bit identifier. This identifier is then placed at the beginning of the interference factor to be processed, forming the final interference factor.

7. A bit-level decryption method for H.264 bitstreams for video transmission, characterized in that, The decryption implementation method specifically includes the following: The main thread creates n child threads, and each of the n child threads is assigned a decryption task; the encryption key required by the decryption task is the encryption key created when the child thread executes the encryption task; Based on the main thread, n sub-threads are generated to extract the encrypted sub-code streams of the encrypted data corresponding to each decryption task, generating n sets of encrypted sub-code streams. Perform a3 inverse diffusion operations in parallel on the generated n groups of encrypted sub-code streams; The encrypted sub-code stream that has completed the de-diffusion operation is expanded into a new two-dimensional matrix N by bits. The new two-dimensional matrix N has the same size as the two-dimensional parent matrix M. Then, a2 global de-scrambling operations are performed on the constructed new two-dimensional matrix N. After completing the global reverse scrambling operation, the new two-dimensional matrix N is divided into n sub-matrices of equal size, and a1 sub-matrix reverse scrambling operations are performed on each sub-matrix. The interference factors of the data content corresponding to all sub-matrixes that have completed the sub-matrix inverse scrambling operation are removed, merged into a standard H.264 bitstream, and decoded to form plaintext data transmission.

8. The H.264 bit-level decryption method for video transmission according to claim 7, characterized in that, The specific process of reverse diffusion includes the following: in The encryption result of the current bitstream bytes. It is the encryption key used in the diffusion process. For elements in the original bitstream, For the previous encrypted bitstream byte; For XOR operation; The specific process of reversing the scramble includes the following: in The position of the matrix element. for The position of the element after the permutation. The size of the matrix. To confuse the seeds, This is for integer modulo operations.

9. A bit-level encryption system for H.264 bitstreams for video transmission, characterized in that, include: The compression encoding task creation unit is used by the main thread to obtain the video to be processed, extract video data frame by frame from the video to be processed, compress and encode the extracted video data frame by frame to generate a standard bitstream, and store it in the first buffer. The compression encoding task sub-thread unit is used to generate n sub-threads based on the main thread. After the main thread extracts the standard bitstream from the first buffer, it divides the standard bitstream into n sub-bitstreams according to the number of sub-threads. The compression encoding task execution unit is used to obtain the encryption key and DNA code, generate n interference factors based on the obtained encryption key and DNA code using n sub-threads, and place the interference factors into the tail of the n sub-code streams respectively. Each sub-stream is expanded bit by bit and stored in a two-dimensional parent matrix M. The two-dimensional parent matrix M is then divided into n sub-matrices of equal size according to the number of sub-threads. The compression encoding result acquisition unit is used to perform scrambling operations on the corresponding sub-matrices of each of the n sub-threads, and reassemble the scrambled sub-matrices into sub-code streams at the corresponding positions by 8 bits per byte. The encryption result acquisition unit is used to diffuse the sub-bitstreams that have completed the scrambling operation based on the n sub-threads, and store the diffused sub-bitstreams into the second buffer to form encrypted video data.

10. A terminal device, characterized in that, The terminal device includes a memory and a processor. The memory stores a computer program that can run on the processor. When the processor executes the computer program, it implements the steps of the method as described in any one of claims 1 to 8.