Disclosure of Invention
In view of the above, the present invention provides a method and a system for scrambling and descrambling a video, so as to improve the convenience of scrambling and descrambling and ensure the decoding performance of a scrambled code stream.
In a first aspect, an embodiment of the present invention provides a video scrambling and descrambling method, where the method includes:
scrambling control is carried out on the original video by adopting scrambling control parameters to obtain a converted video image;
coding the converted video image and self-defining the scrambling control parameter to obtain a video code stream of an auxiliary scrambling parameter unit;
decoding the video code stream of the auxiliary scrambling parameter unit to obtain the converted video image and the scrambling control parameter;
and performing descrambling control on the transformed video image according to the scrambling control parameter to obtain a reconstructed video.
With reference to the first aspect, an embodiment of the present invention provides a first possible implementation manner of the first aspect, where performing cluster scrambling processing on an original video by using a scrambling control parameter to obtain a transformed video image, where the implementing manner includes:
dividing an image of the original video into a plurality of areas according to an application scene, and dividing each area into three color channel plane areas according to a color space;
calculating to obtain a pixel average value in each color channel plane area by adopting a mean clustering method, wherein the scrambling control parameters comprise the area boundary of the area and the pixel average value;
shifting all pixel point values in each color channel plane area according to the pixel average value to obtain a pixel difference value plane area;
all pixel difference plane regions in all regions constitute the transformed video image.
With reference to the first possible implementation manner of the first aspect, an embodiment of the present invention provides a second possible implementation manner of the first aspect, where calculating an average value of pixels in each color channel plane region of each region by using a mean clustering method includes:
and acquiring all pixel point values in each color channel plane area of each area, and performing clustering calculation on all pixel point values by adopting the mean clustering method to obtain the pixel average value.
With reference to the first aspect, an embodiment of the present invention provides a third possible implementation manner of the first aspect, where the encoding the transform video image and the customizing the scrambling control parameter to obtain a video code stream of an auxiliary scrambling parameter unit includes:
coding the converted video image in a video coder to obtain a video code stream;
according to the form of video code stream standard of the video encoder, the scrambling control parameter is customized by a user to generate a scrambling parameter unit;
and attaching the scrambling parameter unit to the video code stream to obtain the video code stream of the attached scrambling parameter unit.
With reference to the third possible implementation manner of the first aspect, an embodiment of the present invention provides a fourth possible implementation manner of the first aspect, where the video bitstream standard is h.264 or h.265.
In a second aspect, an embodiment of the present invention further provides a video scrambling/descrambling system, where the system includes:
the clustering video scrambling module is used for scrambling and controlling the original video by adopting scrambling control parameters to obtain a conversion video image;
the video coding module is used for coding the converted video image and self-defining the scrambling control parameter to obtain a video code stream of an auxiliary scrambling parameter unit;
the video decoding module is used for decoding the video code stream of the auxiliary scrambling parameter unit to obtain the converted video image and the scrambling control parameter;
and the clustered video descrambling module is used for descrambling and controlling the transformed video image according to the scrambling control parameter to obtain a reconstructed video.
With reference to the second aspect, an embodiment of the present invention provides a first possible implementation manner of the second aspect, where the clustered video scrambling module includes:
dividing an image of the original video into a plurality of areas according to an application scene, and dividing each area into three color channel plane areas according to a color space;
calculating to obtain a pixel average value in each color channel plane area by adopting a mean clustering method, wherein the scrambling control parameters comprise the area boundary of the area and the pixel average value;
shifting all pixel point values in each color channel plane area according to the pixel average value to obtain a pixel difference value plane area;
all pixel difference plane regions in all regions constitute the transformed video image.
With reference to the first possible implementation manner of the second aspect, an embodiment of the present invention provides a second possible implementation manner of the second aspect, where calculating an average value of pixels in each color channel plane region of each region by using a mean value clustering method includes:
and acquiring all pixel point values in each color channel plane area of each area, and performing clustering calculation on all pixel point values by adopting the mean clustering method to obtain the pixel average value.
With reference to the second aspect, an embodiment of the present invention provides a third possible implementation manner of the second aspect, where the video encoding module includes:
coding the converted video image in a video coder to obtain a video code stream;
according to the form of video code stream standard of the video encoder, the scrambling control parameter is customized by a user to generate a scrambling parameter unit;
and attaching the scrambling parameter unit to the video code stream to obtain the video code stream of the attached scrambling parameter unit.
With reference to the third possible implementation manner of the second aspect, an embodiment of the present invention provides a fourth possible implementation manner of the second aspect, where the video stream standard is h.264 or h.265.
The embodiment of the invention has the following beneficial effects:
the video scrambling and descrambling method and system provided by the invention comprise the following steps: scrambling control is carried out on the original video by adopting scrambling control parameters to obtain a converted video image; coding the converted video image and self-defining the scrambling control parameter to obtain a video code stream of an auxiliary scrambling parameter unit; decoding the video code stream of the auxiliary scrambling parameter unit to obtain a converted video image and a scrambling control parameter; and performing descrambling control on the transformed video image according to the scrambling control parameter to obtain a reconstructed video. The invention can improve the convenience of scrambling and descrambling and ensure the decoding and descrambling performance of the scrambled code stream.
Additional features and advantages of the invention will be set forth in the description which follows, and in part will be obvious from the description, or may be learned by practice of the invention. The objectives and other advantages of the invention will be realized and attained by the structure particularly pointed out in the written description and claims hereof as well as the appended drawings.
In order to make the aforementioned and other objects, features and advantages of the present invention comprehensible, preferred embodiments accompanied with figures are described in detail below.
Detailed Description
To make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings, and it is apparent that the described embodiments are some, but not all embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
At present, a scrambling mode is often adopted to encrypt a video, reversible change is performed on syntax elements in the process of H.264 or H.265 coding, and standard compatibility of the syntax elements is maintained, so that the purpose of scrambling a video code stream is achieved. The prior scheme has the defects that the scrambling process of video content is built in a video encoder, and the descrambling process is built in a video decoder, so that the codec is not universal any more, and a special codec is required to achieve the scrambling and descrambling functions. Moreover, due to the complexity of decoding operations, and since video decoding generally uses a hardware accelerator (such as a graphics processor) for decoding, such transcoding can only be performed in the decoder memory using CPU instructions, which significantly reduces the decoding performance of the decoder.
Based on this, the video scrambling and descrambling method and system provided by the embodiment of the invention can improve the convenience of scrambling and descrambling and ensure the decoding performance of the scrambled code stream.
For the convenience of understanding the present embodiment, a detailed description will be first given of a video scrambling/descrambling method disclosed in the present embodiment.
The first embodiment is as follows:
fig. 1 is a schematic diagram of a video scrambling and descrambling method according to an embodiment of the present invention.
In this embodiment, a preprocessing step is added before the original video coding, the video coding is performed on the preprocessed converted video image, and meanwhile, a user-defined scrambling parameter Unit, such as h.265nalu (Network Abstract Layer Unit) or h.264nalu, is formed by using the preprocessed control parameters in a form that meets the video code stream standard, and the scrambling parameter Unit is attached to the video code stream. The code stream formed in the way can be decoded by a decoder compatible with H.264 or H.265 of a third party, and the third party decoder cannot decode due to the term user-defined by the additional scrambling parameter unit, only can obtain a converted video image, and cannot perform further decoding post-processing on the converted video image, so that the purpose of video scrambling under the unauthorized condition is achieved.
Referring to fig. 1, the encoding-side flow is as follows: a clustering video scrambling module is added before an H.264 or H.265 video encoder, and a transformed video image is obtained after the original video is subjected to clustering scrambling processing. Converting the video image and inputting the video image into a standard H.264 or H.265 encoder for encoding to obtain a code stream; and generating a user-defined scrambling parameter unit according to the scrambling control parameter required by the clustering video scrambling module and the requirement of H.264 or H.265, wherein the user-defined scrambling parameter unit is attached to the H.264 or H.265 code stream.
The decode side flow is as follows: decoding the code stream compatible with the standard in an H.264 or H.265 video decoder to obtain a converted video image, and simultaneously decoding and analyzing the additional scrambling parameter unit to obtain a scrambling control parameter; the converted video image and the scrambling control parameter are simultaneously input to a clustering video descrambling module, and reversible scrambling processing operation (namely descrambling processing operation) is carried out on the converted video image to obtain a reconstructed video. The reconstructed video is identical to the original video in image detail clarity.
By analyzing the above-mentioned principle of the encoding side and the decoding side, the video scrambling and descrambling method can be obtained, which includes the following contents, referring to fig. 2:
step S110, scrambling control is carried out on the original video by adopting scrambling control parameters to obtain a converted video image;
step S120, coding the converted video image and self-defining the scrambling control parameter to obtain a video code stream of an auxiliary scrambling parameter unit;
the method specifically comprises the following steps: coding the converted video image in a video coder to obtain a video code stream; according to the form of video code stream standard conforming to the video encoder, the scrambling control parameter is customized by a user to generate a scrambling parameter unit; and attaching the scrambling parameter unit to the video code stream to obtain the video code stream of the attached scrambling parameter unit. Here, the video stream standard may be h.264 or h.265.
Step S130, decoding the video code stream of the auxiliary scrambling parameter unit to obtain a converted video image and a scrambling control parameter;
and step S140, descrambling control is carried out on the transformed video image according to the scrambling control parameter to obtain a reconstructed video.
Example two:
fig. 3 is a schematic diagram of clustering region partitioning according to a second embodiment of the present invention.
The video image is generally divided into a moving foreground and a stationary background as shown in fig. 3-a, while for the surveillance video image, the scene is fixed, but the surveillance scene is divided into a Region Of Interest (ROI) and a non-ROI Region as shown in fig. 3-B.
For both fig. 3-a and 3-B, there is an equal division into area 1 and area 2. According to different types of actual scenes, the area 1 may have multiple parts, which can be sequentially represented as an area 1-1, an area 1-2, an area 1-3 and the like, and the area 2 can be divided into an area 2-1, an area 2-2 and the like; for region X-Y, the letter "X" indicates the region type and the letter "Y" indicates the region number. For practical scenarios other than that shown in fig. 3, the number of region types is typically at least 2, and the number of regions of each type is typically at least one.
The original video to be coded has a color space of RGB (Red, Green, Bblue, Red, Green, blue), YUV (Brightness, chroma), or ICTCP(International Color Consortium, International Color Association). For the RGB color space, there are R color channel, G color channel, B color channel, respectively, that is, there are three color planes correspondingly: r color plane, G color plane, B color plane. For the YUV color space, there are a Y color channel, a U color channel, and a V color channel, i.e. there are three color planes correspondingly: y color plane, U color plane, V color plane. To ICTCPColor space, with I color channel, CTColor channel, CPColor channels, i.e. there are three color planes for each: i color plane, CTColor plane, CPA color plane.
For the region classification of the type of fig. 3-B, a total of K regions are assumed. And obtaining the average value of the pixel values of all the pixel points in each type of region in each color plane by using a mean value clustering method. And (3) using a mean clustering algorithm to obtain a mean value of all pixel values in each color plane of each region of the whole image. K mean values are obtained for each color plane, and K × 3 pixel mean values are obtained for all color planes. For the whole image, similar to performing the K-Means local clustering algorithm, where K denotes K regions. The whole flow is shown in fig. 4, and is divided into 8 steps:
step S210, dividing the image of the original video into K areas according to the application scene; i.e. dividing the image into K regions, each region denoted R, by foreground, background or ROI region, non-ROI regioniI is 0,1, …, K-1. According to the color space, each region RiDivided into three color channel plane regions Rij,j=0,1,2。
Step S220, judging whether the current region is the Kth region; and in the case of no, performing step S230; and, in case of yes, indicating that the repetition process of the entire image entire area has been completed, step S260 may be performed.
Step S230, determining whether the color channel is a third color channel plane area; and in the case of no, performs step S240; and, in the case of yes, the repetition process indicating the area of all color channel planes of the area is completed, and the calculation may be performed for the next area, i.e., step S220 is repeatedly performed.
Step S240, calculating by adopting a mean value clustering method to obtain a jth color channel plane region R of an ith regionijInner pixel mean value MijObtaining the planar area R of each color channelijInner pixel mean value Mij. Wherein the scrambling control parameters mainly include the region boundary of the region in step S210 and the pixel average value M of the stepij. First, each color channel plane region R of each region is acquiredijAll pixel point values P withinij_xyUsing mean value clustering method to calculate all pixel point values Pij_xyPerforming clustering calculation to obtain pixel average value Mij. Here, (x, y) is the coordinates of the pixel points in the area.
Step S250, in the jth color channel plane region R of the ith regionijIn accordance with the pixel average value MijFor all pixel point values Pij_xyShifting to obtain a pixel difference value plane area delta PijI.e. all pixel point values Pij_xyMinus its corresponding mean value Mij,ΔPij=Pij_xy-Mij。
Step S260, obtainingTo the plane area delta P consisting of all pixel differences in the K areasijThe constituent transformed video images Δ Pic. In particular, three color planes Δ P per regioniTogether forming a transformed image region Δ RiAll K regions constitute a complete transformed video image Δ Pic. Although the color space of the Δ Pic is the same as that of the original image, due to the shift of the pixel value, the sharp details in the original video image cannot be seen by using the conventional image viewing software (for example, the transformed image in RGB color space is coded in the BMP format, and the picture content is viewed by using the picture viewer carried by the windows operating system), that is, the transformed video image obtained by such operation achieves the purpose of video scrambling.
Step S270, encoding the converted video image in a video encoder to obtain a video code stream;
step S280, the scrambling control parameter is customized by a user, a scrambling parameter unit is generated, and the scrambling parameter unit is attached to the video code stream.
The complete transformed video image delta Pic is used as input and is input to an H.264 or H.265 encoder for encoding, the generated H.264 or H.265 code stream is decoded by using a standard H.264 or H.265 decoder, the obtained reconstructed image is still scrambled, and the observed content color and detail are still different from the original image. Therefore, in order to restore the color and detail of the transformed video image to be the same as the original video image, it is necessary to attach control parameters in the form of a user-defined scrambling parameter unit compatible with the standard h.264 or h.265 to the h.264 or h.265 video code stream so as to be able to perform a descrambling operation on the transformed video image which is decoded and output. The scrambling control parameters mainly comprise region boundaries of K regions and pixel average values of color planes of each region, and the region boundaries are straight lines or dividing lines of curves.
The schemes provided by the embodiments are used for scrambling control of the video images in the monitoring system, the scrambling module is designed to consider the actual use scene of the video monitoring to divide the region types, so that the scrambling module is separated from the descrambling module, the video code stream can be decoded by a third-party decoder, and meanwhile, the video descrambling is presented as a post-processing module after the video images are decoded, so that the purpose of more convenient scrambling and descrambling is achieved.
The descrambling operation shown in fig. 5 is performed after the decoding of h.264/h.265, and belongs to the image processing link. The image processing stage in a typical decoder is prior to image rendering, and this step can be implemented using a hardware acceleration engine (such as a GPU). Meanwhile, the decoded image can be descrambled by directly using a hardware acceleration engine in a video memory. The processing flow remarkably ensures the performance of decoding and descrambling the scrambled code stream.
Example three:
fig. 6 is a schematic diagram of a video scrambling and descrambling system provided by a third embodiment of the present invention.
The video scrambling and descrambling system provided by the embodiment is used for realizing the video scrambling and descrambling method in the embodiment. Referring to fig. 6, the video scrambling/descrambling system includes the following modules:
the clustered video scrambling module 100 is configured to perform scrambling control on an original video by using a scrambling control parameter to obtain a transformed video image;
the video coding module 200 is used for coding the converted video image and self-defining the scrambling control parameter to obtain a video code stream of an auxiliary scrambling parameter unit;
the video decoding module 300 is configured to decode the video code stream of the attached scrambling parameter unit to obtain a converted video image and a scrambling control parameter;
and the clustered video descrambling module 400 is used for performing descrambling control on the transformed video image according to the scrambling control parameter to obtain a reconstructed video.
Further, the clustered video scrambling module 100 includes:
dividing an image of an original video into a plurality of areas according to an application scene, and dividing each area into three color channel plane areas according to a color space;
calculating to obtain the pixel average value in each color channel plane area by adopting a mean clustering method, wherein the scrambling control parameters comprise the area boundary and the pixel average value of the area;
shifting all pixel point values in each color channel plane area according to the pixel average value to obtain a pixel difference value plane area;
all pixel difference plane regions in all regions constitute a transformed video image.
Further, calculating the average value of pixels in each color channel plane area of each area by using a mean clustering method, including:
and acquiring all pixel point values in each color channel plane area of each area, and performing clustering calculation on all pixel point values by adopting a mean clustering method to obtain a pixel average value.
Further, the video encoding module 200 includes:
coding the converted video image in a video coder to obtain a video code stream;
according to the form of video code stream standard conforming to the video encoder, the scrambling control parameter is customized by a user to generate a scrambling parameter unit;
and attaching the scrambling parameter unit to the video code stream to obtain the video code stream of the attached scrambling parameter unit.
Here, the video stream standard is h.264 or h.265.
The embodiment of the invention has the following beneficial effects:
the video scrambling and descrambling method and system provided by the invention comprise the following steps: scrambling control is carried out on the original video by adopting scrambling control parameters to obtain a converted video image; coding the converted video image and self-defining the scrambling control parameter to obtain a video code stream of an auxiliary scrambling parameter unit; decoding the video code stream of the auxiliary scrambling parameter unit to obtain a converted video image and a scrambling control parameter; and performing descrambling control on the transformed video image according to the scrambling control parameter to obtain a reconstructed video. The invention can improve the convenience of scrambling and descrambling and ensure the decoding and descrambling performance of the scrambled code stream.
The embodiment of the present invention further provides an electronic device, which includes a memory and a processor, where the memory stores a computer program that can be run on the processor, and the processor implements the steps of the video scrambling and descrambling method provided in the above embodiment when executing the computer program.
The embodiment of the invention also provides a computer-readable storage medium, wherein a computer program is stored on the computer-readable storage medium, and when the computer program is executed by a processor, the steps of the video scrambling and descrambling method of the embodiment are executed.
The computer program product for performing a video scrambling and descrambling method provided in the embodiments of the present invention includes a computer-readable storage medium storing a nonvolatile program code executable by a processor, where instructions included in the program code may be used to execute the method described in the foregoing method embodiments, and specific implementation may refer to the method embodiments, and will not be described herein again.
It is clear to those skilled in the art that, for convenience and brevity of description, the specific working processes of the above-described systems, apparatuses and units may refer to the corresponding processes in the foregoing method embodiments, and are not described herein again.
In the several embodiments provided in the present application, it should be understood that the disclosed system, apparatus and method may be implemented in other ways. The above-described embodiments of the apparatus are merely illustrative, and for example, the division of the units is only one logical division, and there may be other divisions when actually implemented, and for example, a plurality of units or components may be combined or integrated into another system, or some features may be omitted, or not executed. In addition, the shown or discussed mutual coupling or direct coupling or communication connection may be an indirect coupling or communication connection of devices or units through some communication interfaces, and may be in an electrical, mechanical or other form.
The units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purpose of the solution of the embodiment.
In addition, functional units in the embodiments of the present invention may be integrated into one processing unit, or each unit may exist alone physically, or two or more units are integrated into one unit.
The functions, if implemented in the form of software functional units and sold or used as a stand-alone product, may be stored in a non-volatile computer-readable storage medium executable by a processor. Based on such understanding, the technical solution of the present invention may be embodied in the form of a software product, which is stored in a storage medium and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device) to execute all or part of the steps of the method according to the embodiments of the present invention. And the aforementioned storage medium includes: a U-disk, a removable hard disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a magnetic disk or an optical disk, and other various media capable of storing program codes.
Finally, it should be noted that: the above-mentioned embodiments are only specific embodiments of the present invention, which are used for illustrating the technical solutions of the present invention and not for limiting the same, and the protection scope of the present invention is not limited thereto, although the present invention is described in detail with reference to the foregoing embodiments, those skilled in the art should understand that: any person skilled in the art can modify or easily conceive the technical solutions described in the foregoing embodiments or equivalent substitutes for some technical features within the technical scope of the present disclosure; such modifications, changes or substitutions do not depart from the spirit and scope of the embodiments of the present invention, and they should be construed as being included therein. Therefore, the protection scope of the present invention shall be subject to the protection scope of the claims.