CN117119226A - Efficient H264 video stream real-time encryption method - Google Patents

Efficient H264 video stream real-time encryption method Download PDF

Info

Publication number
CN117119226A
CN117119226A CN202311144328.6A CN202311144328A CN117119226A CN 117119226 A CN117119226 A CN 117119226A CN 202311144328 A CN202311144328 A CN 202311144328A CN 117119226 A CN117119226 A CN 117119226A
Authority
CN
China
Prior art keywords
scrambling
encryption
encrypting
stream
intra
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202311144328.6A
Other languages
Chinese (zh)
Inventor
黄晓平
叶海荣
方翠
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Zhejiang Sci Tech University ZSTU
Original Assignee
Zhejiang Sci Tech University ZSTU
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Zhejiang Sci Tech University ZSTU filed Critical Zhejiang Sci Tech University ZSTU
Priority to CN202311144328.6A priority Critical patent/CN117119226A/en
Publication of CN117119226A publication Critical patent/CN117119226A/en
Pending legal-status Critical Current

Links

Classifications

    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04NPICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N21/00Selective content distribution, e.g. interactive television or video on demand [VOD]
    • H04N21/20Servers specifically adapted for the distribution of content, e.g. VOD servers; Operations thereof
    • H04N21/23Processing of content or additional data; Elementary server operations; Server middleware
    • H04N21/234Processing of video elementary streams, e.g. splicing of video streams or manipulating encoded video stream scene graphs
    • H04N21/2347Processing of video elementary streams, e.g. splicing of video streams or manipulating encoded video stream scene graphs involving video stream encryption
    • HELECTRICITY
    • H04ELECTRIC COMMUNICATION TECHNIQUE
    • H04NPICTORIAL COMMUNICATION, e.g. TELEVISION
    • H04N21/00Selective content distribution, e.g. interactive television or video on demand [VOD]
    • H04N21/80Generation or processing of content or additional data by content creator independently of the distribution process; Content per se
    • H04N21/83Generation or processing of protective or descriptive data associated with content; Content structuring
    • H04N21/835Generation of protective data, e.g. certificates

Landscapes

  • Engineering & Computer Science (AREA)
  • Multimedia (AREA)
  • Signal Processing (AREA)
  • Computer Security & Cryptography (AREA)
  • Two-Way Televisions, Distribution Of Moving Picture Or The Like (AREA)
  • Compression Or Coding Systems Of Tv Signals (AREA)

Abstract

The application relates to a high-efficiency H264 video stream real-time encryption method, which comprises the steps of adopting an encryption algorithm RC4 to generate an encryption key stream; scrambling and encrypting parameters related to quantization parameters in the H264 code stream; for an intra-coded macroblock, scrambling or scrambling encryption is performed on its intra-prediction mode; for inter-frame coding macro blocks, scrambling and encrypting the difference value between the motion vector and the predicted motion vector; and scrambling and encrypting residual coefficients in the H264 code stream. The beneficial effects of the application are as follows: the application can well encrypt the video data by encrypting part of key grammar elements in the code stream of H264 during encoding, has simple and efficient encryption process, can be completed in real time at any terminal, and can be applied to real-time application scenes such as video conferences and the like.

Description

