Media stream encryption method and device, storage medium and electronic equipment
Patent Information
- Application Number
- CN202111265825.2
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-10-28
- Publication Date
- 2025-11-04
- Estimated Expiration
- 2041-10-28
AI Technical Summary
[0008]在本发明实施例中,采用了获取多个待加密的目标媒体流;依次加密多个上述目标媒体流的第一帧媒体帧;在每依次加密多个上述目标媒体流的第I帧媒体帧之后,依次加密多个上述目标媒体流的第I+1帧媒体帧,其中,上述I为正整数的方法,由于在上述方法中,在对多个待加密的目标媒体流进行加密时,可以以媒体帧为单位进行加密,依次加密多个目标媒体流的第一帧媒体帧和后续的媒体帧,从而可以并行对多个目标媒体流进行加密,避免了加密单个媒体流时阻塞其他媒体流的问题,实现了提高媒体流加密效率的目的,进而解决了媒体流加密效率低的技术问题。
Smart Images

Figure CN116055078B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the field of computer, in particular, to a media stream encryption method, device, storage medium and electronic equipment. BACKGROUND
[0002] In the prior art, when encrypting media streams into audio and video streams, a streaming encryption method is adopted. When encrypting a media stream, other media streams need to wait. If the encrypted media stream file is too large, it will block the encryption of other media streams. SUMMARY
[0003] The embodiments of the present application provide a media stream encryption method, device, storage medium and electronic equipment to at least solve the technical problem of low media stream encryption efficiency.
[0004] According to an aspect of the embodiments of the present application, a media stream encryption method is provided, comprising: obtaining a plurality of target media streams to be encrypted; sequentially encrypting the first frame media frame of the plurality of target media streams; and after sequentially encrypting the Ith frame media frame of the plurality of target media streams, sequentially encrypting the (I+1)th frame media frame of the plurality of target media streams, wherein I is a positive integer.
[0005] According to another aspect of the embodiments of the present application, a media stream encryption device is provided, comprising: an obtaining unit configured to obtain a plurality of target media streams to be encrypted; a first encryption unit configured to sequentially encrypt the first frame media frame of the plurality of target media streams; and a second encryption unit configured to sequentially encrypt the (I+1)th frame media frame of the plurality of target media streams after sequentially encrypting the Ith frame media frame of the plurality of target media streams, wherein I is a positive integer.
[0006] According to still another aspect of the embodiments of the present application, a storage medium is provided, which stores a computer program. The computer program is configured to execute the above-mentioned media stream encryption method when running.
[0007] According to still another aspect of the embodiments of the present application, an electronic equipment is provided, which comprises a memory and a processor. The memory stores a computer program, and the processor is configured to execute the above-mentioned media stream encryption method through the computer program.
[0008] In the embodiment of the present application, the method comprises the following steps: obtaining a plurality of target media streams to be encrypted; sequentially encrypting the first frame media frame of the plurality of target media streams; and sequentially encrypting the I+1th frame media frame of the plurality of target media streams after sequentially encrypting the Ith frame media frame of the plurality of target media streams, wherein I is a positive integer. In the method, the first frame media frame and the subsequent media frames of the plurality of target media streams are sequentially encrypted in units of media frames when the plurality of target media streams to be encrypted are encrypted, so that the plurality of target media streams can be encrypted in parallel, the problem of blocking other media streams when a single media stream is encrypted is avoided, the purpose of improving the media stream encryption efficiency is achieved, and the technical problem of low media stream encryption efficiency is solved. BRIEF DESCRIPTION OF DRAWINGS
[0009] The accompanying drawings, which are included to provide a further understanding of the application and are incorporated in and constitute a part of this application, illustrate embodiments of the application and together with the description serve to explain the application. In the drawings:
[0010] Figure 1 is a flow chart of an optional media stream encryption method according to an embodiment of the present application;
[0011] Figure 2 is a schematic diagram of using a CPU to encrypt an optional media stream encryption method according to an embodiment of the present application;
[0012] Figure 3 is a plurality of media stream encryption schematic diagram of an optional media stream encryption method according to an embodiment of the present application;
[0013] Figure 4 is a media frame encryption schematic diagram of an optional media stream encryption method according to an embodiment of the present application;
[0014] Figure 5 is a media frame encryption schematic diagram of another optional media stream encryption method according to an embodiment of the present application;
[0015] Figure 6 is a media frame encryption schematic diagram of another optional media stream encryption method according to an embodiment of the present application;
[0016] Figure 7 is a media frame encryption schematic diagram of another optional media stream encryption method according to an embodiment of the present application;
[0017] Figure 8 is a system schematic diagram of an optional media stream encryption method according to an embodiment of the present application;
[0018] Figure 9is a structural schematic diagram of an optional media stream encryption device according to an embodiment of the present application;
[0019] Figure 10 is a schematic diagram of an electronic device according to an embodiment of the present application. DETAILED DESCRIPTION
[0020] In order to make the personnel in the art better understand the present application, the technical solutions in the embodiments of the present application will be described clearly and completely below in conjunction with the drawings in the embodiments of the present application. Obviously, the described embodiments are only a part of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative labor should belong to the scope of protection of the present application.
[0021] It should be noted that the terms "first", "second", and the like in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects, and do not necessarily indicate a specific order or a chronological sequence. It should be understood that the data thus used can be interchanged under appropriate circumstances, so that the embodiments of the present application described herein can be implemented in an order other than that illustrated or described herein. In addition, the terms "include" and "have" and any variations thereof are intended to cover non-exclusive inclusion, for example, a process, method, system, product or device that includes a series of steps or units does not necessarily have to be limited to those steps or units clearly listed, but can include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0022] According to a first aspect of an embodiment of the present application, a media stream encryption method is provided, which can be optional, as shown in Figure 1 The above method comprises:
[0023] S102, obtaining a plurality of target media streams to be encrypted;
[0024] S104, sequentially encrypting the first frame media frame of the plurality of target media streams;
[0025] S106, after sequentially encrypting the Ith frame media frame of the plurality of target media streams, sequentially encrypting the (I+1)th frame media frame of the plurality of target media streams, wherein I is a positive integer.
[0026] Optionally, in the present embodiment, the target media stream to be encrypted can be an audio stream, can be a video stream, or can be an audio-video stream including both audio and video. Each target media stream includes a plurality of frame media frames.
[0027] Optionally, in the embodiment, for one central processing unit (cpu), one or more processes can be included, and each process can process multiple media streams simultaneously. In the application, the multiple media streams processed by one process can be determined as the target media streams to be processed in the embodiment. For example, as shown in Figure 2 , Figure 2 , the embodiment includes cpu1-cpu3, wherein each cpu contains one process, and the process can trigger an epoll event. In the embodiment, process 1 can trigger a processing event, i.e., an epoll event, once for each read media frame, and encrypt the media frame. Media stream 1 and media stream 2 can be encrypted simultaneously, and the first frame of media stream 1 and media stream 2 is encrypted respectively, and then the second frame of media stream 1 and media stream 2 is processed, and so on until the last frame. The encrypted data of the media stream is written into the media file corresponding to the media stream.
[0028] Optionally, in the embodiment, for multiple target media streams, the first frame media frame of the multiple target media streams can be encrypted in sequence. For example, for three target media streams, the first frame media frame of the three target media streams is encrypted in sequence. After the first frame media frame is encrypted, the second frame media frame of the three target media streams is encrypted in sequence. For example, as shown in Figure 3 , Figure 3 , for target media stream 1 to target media stream 3, the first frame media frame of target media stream 1 is encrypted first, then the first frame media frame of target media stream 2 is encrypted, and then the first frame media frame of target media stream 3 is encrypted. Then, the second frame media frame of target media stream 1, the second frame media frame of target media stream 2, and the second frame media frame of target media stream 3 are encrypted. In this way, the encryption of target media stream 1-3 is completed or terminated.
[0029] Through the above method, the embodiment realizes parallel encryption of multiple media streams using one process of one cpu, and improves the efficiency of media stream encryption.
[0030] As an optional example, the encryption of the first frame media frame of the multiple target media streams in sequence includes:
[0031] The first frame media frame of each target media stream is taken as a current media frame, and the following operations are performed on the current media frame:
[0032] In the current media frame, the encrypted data reaching the target byte is written into the current media file corresponding to the target media stream where the current media frame is located;
[0033] In the current media frame, the remaining data not reaching the target byte is saved in the memory.
[0034] Optionally, in the embodiment, when the first frame media frame of the plurality of target media streams is encrypted, the plurality of target media streams can be sorted, and the first frame media frame of the plurality of target media streams is encrypted in sequence according to the order. When the encryption is performed, the encryption parameter used for the encryption can be initialized, and then the first frame media frame is encrypted using the encryption parameter.
[0035] Optionally, the target byte can be a preset value, which can be adjusted.
[0036] Taking 16 bytes as the target byte as an example, for the current media frame, every 16 bytes of data is encrypted using the encryption parameter and then written into the current media file corresponding to the current media frame. The remaining data that is less than 16 bytes in the current media frame is retained in the memory.
[0037] For example, as shown in FIG. 6, for the current media frame, the data of every target byte is written into the current media file, and the remaining data is saved in the memory. Figure 4
[0038] As an optional example, after the Ith frame media frame of the plurality of target media streams is encrypted in sequence, when the (I+1)th frame media frame of the plurality of target media streams is encrypted in sequence, the method further includes:
[0039] For any first media stream in the plurality of target media streams, when the first data of the Ith frame media frame of the first media stream is included in the memory, the second data is obtained from the (I+1)th frame media frame of the first media stream, wherein the sum of the bytes of the first data and the second data is equal to the target byte.
[0040] The first data and the second data are written into the current media file of the first media stream after being encrypted as combined data.
[0041] Optionally, in the embodiment, for any target media stream in the plurality of target media streams, the target media stream is regarded as the first media stream. When the (I+1)th frame media frame of the first media stream is encrypted, if the first data in the Ith frame media frame of the first media stream is included in the memory, the first data is the data that is less than the target byte and has not been written into the current media file of the first media stream. At this time, the second data can be obtained from the (I+1)th frame media frame, the second data and the first data are combined into data of the target byte length, and then the combined data of the target byte length is written into the current media file of the first media stream.
[0042] For example, as shown in FIG. 7, for the current media frame, the data of every target byte is written into the current media file, and the remaining data is saved in the memory. Figure 5 Figure 5 The current media frame 1 and 2 are media frames in the first media stream. The current media frame 2 is located after the current media frame 1. The remaining first data of the current media frame 1 and the second data of the current media frame 2 stored in the memory are combined as data of a target byte length and written into the current media file.
[0043] As an optional example, after the first data and the second data are written into the current media file of the first media stream as combined data after encryption, the method further comprises:
[0044] Every time data of a target byte is reached in the data of the (I+1)th media frame of the first media stream except the second data, the data is written into the current media file of the first media stream after encryption.
[0045] The remaining data that does not reach the target byte in the data of the (I+1)th media frame of the first media stream except the second data is saved in the memory.
[0046] Optionally, for the (I+1)th media frame of the first media stream, the data that reaches the target byte in the data except the second data is written into the current media file of the first media stream. The data that does not reach the target byte is left in the memory. As shown in Figure 6 The part of the data in the current media frame 2 and the part of the data in the current media frame 1 after encryption are combined as data of a target byte length and written into the current media file. The remaining data, the data that reaches the target byte, is written into the current media file, and the data that does not reach the target byte is saved in the memory.
[0047] As an optional example, when the remaining data that does not reach the target byte in the data of the (I+1)th media frame of the first media stream except the second data is saved in the memory, the method further comprises:
[0048] When the (I+1)th media frame of the first media stream is the last media frame of the first media stream or the media stream length of the current media file of the first media stream reaches a predetermined length, the data of the (I+1)th media frame of the first media stream saved in the memory is padded to a length of a target byte.
[0049] The padded data is written into the current media file after encryption.
[0050] Optionally, in the embodiment, when the remaining data of the (I+1)th media frame which is not written into the current media file is saved in the memory, if the (I+1)th media frame is the last media frame of the first media stream, the data saved in the memory is encrypted after being padded to the target byte length and then written into the current media file. Alternatively, when the remaining data of the (I+1)th media frame which is not written into the current media file is saved in the memory, if the media stream duration of the data in the current media file reaches a predetermined duration, which can be a preset time length, such as 5 seconds, the data saved in the memory is encrypted after being padded to the target byte length and then written into the current media file.
[0051] As an optional example, in the case where the duration of the current media file of the first media stream reaches a predetermined duration, after the padded data is written into the current media file, the method further includes:
[0052] In the encryption of the (I+2)th media frame of the first media stream, the data of the (I+2)th media frame reaching the target byte is encrypted and then written into a first media file different from the current media file of the first media stream.
[0053] The remaining data of the (I+2)th media frame not reaching the target byte is saved in the memory.
[0054] Optionally, each target media stream in the embodiment can correspond to one or more media files.
[0055] In the embodiment, if the current media file of the first media stream reaches a predetermined duration and the encrypted (I+1)th media frame of the first media stream is written into the current media file, for the (I+2)th media frame of the first media stream, when writing, it is written into a first media file of the first media stream different from the current media file. For example, as shown in Figure 7 the media stream duration in the current media file reaches a predetermined duration, such as 5 seconds, the remaining data of the current media frame 1 is written into the current media file after padding, and the current media frame 2 is written into the first media file. The current media file and the first media file are both media files of the first media stream.
[0056] As an optional example, the above method further includes:
[0057] Any process of any central processing unit is used to encrypt multiple target media streams.
[0058] Optionally, in the embodiment, when the media streams to be encrypted are obtained, all the media streams can be allocated to different processes of different cpus. Each process can use the above method of the embodiment to encrypt multiple target media streams in parallel.
[0059] In this embodiment, multi-process encryption can be used to maximize the use of CPU. Using the epoll model, the single-process load capacity is maximized. Each time a media frame is read, an epoll event is triggered, and a frame is encrypted using the symmetric encryption algorithm aes-128-cbc. The single-frame data volume is small, and the CPU is released after encryption to encrypt the next single-frame media frame of the media stream. Each media stream is encrypted one frame at a time. This embodiment ensures that the current stream encryption does not block the encryption of other streams. This embodiment allows the user to perceive that multiple media streams can be simultaneously sliced and encrypted.
[0060] Figure 8The system flowchart of the embodiment is shown in the figure. When the stream_begin field is received, it indicates that the encryption starts, and the subsequent fields are received and encrypted according to the subsequent fields. When the publish field is received, the initialization function is encapsulated, and all parameters of the aes-128-cbc encryption are initialized, including the encryption parameters key, iv, and padding. Then, the media stream AV data processing is performed. The open start slice of the media stream is written into the media file hls file header. Then, the media stream media frame flush input is encrypted and written into the media file. In this process, the data of each target byte length is encrypted and written into the media file, and the data less than the target byte length is saved in the memory. In the embodiment, the epoll mode can be used, and the slice logic is triggered frame by frame. If it is the first frame of the media stream, a new media file ts file of the media file ts is opened, the frame data is encrypted and written into the ts file, and the data less than 128 bits (16 bytes) is left in the memory for the next frame encryption. The encryption writing of the ts file is ended, and the cpu is released to other media stream processing media frame. If it is not the first frame, the frame data is encrypted and written into the ts file of the current media stream, and the data less than 128 bits (16 bytes) is left in the memory for the next frame encryption. The encryption writing of the ts file is ended, and the cpu is released to other media stream processing media frame. If the audio and video data in the ts file reaches the predetermined time length, such as 5 seconds, the last data less than 128 bits (16 bytes) is filled by the padding method PKCS7 padding, the 128 bits (16 bytes) length is met, and then the data is encrypted and written into the ts file, and the ts file is closed. When padding, the zero data is filled by the PKCS7 padding method, and the data less than 128 bits is filled to 128 bits. If the media stream is interrupted, the data less than 128 bits is filled to 128 bits by the PKCS7 padding method, and then the data is encrypted and written into the ts file, and the ts file is closed. If the close field is received, the remaining data of one frame is written into the media file after the remaining data is filled to the target byte length. If the stream_eof field is received, it indicates that the media stream is ended. At this time, the remaining data of the media stream media frame is filled to the target byte length, and then the data is encrypted and written into the media file. If the media stream is ended, but the stream_eof field is not received, the close_stream field is triggered automatically, and the media stream is closed. The remaining data of the media stream media frame is filled to the target byte length and written into the media file.
[0061] It should be noted that, for the foregoing method embodiments, for the sake of simple description, they are all described as a combination of a series of actions, but those skilled in the art should know that the present application is not limited to the action sequence described, because according to the present application, certain steps can be performed in other sequences or simultaneously. Secondly, those skilled in the art should know that the embodiments described in the specification are all preferred embodiments, and the actions and modules involved are not necessarily necessary for the present application.
[0062] According to another aspect of the embodiments of the present application, a media stream encryption device is also provided, as shown in the figure, comprising: Figure 9
[0063] The acquisition unit 902 is configured to acquire a plurality of target media streams to be encrypted.
[0064] The first encryption unit 904 is configured to sequentially encrypt the first frame media frame of the plurality of target media streams.
[0065] The second encryption unit 906 is configured to sequentially encrypt the (I+1)th frame media frame of the plurality of target media streams after sequentially encrypting the Ith frame media frame of the plurality of target media streams, where I is a positive integer.
[0066] Optionally, in the present embodiment, the target media stream to be encrypted can be an audio stream, a video stream, or an audio-video stream including both audio and video. Each target media stream includes a plurality of media frames.
[0067] Optionally, in the present embodiment, for a central processing unit (CPU), one or more processes can be included, and each process can process a plurality of media streams simultaneously. In the present application, the plurality of media streams processed by one process can be determined as the plurality of target media streams to be processed in the present embodiment. For example, as shown in the figure, a plurality of processes can be included in a CPU, where each process can trigger an epoll event. Figure 2 Figure 2 In the present embodiment, process 1 can trigger a processing event, i.e., an epoll event, once for each media frame read, to encrypt the media frame. Media stream 1 and media stream 2 can be encrypted simultaneously, and the first frame of media stream 1 and media stream 2 is encrypted respectively, and then the second frame of media stream 1 and media stream 2 is processed, and so on until the last frame. The encrypted data of the media stream is written into the media file corresponding to the media stream.
[0068] Optionally, in this embodiment, for the plurality of target media streams, the first frame media frame of the plurality of target media streams can be encrypted in sequence. For example, for three target media streams, the first frame media frame of the three target media streams is encrypted in sequence. After the first frame media frame is encrypted, the second frame media frame of the three target media streams is encrypted in sequence. For example, as shown in Figure 3 Figure 3 For target media stream 1 to target media stream 3, the first frame media frame of target media stream 1 is encrypted first, then the first frame media frame of target media stream 2 is encrypted, and then the first frame media frame of target media stream 3 is encrypted. Then, the second frame media frame of target media stream 1, the second frame media frame of target media stream 2, and the second frame media frame of target media stream 3 are encrypted. In this way, until the encryption of target media stream 1-3 is completed or terminated.
[0069] Through this embodiment, by the above method, parallel encryption of multiple media streams using one process of one cpu is realized, and the efficiency of media stream encryption is improved.
[0070] Other examples of this embodiment are described in the above examples, which will not be repeated here.
[0071] Figure 10 is a structural block diagram of an optional electronic device according to an embodiment of the present application, as shown in Figure 10 includes a processor 1002, a communication interface 1004, a memory 1006, and a communication bus 1008, wherein the processor 1002, the communication interface 1004, and the memory 1006 complete communication with each other through the communication bus 1008, wherein,
[0072] The memory 1006 is used to store a computer program;
[0073] The processor 1002 is used to execute the computer program stored in the memory 1006, and the following steps are implemented:
[0074] Obtain a plurality of target media streams to be encrypted;
[0075] Encrypt the first frame media frame of the plurality of target media streams in sequence;
[0076] After each I frame media frame of the plurality of target media streams is encrypted in sequence, the I+1 frame media frame of the plurality of target media streams is encrypted in sequence, wherein I is a positive integer.
[0077] Optionally, in this embodiment, the communication bus can be a PCI (Peripheral Component Interconnect) bus or an EISA (Extended Industry Standard Architecture) bus, etc. This communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 10 The symbol is represented by a single thick line, but this does not indicate that there is only one bus or one type of bus. The communication interface is used for communication between the aforementioned electronic devices and other devices.
[0078] The memory may include RAM, or non-volatile memory, such as at least one disk storage device. Optionally, the memory may also be at least one storage device located remotely from the aforementioned processor.
[0079] As an example, the memory 1006 described above may include, but is not limited to, the acquisition unit 902, the first encryption unit 904, and the second encryption unit 906 in the aforementioned processing device. Furthermore, it may include, but is not limited to, other module units in the aforementioned processing device, which will not be elaborated upon in this example.
[0080] The processors mentioned above can be general-purpose processors, including but not limited to: CPU (central processing unit), NP (network processor), etc.; they can also be DSP (Digital Signal Processor), ASIC (Application Specific Integrated Circuit), FPGA (Field-Programmable Gate Array) or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components.
[0081] Optionally, specific examples in this embodiment can refer to the examples described in the above embodiments, and will not be repeated here.
[0082] Those skilled in the art will understand that Figure 10 The structure shown is for illustrative purposes only. The device that implements the above request processing method can be a terminal device, such as a smartphone (e.g., Android phone, iOS phone), tablet computer, PDA, mobile Internet Device (MID), PAD, etc.Figure 10 It does not cause limitation to the structure of the electronic device. For example, the electronic device can further include more or less components (such as a network interface, a display device, etc.) than those shown in the figures, or have a different configuration from that shown in the figures. Figure 10 Figure 10 The electronic device can further include more or less components (such as a network interface, a display device, etc.) than those shown in the figures, or have a different configuration from that shown in the figures.
[0083] A person of ordinary skill in the art can understand that all or part of the steps of various methods in the above embodiments can be completed by a program instructing the hardware related to the terminal device, and the program can be stored in a computer readable storage medium, which can include a flash disk, a ROM, a RAM, a magnetic disk, or an optical disk, etc.
[0084] According to another aspect of the embodiments of the present application, a computer readable storage medium is also provided, which stores a computer program. When the computer program is executed, the steps of the above media stream encryption method are performed.
[0085] Optionally, in the present embodiment, a person of ordinary skill in the art can understand that all or part of the steps of various methods in the above embodiments can be completed by a program instructing the hardware related to the terminal device, and the program can be stored in a computer readable storage medium, which can include a flash disk, a ROM, a RAM, a magnetic disk, or an optical disk, etc.
[0086] The serial numbers of the above embodiments of the present application are only for description, and do not represent the advantages or disadvantages of the embodiments.
[0087] The integrated units in the above embodiments, if realized in the form of software function units and sold or used as independent products, can be stored in the above computer readable storage medium. Based on such understanding, the technical solutions of the present application or all or part of the solutions that essentially contribute to the prior art can be embodied in the form of a software product, which is stored in a storage medium, includes a number of instructions for making one or more computer devices (which can be personal computers, servers or network devices, etc.) execute all or part of the steps of the methods described in the embodiments of the present application.
[0088] In the above embodiments of the present application, the description of each embodiment has its own focus, and the parts not described in detail in a certain embodiment can be referred to the relevant description of other embodiments.
[0089] In several embodiments provided in the present application, it should be understood that the disclosed client can be implemented in other manners. Of course, the described apparatus embodiments are merely schematic, and the division of units is merely logical function division, and there can be other division manners in actual implementation. For example, a plurality of units or components can be combined or integrated into another system, or some features can be ignored or not executed. In addition, the displayed or discussed mutual couplings or direct couplings or communication connections can be indirect couplings or communication connections through some interfaces, units or modules, and can be in electrical, mechanical or other forms.
[0090] The units described as separated components can or can not be physically separated, and the components displayed as units can or can not be physical units, i.e., can be located in one place or can be distributed on a plurality of network units. Some or all of the units can be selected according to actual needs to achieve the purposes of the embodiments of the present application.
[0091] In addition, each functional unit in the various embodiments of the present application can be integrated in a processing unit, or each unit can exist physically as a separate unit, or two or more units can be integrated in one unit. The integrated unit can be implemented in the form of hardware, or in the form of a software functional unit.
[0092] The above descriptions are merely preferred embodiments of the present application, and it should be pointed out that, for those skilled in the art, some improvements and refinements can be made without departing from the principles of the present application, and these improvements and refinements should also be considered as the protection scope of the present application.
Claims
1. A media stream encryption method, characterized by, The method comprises: obtaining, by a process, a plurality of target media streams to be encrypted, and sorting the plurality of target media streams to be encrypted; encrypting, by the process, first frame media frames of the plurality of target media streams in sequence according to the sorting order; after each Ith frame media frame of the plurality of target media streams is encrypted in sequence, encrypting, by the process, (I+1)th frame media frame of the plurality of target media streams in sequence according to the sorting order of the plurality of target media streams, wherein I is a positive integer, until all media frames of the plurality of target media streams are encrypted.
2. The method of claim 1, wherein, encrypting the first frame media frames of the plurality of target media streams in sequence comprises: taking the first frame media frame of each target media stream as a current media frame, and performing the following operations on the current media frame: writing, after encryption, data in the current media frame that reaches a target byte to a current media file corresponding to the target media stream where the current media frame is located; saving, in a memory, remaining data in the current media frame that does not reach the target byte.
3. The method of claim 2, wherein, After each Ith frame media frame of the plurality of target media streams is encrypted in sequence, when the (I+1)th frame media frame of the plurality of target media streams is encrypted in sequence, the method further comprises: for any first media stream in the plurality of target media streams, in the case that the memory includes first data of the Ith frame media frame of the first media stream, obtaining second data from the (I+1)th frame media frame of the first media stream, wherein the sum of the bytes of the first data and the second data is equal to the target byte; writing, after encryption, the first data and the second data as combined data to the current media file of the first media stream.
4. The method of claim 3, wherein, After the first data and the second data are written, after encryption, to the current media file of the first media stream as combined data, the method further comprises: writing, after encryption, data in the (I+1)th frame media frame of the first media stream that reaches a target byte to the current media file of the first media stream, except for the second data; saving, in the memory, remaining data in the (I+1)th frame media frame of the first media stream that does not reach the target byte, except for the second data.
5. The method of claim 4, wherein, When the remaining data in the (I+1)th frame media frame of the first media stream that does not reach the target byte is saved in the memory, except for the second data, the method further comprises: in the case that the (I+1)th frame media frame of the first media stream is the last frame media frame of the first media stream, or the media stream length of the current media file of the first media stream reaches a predetermined length, padding the data of the (I+1)th frame media frame of the first media stream saved in the memory to the length of the target byte; writing, after encryption, the padded data to the current media file.
6. The method of claim 5, wherein, In the case that the length of the current media file of the first media stream reaches a predetermined length, after the padded data is written to the current media file, the method further comprises: In the process of encrypting the I+2th media frame of the first media stream, data reaching the target byte in the I+2th media frame is written into a first media file different from the current media file of the first media stream after encryption; Data not reaching the target byte in the I+2th media frame is saved in the memory.
7. A media stream encryption apparatus, characterized by, The method comprises the steps of: An acquisition unit is configured to acquire, by a process, a plurality of target media streams to be encrypted, and sort the plurality of target media streams to be encrypted; A first encryption unit is configured to encrypt, by the process, a first media frame of each of the plurality of target media streams in sequence according to the sorting order; A second encryption unit is configured to encrypt, by the process, an I+1th media frame of each of the plurality of target media streams in sequence according to the sorting order after the Ith media frame of each of the plurality of target media streams is encrypted in sequence, wherein I is a positive integer, and the encryption is performed until all media frames of the plurality of target media streams are encrypted.
8. The apparatus of claim 7, wherein, The first encryption unit comprises: A processing module is configured to take the first media frame of each of the plurality of target media streams as a current media frame, and perform the following operations on the current media frame: Data reaching a target byte in the current media frame is written into a current media file corresponding to the target media stream where the current media frame is located after encryption; Data not reaching the target byte in the current media frame is saved in the memory.
9. The apparatus of claim 8, wherein, The second encryption unit comprises: An acquisition module is configured to, after the Ith media frame of each of the plurality of target media streams is encrypted in sequence, acquire, when the I+1th media frame of each of the plurality of target media streams is encrypted in sequence, second data from the I+1th media frame of any first media stream of the plurality of target media streams, in the case that the first media stream includes first data of the Ith media frame of the first media stream in the memory, wherein the sum of the bytes of the first data and the second data is equal to the target byte; A first writing module is configured to write the first data and the second data as combined data into the current media file of the first media stream after encryption.
10. The apparatus of claim 9, wherein, The second encryption unit further comprises: A second writing module is configured to, after the first data and the second data are written into the current media file of the first media stream as combined data after encryption, write data reaching a target byte in the I+1th media frame of the first media stream, except the second data, into the current media file of the first media stream after encryption; A first saving module is configured to save data not reaching the target byte in the I+1th media frame of the first media stream, except the second data, in the memory.
11. The apparatus of claim 10, wherein, When data not reaching the target byte in the I+1th media frame of the first media stream, except the second data, is saved in the memory, the second encryption unit further comprises: The patching module is configured to, in a case where the (I+1)th media frame of the first media stream is the last media frame of the first media stream or a media stream time length of the current media file of the first media stream reaches a predetermined time length, patch data of the (I+1)th media frame of the first media stream saved in the memory to the length of the target byte; The third writing module is configured to write the patched data after encryption into the current media file.
12. The apparatus of claim 11, wherein, The second encryption unit further includes: The fourth writing module is configured to, in a case where a time length of the current media file of the first media stream reaches a predetermined time length, after writing the patched data into the current media file, write, when encrypting the (I+2)th media frame of the first media stream, data of the (I+2)th media frame that reaches the target byte each time after encryption into a first media file different from the current media file of the first media stream; The second saving module is configured to save data of the (I+2)th media frame that does not reach the target byte in the memory.
13. A computer-readable storage medium storing a computer program, the computer-readable storage medium being characterized by, The computer program is configured to execute the method in any one of claims 1 to 6 when running.
14. An electronic device comprising a memory and a processor, characterized in that The memory stores a computer program, and the processor is configured to execute the method in any one of claims 1 to 6 by using the computer program.
Citation Information
Patent Citations
Video stream processing method and device, server, electronic device and storage medium
CN111083425A