Efficient H264 video stream real-time encryption method
Technical Field
The application relates to the technical field of video communication, in particular to an efficient H264 video stream real-time encryption method.
Background
With the continuous development of technology, network applications related to video, such as video on demand, internet television, video telephony, and video conferencing, are increasing. Accordingly, security of video content on a network has received increasing attention, such as video on demand services, in which only users who subscribe to the service are expected to view high quality programs; in commercial video conferencing applications, conference participants want to allow only legitimate conference members to receive audio and video data to protect confidentiality of conference content. How to protect video information safety is a very urgent and important work, and has important theoretical significance and practical application value.
Video encryption is a technology for protecting video information safety by utilizing a cryptography method, and mainly aims to research an encryption algorithm or an encryption method suitable for the characteristics of video data. The video data encrypted by the encryption algorithm can be decrypted and accessed by only the authorized party having the decryption key. Many methods have been proposed for encrypting video. According to encryption at different stages of video coding, three types of encryption can be classified: pre-encoding encryption, in-encoding encryption, and post-encoding encryption. The encryption before video coding is to encrypt YUV image data, and generally, the YUV image data is encrypted by adopting a traditional text encryption algorithm (such as DES, AES, RSA, IDEA and the like), and then the encrypted data is normally encoded. The encryption method has too large operation amount and is rarely adopted. The encryption in the encoding refers to simultaneous encryption in the encoding process, and when the encoding is finished, the generated code stream is the encrypted code stream. In the encoding, a selective encryption algorithm (Selective Encryption, SE) is generally adopted, and only a small amount of key syntax elements or structures in the video code stream data are selected for encryption in consideration of the self-characteristics of the video code stream data. If video is encrypted in a video conference, only encryption in coding can be used because the transmission is encoded in real time. After encoding, encrypting refers to encrypting the encoded video file which can be normally played. Some people encrypt by adopting a traditional text encryption algorithm, consider a video file as a common text file, encrypt the video file directly by using the traditional text encryption algorithm, the required calculation amount is large, the occupied hardware resources are large, the size of the encrypted file is changed, and the format cannot be compatible. The encoded video file is also parsed and encrypted according to different syntax elements.
The syntax format of the video stream data is specified by the video coding standard, and different video coding standards have different syntax formats, so that the selective encryption method is aimed at a specific video coding standard. Currently, the mainstream video format is h.264/AVC, and in recent years, researchers have made many researches on video data encryption of h.264/AVC, and many methods have been proposed, but the following problems still remain: the method comprises the steps of (1) complicating an encryption algorithm, increasing the calculated amount, and not processing hardware resources of mobile equipment enough (2) complicating the encryption algorithm, so that the encoding time is long, video communication cannot be performed in real time, (3) incompatibility of the encrypted code stream format, so that the code stream data after encryption of a standard decoder crash (4) is much larger than that after encryption, and the compression rate is reduced.
Disclosure of Invention
The application aims at overcoming the defects of the prior art, and provides an efficient H264 video stream real-time encryption method.
In a first aspect, an efficient real-time encryption method for an H264 video stream is provided, including:
step 1, generating an encryption key stream by adopting an encryption algorithm RC 4;
step 2, scrambling and encrypting parameters related to quantization parameters in the H264 code stream;
step 3, for the intra-frame coding macro block, scrambling or scrambling encryption is carried out on the intra-frame prediction mode of the intra-frame coding macro block;
step 4, for the inter-frame coding macro block, scrambling and encrypting the difference value between the motion vector and the predicted motion vector;
and 5, carrying out scrambling encryption on residual coefficients in the H264 code stream.
Preferably, step 1 includes:
step 1.1, initializing an array S-box by using natural numbers 0-255, randomly scrambling the S-box through an input secret key, and ensuring that each element of the S-box is processed;
step 1.2, the S-box is scrambled again according to the input key, and an array keyStream of the key stream is generated.
Preferably, step 2 includes:
step 2.1, collecting images, and entering an H.264 coding stage;
step 2.2, scrambling and encrypting the picture initialization luminance quantization parameter (pic_intel_qp_minus 26) in the picture parameter set (pic_parameter_set);
step 2.3, scrambling and encrypting the offset (chroma_qp_index_offse) value of the chroma quantization parameter relative to the luma parameter;
step 2.4, scrambling and encrypting the slice syntax element slice quantization difference value (slice_qp_delta) and the macroblock layer quantization parameter (mb_qp_delta).
Preferably, in step 2, the scrambling method includes: different processing is carried out according to the current bit value of the key stream, if the bit value is 0, the original symbol is adopted, and if the bit value is 1, the symbol opposite to the original symbol is adopted;
the encryption method comprises the following steps: and carrying out normal Columbus code table coding on the scrambled parameters to obtain N bits, selecting the first 1N/2 bit in the N bits, and carrying out exclusive OR encryption on the N/2 bit and the current N/2 bit in the key stream.
Preferably, in step 3, the intra-coded macroblock is a macroblock other than the first row or the first column;
for the 16x6 intra prediction mode, scrambling only does not encrypt, including: firstly, carrying out complementary operation on a prediction mode and 3, and then carrying out normal variable length coding together with a chroma and brightness coding mode as a macro block type;
for a4x4 intra prediction mode, scrambling encryption is performed, including: then the prediction mode and 8 are complemented, then the normal variable length coding is carried out, an N-bit binary bit stream is generated, and the following N/2 bits of the bit stream and the N/2 bits of the corresponding key stream are subjected to exclusive OR encryption.
Preferably, in step 4, the motion vector of each inter-coded block has two directions, namely an X direction and a Y direction, which represent distances between the coded block and the predicted block in the X direction and the Y direction, and the difference between the motion vector in the X direction and the Y direction and the predicted motion vector is respectively represented as MVDx and MVDy; in the scrambling method for MVDx and MVDy, the MVDx value and the MVDy value are exchanged, and then the respective sign bits are scrambled according to the key stream.
Preferably, in step 5, the sign bits and magnitude values of the non-zero coefficients of the residual coefficients are scrambled.
In a second aspect, there is provided an H264 video stream real-time video encryption system configured to perform the efficient H264 video stream real-time encryption method according to any one of the first aspect, including:
the generation module is used for generating an encryption key stream by adopting an encryption algorithm RC 4;
the first scrambling and encrypting module is used for scrambling and encrypting parameters related to quantization parameters in the H264 code stream;
the second scrambling and encrypting module is used for scrambling or scrambling and encrypting the intra-frame prediction mode of the intra-frame coded macro block;
the third scrambling and encrypting module is used for scrambling and encrypting the difference value of the motion vector and the predicted motion vector of the inter-frame coded macro block;
and the fourth scrambling and encrypting module is used for scrambling and encrypting residual coefficients in the H264 code stream.
In a third aspect, a computer storage medium having a computer program stored therein is provided; the computer program, when running on a computer, causes the computer to perform the efficient H264 video stream real-time encryption method of any one of the first aspects.
The beneficial effects of the application are as follows: the application can well encrypt the video data by encrypting part of key grammar elements in the code stream of H264 during encoding, has simple and efficient encryption process, can be completed in real time at any terminal, and can be applied to real-time application scenes such as video conferences and the like.
Drawings
FIG. 1 is a schematic diagram of an H.264 coding framework;
FIG. 2 is a graph showing the image quality comparison of the paris. Cif 1 st frame before and after encryption;
FIG. 3 is a graph showing the contrast of image quality before and after encryption of the 99 th frame of the paris. Cif;
fig. 4 is a graph showing image quality comparison before and after encryption of the frame 1 of tempete.
FIG. 5 is a graph showing image quality comparison before and after encryption of a 99 th frame of tempete.
FIG. 6 is a graph of image quality contrast before and after encryption of the 1 st frame of the foreman. Qcif;
fig. 7 is a graph of image quality contrast before and after encryption of the 99 th frame of foreman.
Detailed Description
The application is further described below with reference to examples. The following examples are presented only to aid in the understanding of the application. It should be noted that it will be apparent to those skilled in the art that modifications can be made to the present application without departing from the principles of the application, and such modifications and adaptations are intended to be within the scope of the application as defined in the following claims.
Example 1:
the flow sequence of the main syntax structure of the h.264 protocol specification standard is as follows:
sps()→pps()→slice_header()→slice_data()
the slice_data () contains the marcoblock_layer () data of all the macroblocks of the slice (slice), and the marcoblock_layer () contains syntax data in the order: mb_type (intra 16x16 prediction mode) () - -mb_pre (intra 4x4 prediction mode included, mvd value) →code_block_pattern→mb_qp_delta- →residual ()
residual () contains: residual_block_calc ()
residual_block_calc () contains: trailing_ones_sign_flag, level_prefix, level_ suffix, totalZeros and RunBeform
The grammars involved in scrambling or encryption of the present application are:
pic_inteli_qp_minus 26, chroma_qp_index_offse in pps; slice_qp_delta in slice_header; mb_type (intra 16x16 prediction mode), mb_pre (intra 4x4 prediction mode included, mvd value) and residual (); the level_suffix value in residual_block_calc () of residual
Part of the syntax is explained as follows (see h.264 protocol for more details):
SPS seq_parameter_set, sequence parameter set
PPS pic_parameter_set, picture parameter set
slice_header: tape head information
SLCIDE_data, specific information of strip content
marcoblock_layer (): macroblock layer data
mb_type: macroblock type
mb_pre: macroblock prediction information
code_block_pattern: coding block mode
mb_qp_delta: macroblock quantization parameter difference
residual (): residual data variable length encoded data
residual_block_calc (): variable length encoded data using calc method
Trailing_ones_sign_flag: sign value of trailing coefficient
Level_prefix: prefix portion when CAVLC encoding non-zero and non-trailing coefficient values
Level_unification: suffix portion when CAVLC encoding non-zero and non-trailing coefficient values
TotalZeros: encoding the total number of 0 s before the last non-zero coefficient
RunBefore: number of zeros before each non-zero coefficient
On the basis, the embodiment of the application provides a selective video encryption method based on H264, which selects to encrypt a small amount of key data, thereby meeting the video security transmission, not only meeting the real-time requirement without increasing the calculation amount, but also being capable of being used on each terminal in a video conference, especially on mobile equipment with low hardware configuration such as a mobile phone, and the like, and achieving real-time high efficiency and basically unchanged compression ratio.
The application scrambles or scrambles part of key grammar data of H264 and encrypts the key grammar data at the same time, belonging to encryption in coding. The whole scrambling and encrypting process is integrated in the encoding process, and no extra independent process is needed. The real-time efficient selective video encryption method specifically comprises the following steps:
and step 1, generating an encryption key stream by adopting an encryption algorithm RC 4.
Step 1 employs a classical encryption algorithm RC4 to generate an encryption key stream. RC4 is a symmetric encryption algorithm, which encrypts each byte in the plaintext in sequence in a byte stream manner, and decrypts each byte in the ciphertext in sequence during decryption. The RC4 has the characteristics of simple algorithm, variable key length ranging from 1 byte to 256 bytes, high running speed, no increase of data length and particular suitability for real-time video application scenes. Because the video code stream has large data quantity, the whole encryption is time-consuming, the produced encrypted code stream cannot be syntactically compatible, and other decoders cannot play normally. In order to be compatible with grammar, the application only encrypts the grammar data which can still be normally played after being encrypted in the video code stream. A 256 byte length key stream is generated by using the RC4 algorithm and the key, and the 256 byte key stream is always recycled in the subsequent encryption process.
The specific method for generating the random key stream comprises the following steps:
step 1.1, initializing an array S-box by using natural numbers 0-255, randomly scrambling the S-box through an input secret key, and ensuring that each element of the S-box is processed;
step 1.2, the S-box is scrambled again according to the input key, and an array keyStream of the key stream is generated.
In the video coding encryption process, the syntax element of the video and the coded data are both called plaintext, the data in the array keyStream are called key stream (use up one bit, automatically move to the next bit, and recycle back to the beginning of the first bit after last bit), and the encrypted data are called ciphertext. The basic encryption method is that the plaintext and the key stream are subjected to exclusive or operation to obtain ciphertext.
And 2, scrambling and encrypting parameters related to quantization parameters in the H264 code stream.
The step 2 comprises the following steps:
step 2.1, collecting images, and entering an H.264 coding stage;
step 2.2, scrambling and encrypting the image initialization brightness quantization parameter in the image parameter set;
step 2.3, scrambling and encrypting the offset value of the chromaticity quantization parameter relative to the brightness parameter;
and 2.4, scrambling and encrypting the strip quantization difference value of the strip layer syntax element and the quantization parameter of the macro block layer.
The quantization parameter QP of the current macro block is determined by the image initialization brightness quantization parameter, the stripe layer syntax element stripe quantization difference value and the macro block layer quantization parameter together, the quantization is the reason of the image quality loss, and the size of the quantization parameter determines the quality of the image. Encryption of quantization parameters can effectively affect image quality. The method comprises the steps of firstly scrambling sign values by adopting the same method, wherein the scrambling method comprises the following steps: the current bit value of the key stream is processed differently, if the bit value is 0, the original symbol is adopted, and if the bit value is 1, the symbol opposite to the original symbol is adopted. The normal golomb code table coding of the scrambled parameter results in N bits of binary, the first "1" of the N bits being the flag information for the number of zeros before being calculated during decoding. To ensure stream compatibility, this "1" and its preceding zeros are unchanged, and only the N/2 bits following the first "1" are encrypted. The encryption method comprises the following steps: the N/2 bit bits are exclusive-OR encrypted with the current N/2 bit bits in the key stream.
And 3, for the intra-frame coding macro block, scrambling or scrambling encryption is carried out on the intra-frame prediction mode of the intra-frame coding macro block.
In step 3, intra prediction requires surrounding data as a prediction value, the first row lacks the above prediction data, and the first column lacks the left prediction data, which may cause decoding errors of a common decoder if intra prediction mode values of all macro blocks are encrypted, and a problem of code stream incompatibility occurs. The present application performs scrambling encryption processing only on intra prediction mode values that are not the first row or first column of macroblocks.
For the Intra prediction mode of 16×6, there are four Intra prediction modes of Intra16×16, respectively: 0 represents the vertical direction, 1 represents the horizontal direction, 2 represents the DC prediction, and 3 represents the plane. Firstly, scrambling a coding mode value, wherein the scrambling method comprises the following steps: complementary to 3, such as scrambling 2 with coding mode 1, 2 scrambling 1,0 scrambling 3. Since the prediction mode of Intra16x16 is not variable length coded alone, but is variable length coded as a macroblock type (mb_type) together with the coding modes of luminance and chrominance, the binary bit stream of mb_type is not encrypted to ensure stream compatibility.
For the 4x4 Intra prediction mode, there are 9 Intra prediction modes of Intra4x4, and the mode value is from 0 to 8. In the actual coding, when the actually used predicted value (intra_mode) is the same as the predicted value (intra_pre) which is originally predicted, the prediction mode is not coded; if the intra_mode is greater than the intra_pre, the actual code value is intra_mode minus 1, otherwise the code value is intra_mode. Firstly, scrambling the coding mode value intra_mode, wherein the scrambling method comprises the following steps: complementary to 8, the coding mode is 0 scrambling to 8,1 scrambling to 7,2 scrambling to 6,3 scrambling to 5,4 scrambling to 4,5 scrambling to 3, and so on for other values. Such scrambling may change the value of intra_mode to the predicted value pre_mode, resulting in stream incompatibility and normal decoding errors. Here, the encryption process is directly entered without performing the scrambling process for the prediction mode which is the same as the predicted value pre_mode after the scrambling. Normal golomb code table encoding of the scrambled Intra4x4 prediction mode results in N bits of binary, the first "1" of the N bits being the flag information for the number of zeros before being calculated upon decoding. To ensure stream compatibility, this "1" and its preceding zeros are unchanged, and only the N/2 bits following the first "1" are encrypted. The encryption method is the same as step 2, and will not be described here again.
And 4, for the inter-frame coding macro block, scrambling and encrypting the difference value of the motion vector and the predicted motion vector.
The motion vector refers to the distance of the current block from the corresponding best matching block in the reference frame. The size of the motion vector is very important for decoding the image, the image quality is seriously affected by the error of the motion vector, and the compatibility of the encrypted code stream is easy to realize. The motion vector of each inter-frame coding block has two directions of X direction and Y direction, which represent the distance between the coding block and the prediction block in the X direction and the Y direction, and only the difference (MVD) between the motion vector and the prediction motion vector is coded during coding, namely the MVDx in the X direction and the MVDy in the Y direction. In order to make motion estimation more accurate and reduce coded data, inter-frame macroblock coding of h.264 may divide blocks of various sizes for motion estimation, each block having its own corresponding MVDx and MVDy. The scrambling method for MVDx and MVDy comprises the following steps: the MVDx value and the MVDy value are exchanged, and then the respective sign bits are scrambled according to the key stream, if the bit value of the corresponding key stream is 0, the original sign is adopted, and if the bit is 1, the opposite sign is adopted, so that the length of the coded data, namely the size of the code stream, is basically not influenced. Then, encryption is performed again, and the encryption method is the same as that of the step 2, and will not be described here again.
And 5, carrying out scrambling encryption on residual coefficients in the H264 code stream.
The data entering the coding in the H264 protocol is the difference between the original data block and the predicted data block in the image, and the difference is quantized after DCT change and then becomes a residual coefficient. The residual coefficient is coded by CAVLC (Context-based Adaptive Variable Length Coding) to become H264 code stream part to be output. The code stream of H264 is mostly residual coefficients, and encryption of residual coefficients can more effectively destroy the visual quality of the image. The residual coefficient encoding steps are as follows: (1) The number of non-zero coefficients in the encoded block (TotalCoeffs) and the number of tail coefficients with absolute value 1 (TrailingOnes, also called trailing coefficient number, up to three) and the number of zeros before the last non-zero coefficient (Total zeros) are determined. (2) judging and calculating NC value: the chromaticity direct current coefficient nc= -1; other coefficient type NC values are found from the number of non-zero coefficients (NA) for the 4*4 block to the left of the current block and the number of non-zero coefficients (NB) for the 4*4 block above the current block. (3) All Trailing coefficient sign bits (trailing_ones_sign_flag) are encoded. (4) The prefix portion Level _ prefix and its suffix portion (Level _ suffix) of the non-zero coefficients of the non-trailing coefficients are encoded. (5) Number of 0 before the last non-zero coefficient is encoded (totalzeroes). (6) The number of zeros before each non-zero coefficient is encoded (RunBefore).
In order to ensure compatibility of the encrypted code stream, only sign bits and amplitude values of non-zero coefficients in residual coefficients are encrypted, namely, the step (3) and the step (4) in the above steps. The Trailing coefficients in the non-zero coefficients have magnitudes of 1, the H.264 does not encode the magnitudes of the Trailing coefficients, and only the sign bits of the Trailing coefficients are encoded, namely the trailing_ones_sign_flag in the step (3). Each Trailing coefficient has a bit of trailing_ones_sign_flag and the current bit value of the key stream is exclusive-or encrypted. The non-trailing non-zero coefficient Level is converted into a non-negative number Level code according to a formula, and then the Level code is subjected to variable length coding. The patent scrambles the sign bit of this nonzero coefficient Level earlier, specifically does: the current bit value of the key stream is processed differently, if the bit value is 0, the original symbol is adopted, and if the bit value is 1, the symbol opposite to the original symbol is adopted. The scrambled Level value is then converted conventionally into a Level code, and the level_prefix value and the level_diffix value are then encoded according to the Level code calculated. The encoding of the level_prefix value corresponds to a fixed code table, and if encryption occurs, the code stream is not compatible, and the level_prefix is not encrypted; exclusive-or encryption is performed only on the encoded level_unification portion and the key corresponding bit number.
Example 2:
on the basis of embodiment 1, embodiment 2 of the present application provides a more specific H264-based selective video encryption method.
The coding framework specified by the h.264 protocol is shown in fig. 1.
Wherein, the coding flow of I frame: the method comprises the steps of selecting a current image frame Fn, selecting an intra-frame prediction mode, selecting an optimal intra-frame prediction mode, performing intra-frame prediction to obtain a predicted block (P), subtracting a pixel value of a position corresponding to the predicted block P from the current block according to the pixel value to obtain a difference Dn, performing DCT (discrete cosine transform), and then quantizing to obtain a residual coefficient X. X has two places, one places is to enter into Zig-zag scanning rearrangement, enter into entropy coding link, and finally become NAL unit data, namely H.264 code stream. The other pass of X is to enter inverse quantization and inverse DCT transform to obtain decoded residual coefficients Dn ' and add to the previous prediction block P to obtain an image uFn ' and to obtain a reconstructed image frame Fn ' through loop filtering (Filter). The following P-frame prediction is based on reconstructed image Fn' as reference image. The actual encoding process is performed in units of macro blocks, and the processing unit of the above process is also macro blocks, but the size of the prediction block may be a16x16 block or a4x4 block.
Coding flow of P frame: the current image frame Fn is predicted both intra-and inter-and then an optimal prediction is selected. Fn first enters a motion estimation module to obtain an optimal inter prediction mode and a motion vector, and then enters a motion compensation module. Fn enters an intra prediction module (as in I-frame procedure above) to obtain the best intra prediction mode. Then, the optimal prediction mode is selected in the intra and inter frames to generate a prediction block P. The following flow is the same as I frame coding, and enters DCT transformation, quantization, zig-zag scanning rearrangement and entropy coding to generate H.264 code stream.
In order not to influence the subsequent encoding process of H.264, the processing process of the application is carried out in the entropy encoding process of FIG. 1, only has influence on the code stream, has no influence on the reconstructed image, and can ensure that the image quality after decryption is unchanged.
Specifically, the embodiment of the application takes a video conference application scene as an example to describe the implementation process of the application.
Firstly, generating a key stream of 256 bytes by adopting an RC4 algorithm and an encryption key, and then, the encryption process always loops the key stream of 256 bytes.
Then the image is acquired and the H.264 coding stage is entered. In the encoding process, the images in the image parameter set which are firstly encountered initialize the offset values of the brightness quantization parameter and the chromaticity quantization parameter relative to the brightness parameter, scramble the positive and negative signs according to the key stream, adopt the original sign if the corresponding key stream bit is 0, and adopt the sign opposite to the original sign if the corresponding key stream bit is 1. And carrying out variable length coding on the offset of the brightness quantization parameter and the chromaticity quantization parameter of the scrambled image initialization relative to the brightness parameter according to the H.264 standard protocol, generating an N-bit binary bit stream, and carrying out exclusive-OR encryption on the rear N/2 bits of the bit stream and the N/2 bits of the corresponding key stream.
In coding order, the slice layer syntax element slice quantized difference values in the H264 bitstream are then scrambled. The quantization parameter calculation method of the stripe layer comprises the steps of adding a stripe quantization difference value to the last stripe parameter to the first frame QPslcie=26+pic_intel_qp_minus26+slice_qp_delta, and adding the stripe quantization difference value to the last frame of stripe layer quantization parameter to obtain the first frame QPslcie=QPslice-pre+slice_qp_delta.
The stripe quantization difference value is positive or negative, and the sign bit is firstly scrambled, and the scrambling method comprises the following steps: the current bit value of the key stream is processed differently, if the bit value is 0, the original symbol is adopted, and if the bit value is 1, the symbol opposite to the original symbol is adopted. And normally encoding the scrambled stripe quantization difference value to obtain an N-bit binary system, and performing exclusive-OR encryption on the rear N/2 bits of the bit stream and the N/2 bits of the corresponding key stream.
In coding order, the first frame is then coded. Since the first frame is an intra-coded frame, all its macroblocks are intra-coded. For macroblocks in the first row or outside the first column, the prediction mode is scrambled or scrambled. If the prediction mode is the intra prediction mode of 16x6, only scrambling the prediction mode and not encrypting the prediction mode; the prediction mode and 3 are subjected to complementary operation, and then the prediction mode and the chroma and brightness coding mode are used as mb_type to perform normal variable length coding. If the prediction mode is the intra-frame prediction mode of 4x4, the prediction mode and 8 are subjected to complementary operation, normal variable length coding is performed, an N-bit binary bit stream is generated, and the following N/2 bits of the bit stream and the N/2 bits of the corresponding key stream are subjected to exclusive-OR encryption.
The macroblock layer quantization parameter mb_qp_delta is then scrambled in coding order. The quantization parameter QPcur of the current macroblock is the sum of the quantization parameters QPpre of the previous macroblock (qpcur=qppre+mb_qp_delta). The range of mb_qp_delta values is (-26, 25), and the sign bits are firstly scrambled by the following scrambling method: the original symbol is used if the current bit value of the key stream is 0, and the opposite symbol is used if the bit value is 1. And performing normal variable length coding on the scrambled mb_qp_delta to obtain an N-bit binary system, and performing exclusive-OR encryption on the rear N/2 bits of the bit stream and the N/2 bits of the corresponding key stream to ensure the compatibility of the bit stream.
And then carrying out variable length coding on the residual coefficient of the macro block, wherein the corresponding encryption process is as follows: the sign bits and magnitude values of non-zero coefficients in the residual coefficients are encrypted. The Trailing coefficient in the non-zero coefficient only encodes the symbol bit trailing_ones_sign_flag of the Trailing coefficient because the H.264 protocol does not encode the amplitude; there is one bit of Trailing _ ones _ sign _ flag for each Trailing coefficient and the current bit value of the key stream is exclusive-or encrypted. The other nonzero coefficient Level is positive and negative, and the normal coding process is to convert into a nonnegative coefficient Level code and then code. The patent scrambles the sign bit of this nonzero coefficient Level earlier, specifically does: the current bit value of the key stream is processed differently, if the bit value is 0, the original symbol is adopted, and if the bit value is 1, the symbol opposite to the original symbol is adopted. Then the conversion is carried out conventionally into a levecode, and the codes are encoded according to the level_prefix value and the level_suffix value calculated by the levecode. The encoding of the level_prefix value corresponds to a fixed code table, and if the encryption is incompatible with the decoding, the level_prefix is not encrypted; and only encrypting the coded level_mix part, wherein the encryption method is exclusive-or encryption with the bit number corresponding to the key stream.
Each macroblock is then coded and scrambled in a loop until the last macroblock in the first frame ends and the next frame is coded. And firstly, scrambling, encrypting and encoding the strip quantization difference value of the strip layer syntax element in the H264 code stream, and finishing the method as before. Since the second frame is an inter-prediction encoded P frame, there may be an intra-prediction macroblock and an inter-prediction macroblock. In the case of intra-predicted macroblocks, the scrambling method is the same as that of previous intra-predicted macroblocks. If the macroblock is inter-frame predictive coding, the MVDx and MVDy are scrambled and encrypted: the MVDx value and the MVDy value are exchanged with each other, then the positive and negative sign bits are scrambled, if the corresponding key stream bit value is 0, the original sign is adopted, and if the bit is 1, the opposite sign is adopted. And carrying out normal variable length coding on the scrambled MVDx and MVDy to obtain an N-bit binary system, and carrying out exclusive or encryption on the latter N/2-bit and the current N/2-bit in the key stream.
The macroblock layer quantization parameter mb_qp_delta is then scrambled, encoded, and encrypted in the same way as the macroblock of the first frame.
The residual coefficients of each block in the macroblock are then scrambled, encoded and encrypted in the same way as the macroblock of the first frame.
And (5) circularly processing all macro blocks of the second frame and entering a third frame coding process. The third frame scrambling, encoding and encryption process is identical to the second frame and so on to each subsequent frame. If the frame is the P frame, the method is the same as the second frame; in the case of an I frame, the method is the same as the first frame.
For each 100 frames of the classical sequences of the H.264 coding, namely the pa ris.cif, the tempete.cif and the foreman.qcif, the target code rate of the CIF sequence is 384Kbits/s, and the target code rate of the Qcif sequence is 128Kbits/s. The data before and after encryption are compared as shown in table 1 below. As can be seen from the table, after encryption, the PSNR value representing the image quality is greatly reduced; but the code rate and coding time are substantially unchanged. The encrypted code stream is completely compatible with other standard H.264 decoders, and can be normally decoded by using an FFMPEG decoder with an open source, and the crash condition can not occur.
TABLE 1 comparison of PSNR before and after encryption, code Rate and coding time
The image quality before and after encryption is shown in fig. 2-7, and the image after encryption can not be recognized by human eyes, so that the image information is effectively protected.
In this embodiment, the same or similar parts as those in embodiment 1 may be referred to each other, and will not be described in detail in the present disclosure.
Example 3:
on the basis of embodiments 1 and 2, embodiment 3 of the present application provides an H264 video stream real-time video encryption system, including:
the generation module is used for generating an encryption key stream by adopting an encryption algorithm RC 4;
the first scrambling and encrypting module is used for scrambling and encrypting parameters related to quantization parameters in the H264 code stream;
the second scrambling and encrypting module is used for scrambling or scrambling and encrypting the intra-frame prediction mode of the intra-frame coded macro block;
the third scrambling and encrypting module is used for scrambling and encrypting the difference value of the motion vector and the predicted motion vector of the inter-frame coded macro block;
and the fourth scrambling and encrypting module is used for scrambling and encrypting residual coefficients in the H264 code stream.
Specifically, the system provided in this embodiment is a system corresponding to the method provided in embodiments 1 and 2, so that the portions in this embodiment that are the same as or similar to those in embodiments 1 and 2 may be referred to each other, and will not be described in detail in this disclosure.

Claims (9)

1. An efficient H264 video stream real-time encryption method, comprising:
step 1, generating an encryption key stream by adopting an encryption algorithm RC 4;
step 2, scrambling and encrypting parameters related to quantization parameters in the H264 code stream;
step 3, for the intra-frame coding macro block, scrambling or scrambling encryption is carried out on the intra-frame prediction mode of the intra-frame coding macro block;
step 4, for the inter-frame coding macro block, scrambling and encrypting the difference value between the motion vector and the predicted motion vector;
and 5, carrying out scrambling encryption on residual coefficients in the H264 code stream.
2. The efficient H264 video stream real-time encryption method of claim 1, wherein step 1 comprises:
step 1.1, initializing an array S-box by using natural numbers 0-255, randomly scrambling the S-box through an input secret key, and ensuring that each element of the S-box is processed;
step 1.2, the S-box is scrambled again according to the input key, and an array keyStream of the key stream is generated.
3. The efficient H264 video stream real-time encryption method of claim 2, wherein step 2 comprises:
step 2.1, collecting images, and entering an H.264 coding stage;
step 2.2, scrambling and encrypting the image initialization brightness quantization parameter in the image parameter set;
step 2.3, scrambling and encrypting the offset value of the chromaticity quantization parameter relative to the brightness parameter;
and 2.4, scrambling and encrypting the strip quantization difference value of the strip layer syntax element and the quantization parameter of the macro block layer.
4. The efficient H264 video stream real-time encryption method of claim 3 wherein in step 2, the scrambling method comprises: different processing is carried out according to the current bit value of the key stream, if the bit value is 0, the original symbol is adopted, and if the bit value is 1, the symbol opposite to the original symbol is adopted;
the encryption method comprises the following steps: and carrying out normal Columbus code table coding on the scrambled parameters to obtain N bits, selecting the first 1N/2 bit in the N bits, and carrying out exclusive OR encryption on the N/2 bit and the current N/2 bit in the key stream.
5. The efficient H264 video stream real-time encryption method according to claim 4, wherein in step 3, the intra-coded macroblock is a macroblock other than the first row or first column;
for the 16x6 intra prediction mode, scrambling only does not encrypt, including: firstly, carrying out complementary operation on a prediction mode and 3, and then carrying out normal variable length coding together with a chroma and brightness coding mode as a macro block type;
for a4x4 intra prediction mode, scrambling encryption is performed, including: then the prediction mode and 8 are complemented, then the normal variable length coding is carried out, an N-bit binary bit stream is generated, and the following N/2 bits of the bit stream and the N/2 bits of the corresponding key stream are subjected to exclusive OR encryption.
6. The efficient H264 video stream real-time encryption method according to claim 5, wherein in step 4, each inter-frame coded block has two motion vectors, i.e., X-direction and Y-direction, representing distances between the coded block and the predicted block in the X-direction and Y-direction, and differences between the motion vectors in the X-direction and Y-direction and the predicted motion vectors are respectively represented as MVDx and MVDy; in the scrambling method for MVDx and MVDy, the MVDx value and the MVDy value are exchanged, and then the respective sign bits are scrambled according to the key stream.
7. The efficient H264 video stream real-time encryption method according to claim 6, wherein in step 5, the sign bits and magnitude values of the non-zero coefficients of the residual coefficients are scrambled and encrypted.
8. An H264 video stream real-time video encryption system for performing the efficient H264 video stream real-time encryption method of any one of claims 1 to 7, comprising:
the generation module is used for generating an encryption key stream by adopting an encryption algorithm RC 4;
the first scrambling and encrypting module is used for scrambling and encrypting parameters related to quantization parameters in the H264 code stream;
the second scrambling and encrypting module is used for scrambling or scrambling and encrypting the intra-frame prediction mode of the intra-frame coded macro block;
the third scrambling and encrypting module is used for scrambling and encrypting the difference value of the motion vector and the predicted motion vector of the inter-frame coded macro block;
and the fourth scrambling and encrypting module is used for scrambling and encrypting residual coefficients in the H264 code stream.
9. A computer storage medium, wherein a computer program is stored in the computer storage medium; the computer program, when run on a computer, causes the computer to perform the efficient H264 video stream real-time encryption method of any one of claims 1 to 7.
CN202311144328.6A 2023-09-06 2023-09-06 Efficient H264 video stream real-time encryption method Pending CN117119226A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202311144328.6A CN117119226A (en) 2023-09-06 2023-09-06 Efficient H264 video stream real-time encryption method

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202311144328.6A CN117119226A (en) 2023-09-06 2023-09-06 Efficient H264 video stream real-time encryption method

Publications (1)

Publication Number Publication Date
CN117119226A true CN117119226A (en) 2023-11-24

Family

ID=88805424

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202311144328.6A Pending CN117119226A (en) 2023-09-06 2023-09-06 Efficient H264 video stream real-time encryption method

Country Status (1)

Country Link
CN (1) CN117119226A (en)

Similar Documents

Publication Publication Date Title
US6920175B2 (en) Video coding architecture and methods for using same
US6160503A (en) Deblocking filter for encoder/decoder arrangement and method with divergence reduction
US7006631B1 (en) Method and system for embedding binary data sequences into video bitstreams
Wang et al. A tunable encryption scheme and analysis of fast selective encryption for CAVLC and CABAC in H. 264/AVC
US20020122491A1 (en) Video decoder architecture and method for using same
US7221761B1 (en) Error resilient digital video scrambling
JP2005533468A (en) Method and apparatus for transform coding between hybrid video codec bitstreams
CN110677694A (en) Video encryption method for resisting contour attack
Joy et al. An overview of traditional and recent trends in video processing
Dubois et al. Smart selective encryption of CAVLC for H. 264/AVC video
Wang et al. The improved sign bit encryption of motion vectors for H. 264/AVC
Raja et al. Performance comparison of advanced video coding H. 264 standard with baseline H. 263 and H. 263+ standards
Luthra et al. Overview of the H. 264/AVC video coding standard
Takayama et al. A video scrambling scheme applicable to local region without data expansion
CN117119226A (en) Efficient H264 video stream real-time encryption method
Lee et al. Low complexity controllable scrambler/descrambler for H. 264/AVC in compressed domain
Joshi et al. Selective encryption using ISMACryp in real time video streaming of H. 264/AVC for DVB-H application
CN108900868B (en) Video transmission method, device and storage medium based on H.264
Saleh et al. Fast selective encryption for video stream of high efficiency video coding standard
Shahid et al. Fast protection of H. 264/AVC by selective encryption of CABAC for I & P frames
KR101375302B1 (en) Apparatus and method of processing multimedia data
Lei et al. A new H. 264 video encryption scheme based on chaotic cipher
Qi et al. Research on CAVLC audio-video synchronization coding approach based on H. 264
Varlakshmi et al. An efficient scalable video encryption scheme for real time applications
Khlif et al. Selective encryption of CAVLC for H. 264/AVC

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination