Method, device, electronic equipment and storage medium for playing multimedia file
By working collaboratively at the ffmpeg layer and application layer, and using self-developed protocols and encryption/decryption algorithms, real-time decryption and playback of encrypted multimedia files were achieved, solving playback stuttering and latency issues and ensuring data security.
Patent Information
- Application Number
- CN202210225136.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-03-09
- Publication Date
- 2025-11-21
- Estimated Expiration
- 2042-03-09
AI Technical Summary
Existing technologies suffer from stuttering and latency issues when playing encrypted audio and video, especially during seek operations where the inability to pre-decrypt causes unavoidable latency, and decrypted files are easily leaked.
By calling a specified protocol at the ffmpeg layer to stream encrypted multimedia files, the application layer decrypts the data, and the player engine layer and ffmpeg layer are seamlessly connected to achieve real-time decryption and playback of the data stream. The system uses a self-developed protocol CCSecretProtocol and encryption/decryption algorithms such as HMAC and SHA1 to decrypt the data stream and then decapsulate and decode it.
It enables real-time decryption and playback of encrypted multimedia files, solving playback stuttering and latency issues, ensuring data security, and preventing file leaks.
Smart Images

Figure CN114791960B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of audio and video, and in particular to a method, apparatus, electronic device, and storage medium for playing multimedia files. Background Technology
[0002] For security and to prevent leakage, stored audio and video are encrypted, such as videos stored on a mobile phone. Currently, the method for playing encrypted audio and video involves dividing a segment into multiple sub-audio and video blocks based on keyframes, encrypting each sub-block using an encryption module, uploading the encrypted audio and video file and a text document containing the private key to a storage server, and decrypting each encrypted sub-block before playback.
[0003] While the above methods can avoid the huge latency and overhead caused by encrypting and decrypting the entire audio and video to some extent, the overhead of decrypting audio and video blocks will still cause some stuttering and latency, resulting in encrypted multimedia files not being able to be decrypted and played in real time. Summary of the Invention
[0004] In view of this, the purpose of the present invention is to provide a method, apparatus, electronic device and storage medium for playing multimedia files. By having the encrypted data corresponding to the target encrypted multimedia file flow in the form of a data stream between the application layer, the player engine layer and the ffmpeg layer, a seamless connection between data reading, data decryption and data playback is achieved. This solves the problems of ffmpeg being unable to read encrypted files and the playback stuttering and delay caused by pre-decryption, and enables real-time decryption and playback of encrypted multimedia files.
[0005] In a first aspect, embodiments of the present invention provide a method for playing a multimedia file, the method comprising:
[0006] By calling a specified protocol through the ffmpeg layer, the target encrypted multimedia file is streamed and read in a streaming manner through the specified protocol to obtain an encrypted data stream;
[0007] The encrypted data stream is decrypted at the application layer to obtain the decrypted data stream;
[0008] The decrypted data stream is played through the player engine layer and the ffmpeg layer.
[0009] Before the above-mentioned step of calling a specified protocol through the ffmpeg layer to stream the target encrypted multimedia file and obtain the encrypted data stream, the method further includes:
[0010] The application layer obtains the specified protocol name and storage address of the target encrypted multimedia file, and concatenates the specified protocol name with the storage address to obtain the address information of the target encrypted multimedia file. The specified protocol name is used by the ffmpeg layer to call the specified protocol to stream the target encrypted multimedia file based on the storage address.
[0011] The address information of the target encrypted multimedia file is passed into the ffmpeg layer by calling the preset ffmpeg layer interface through the player engine layer.
[0012] The above steps, which involve calling a specified protocol through the ffmpeg layer to stream the target encrypted multimedia file and obtain an encrypted data stream, include:
[0013] The address information of the target encrypted multimedia file is obtained through the ffmpeg layer, and the address information is parsed to obtain the specified protocol name and storage address;
[0014] Locate the specified protocol based on the specified protocol name;
[0015] The target encrypted multimedia file is read into memory in a streaming manner from the stored disk based on the specified storage address using the specified protocol, thus obtaining an encrypted data stream.
[0016] The steps described above, which involve reading the target encrypted multimedia file from the stored disk in a streaming manner into memory based on the specified protocol and the storage address to obtain an encrypted data stream, include:
[0017] The specified protocol is invoked to obtain the protocol context based on the specified protocol name, and the file size in the disk to be read in a single operation is set based on the protocol context;
[0018] Obtain the seek value, and based on the storage address, set the file offset position of the target encrypted multimedia file to the position corresponding to the seek value to obtain the file read position;
[0019] A preset read function is invoked to read the target encrypted multimedia file into memory in a stream manner, based on the file read position and the file size, thereby obtaining an encrypted data stream.
[0020] The above steps of decrypting the encrypted data stream through the application layer to obtain the decrypted data stream include:
[0021] The encrypted data stream is fed into a preset player engine layer, and then fed into the application layer through the player engine layer.
[0022] The encrypted data stream is decrypted by replacing the original file header data through the application layer.
[0023] The above-described steps involve replacing the original file header data of the encrypted data stream at the application layer to obtain the decrypted data stream, including:
[0024] The application layer obtains the offset of the encrypted data stream and the length of the read data based on a preset callback function.
[0025] Based on the offset and the length of the read data, determine whether the encrypted data stream corresponds to the original multimedia file header file;
[0026] If the encrypted data stream corresponds to the header file of the original multimedia file, then the target data in the encrypted data stream is obtained;
[0027] The target data is replaced with the header data of the original multimedia file to obtain the decrypted data stream.
[0028] Before the above-mentioned step of calling a specified protocol through the ffmpeg layer to stream the target encrypted multimedia file and obtain the encrypted data stream, the method further includes:
[0029] The multimedia files to be encrypted are classified to obtain first data and second data. The first data is used to indicate the data before a preset byte position in the multimedia files to be encrypted, and the second data is used to indicate the data after the preset byte position in the multimedia files to be encrypted.
[0030] The first data is encrypted using a preset stream encryption algorithm, and the second data is subjected to a single-table permutation to obtain an encrypted multimedia file.
[0031] The above steps of decrypting the encrypted data stream through the application layer to obtain the decrypted data stream include:
[0032] By calling the preset password initialization and decryption module at the application layer, the first data in the encrypted data stream is decrypted based on the stream encryption algorithm, and the inverse mapping table is obtained. Based on the inverse mapping table, the second data in the encrypted data stream is decrypted to obtain the decrypted data stream.
[0033] Secondly, embodiments of the present invention provide a multimedia file playback device, the multimedia file playback device comprising:
[0034] The reading module is used to call a specified protocol through the ffmpeg layer to stream the target encrypted multimedia file through the specified protocol and obtain an encrypted data stream;
[0035] The decryption module is used to decrypt the encrypted data stream through the application layer to obtain a decrypted data stream;
[0036] The playback module is used to process the decrypted data stream through the player engine layer and the ffmpeg layer.
[0037] Thirdly, embodiments of the present invention provide an electronic device, including a processor and a memory, wherein the memory stores machine-executable instructions that can be executed by the processor, and the processor executes the machine-executable instructions to implement the above-mentioned method for playing multimedia files.
[0038] Fourthly, embodiments of the present invention provide a machine-readable storage medium storing machine-executable instructions. When the machine-executable instructions are invoked and executed by a processor, the machine-executable instructions cause the processor to implement the aforementioned method for playing multimedia files.
[0039] The embodiments of the present invention bring the following beneficial effects:
[0040] The aforementioned multimedia file playback method, device, electronic device, and storage medium invoke a specified protocol through the ffmpeg layer to stream the target encrypted multimedia file, obtaining an encrypted data stream. The application layer then decrypts the encrypted data stream, obtaining a decrypted data stream. Finally, the player engine layer and the ffmpeg layer process the decrypted data stream for playback. In this method, the encrypted data corresponding to the target encrypted multimedia file flows as a data stream between the application layer, player engine layer, and ffmpeg layer, achieving seamless integration of data reading, data decryption, and data playback. This solves the problems of ffmpeg's inability to read encrypted files and playback stuttering and latency caused by pre-decryption, enabling real-time decryption and playback of encrypted multimedia files.
[0041] Other features and advantages of the invention will be set forth in the description which follows, and will be apparent in part from the description, or may be learned by practicing the invention. The objects and other advantages of the invention are realized and obtained in accordance with the structures particularly pointed out in the description, claims and drawings.
[0042] To make the above-mentioned objects, features and advantages of the present invention more apparent and understandable, preferred embodiments are described below in detail with reference to the accompanying drawings. Attached Figure Description
[0043] To more clearly illustrate the specific embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the specific embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are some embodiments of the present invention. For those skilled in the art, other drawings can be obtained from these drawings without creative effort.
[0044] Figure 1 A schematic diagram illustrating an embodiment of the logical relationship between the application layer, the player engine layer, and the ffmpeg layer provided in this invention.
[0045] Figure 2 A schematic diagram of an embodiment of the multimedia file playback method provided in this invention;
[0046] Figure 3 A schematic diagram of the flow steps of a multimedia file playback method provided in this invention;
[0047] Figure 4 A schematic diagram of another embodiment of the process steps of the multimedia file playback method provided in this invention;
[0048] Figure 5 A schematic diagram of another embodiment of the multimedia file playback method provided in this invention;
[0049] Figure 6 A schematic diagram of an embodiment of the built-in default encryption algorithm provided in this invention;
[0050] Figure 7 This is a schematic diagram of an embodiment of the process for replacing the original file header data of an encrypted data stream, provided by an embodiment of the present invention;
[0051] Figure 8 A schematic diagram of a multimedia file playback device provided in an embodiment of the present invention;
[0052] Figure 9 This is a schematic diagram of an electronic device provided in an embodiment of the present invention. Detailed Implementation
[0053] To make the objectives, 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. Obviously, the described embodiments are only some embodiments of the present invention, not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.
[0054] Mobile devices (such as smartphones) or other terminals may store multimedia files that they do not want others to access. To prevent the negative impact of such multimedia leaks, these files are encrypted. Currently, the method for playing encrypted audio and video is to divide a segment of audio and video into multiple sub-audio and video blocks based on keyframes, encrypt each sub-audio and video block using an encryption module, upload the encrypted audio and video files and a text document containing the private key to a storage server, and decrypt each encrypted sub-audio and video block before playback.
[0055] This method also utilizes ffmpeg, one of the most widely used open-source libraries in the multimedia field. However, ffmpeg itself does not support video encryption and decryption. Although the above method can avoid the huge latency and overhead caused by encrypting and decrypting the entire audio and video to a certain extent, the audio and video decryption overhead will still cause some stuttering and latency, resulting in encrypted multimedia files not being able to be decrypted and played in real time. This shortcoming can be avoided by pre-decryption when playing sequentially, but there is no feasible solution for seeking operations because the sub-multimedia files to be decrypted cannot be known in advance. In addition, after decrypting the sub-multimedia files, the above method needs to temporarily save the decrypted sub-multimedia files on the disk and read them directly during playback. At this time, the sub-multimedia files that are not in an encrypted state can also be easily obtained by others, resulting in content leakage.
[0056] Based on the above, embodiments of the present invention provide a method, apparatus, electronic device, and storage medium for playing multimedia files.
[0057] In one possible implementation, this embodiment of the invention provides a method for playing multimedia files, wherein the terminal device may be the aforementioned local terminal device.
[0058] This invention provides an architecture for real-time decryption and playback of encrypted multimedia files. After the player engine is integrated with the application, its multimedia file playback function can be divided into three layers: the application layer, the player engine layer, and the ffmpeg layer. The application is divided into these three layers from top to bottom. The player engine layer is responsible for playback logic control such as multimedia file playback, rendering, and seek. The application layer obtains the multimedia file playback function by calling the player engine. The ffmpeg layer is responsible for specific operations such as protocol decryption, decapsulation, and decoding. Protocol decryption instructs the parsing of streaming media protocol data into corresponding encapsulation format data. Decapsulation instructs the separation of input encapsulation format data into compressed multimedia file data (e.g., compressed audio stream data or compressed video stream data). Decoding instructs the decoding of compressed multimedia file data into uncompressed raw multimedia file data (e.g., raw video data or raw audio data). Seek instructs jumping to a specific point in time within the multimedia file for playback. Specifically, the logical relationship between the application, the player engine, and the multimedia file processing library is as follows: Figure 1 As shown.
[0059] The above architecture enables real-time decryption and playback of encrypted multimedia files, eliminating the need to pre-decrypt the encrypted multimedia files before playback. When performing seek and related operations, playback can be achieved simply by decrypting the data of the encrypted multimedia file read after seek (e.g., encrypted video stream), thus avoiding video playback delays caused by pre-decryption.
[0060] See Figure 2 The diagram illustrates an embodiment of a method for playing a multimedia file, which includes the following steps:
[0061] Step S201: The specified protocol is called through the ffmpeg layer to stream the target encrypted multimedia file and obtain the encrypted data stream.
[0062] The aforementioned ffmpeg layer is used for encapsulation, format parsing, decapsulation, and decoding of encrypted data in multimedia files. ffmpeg can be used in two ways: one is to install it on a computer as an application and call it using command-line calls; the other is to integrate it from source code and call it via C language functions. In this embodiment of the invention, ffmpeg is integrated into the player engine as a static or dynamic library, which can be understood as source code integration, making it part of the player engine.
[0063] The specified protocol mentioned above refers to the URLProtocol structure type used for decryption in the ffmpeg layer. This is not a limitation, but rather an example, not a restriction. The specified protocol implemented in this invention can be a self-developed protocol, CCSecretProtocol, added to the existing URLProtocol protocol system of ffmpeg for real-time decryption and playback. When playing the target encrypted file of a target multimedia file, it can perform random reading (occurring during seek operations) and real-time decryption and playback. The following explanation will use CCSecretProtocol. The specified protocol is a protocol within the ffmpeg layer, a part of ffmpeg; that is, a self-developed protocol is added to the protocol array of ffmpeg. ffmpeg can locate the specified protocol by traversing the protocol array by the protocol name preceding the file path.
[0064] The aforementioned target encrypted multimedia file is the selected or retrieved encrypted multimedia file to be played, such as an encrypted mp4 file. For ease of understanding, this embodiment of the invention uses a video as an example of the target encrypted multimedia file for illustration.
[0065] By calling a specified protocol through the ffmpeg layer, the encrypted files of the target multimedia file are read in a streaming manner according to the specified protocol, and the encrypted data stream is obtained.
[0066] By calling a specified protocol through the ffmpeg layer, the target multimedia file can be streamed and encrypted, thus solving the problem that the existing ffmpeg layer cannot read encrypted multimedia files and enabling the ffmpeg layer to randomly read encrypted multimedia files.
[0067] Step S202: Decrypt the encrypted data stream through the application layer to obtain the decrypted data stream.
[0068] The application layer mentioned above is the application accessed by the player engine layer. The application can be any cloud application that can run under the cloud interaction system.
[0069] The application layer calls a pre-defined encryption / decryption algorithm from the player engine layer via a pre-defined interface to decrypt the encrypted data stream, thus obtaining the decrypted data stream. The type of encryption / decryption algorithm can be digital signature, information encryption, etc., which is not limited here. To improve encryption accuracy, a higher encryption accuracy algorithm is preferred. The encryption / decryption algorithm used can be a single algorithm or a combination of multiple algorithms. For example, a single algorithm can be a Hash-based Message Authentication Code (HMAC) algorithm, while multiple algorithms can be combined to use both the Hash-based Message Authentication Code (HMAC) algorithm and the Secure Hash Algorithm (SHA1) algorithm. HMAC encryption / decryption is performed first, followed by SHA1 encryption / decryption.
[0070] Step S203: The decrypted data stream is played through the player engine layer and the ffmpeg layer.
[0071] The player engine in the aforementioned player engine layer can be a software development kit that provides functionality to the application in the form of a static library or a dynamic library. This is not a limitation. As an example rather than a limitation, the player engine implemented in this invention is an SDK, and the following explanation will use the player engine as an SDK.
[0072] The ffmpeg layer decrypts and decodes the data stream to obtain the data to be played. Specifically, the ffmpeg layer parses the decrypted data stream into the corresponding encapsulation format data to decapsulate it, resulting in a decapsulated data stream. This decapsulated data stream is then decoded to obtain the data to be played, which is then sent to the player engine. The player engine renders the data and displays it on a screen or other display device. In detail, the ffmpeg layer separates the decrypted data stream into corresponding multimedia compressed encoded data, i.e., it decapsulates the decrypted data stream. The decapsulated data stream is actually an encapsulated data stream (e.g., mp4, flv, etc.). This encapsulated data stream can be an encapsulated audio stream, an encapsulated video stream, or more often, a mixture of audio and video data. For example, if the decapsulated data stream is mixed audio and video encoded data, the decoded multimedia compressed encoded data is separated into audio and video streams. The ffmpeg layer then decodes this multimedia compressed encoded data back into uncompressed raw data, thus obtaining the data to be played.
[0073] By decrypting at the application layer and playing through the player engine layer, the encryption / decryption algorithm calls and player logic are separated. This allows applications to change encryption algorithms as needed without modifying the player engine. As a provider of basic components, the player engine (Software Development Kit, SDK) is typically integrated into dozens or even hundreds of applications. The modifiable encryption / decryption algorithm not only facilitates software integration and allows for the free definition of encryption / decryption algorithms but also reduces the maintenance cost of the SDK itself.
[0074] The aforementioned method for playing multimedia files involves calling a specified protocol through the ffmpeg layer to stream the target encrypted multimedia file, obtaining an encrypted data stream. The application layer then decrypts the encrypted data stream, yielding a decrypted data stream. Finally, the player and ffmpeg layers process the decrypted data stream for playback. This method achieves seamless integration of data reading, decryption, and playback by having the encrypted data corresponding to the target encrypted multimedia file flow as a data stream between the application, player engine, and ffmpeg layers. This resolves the issues of ffmpeg's inability to read encrypted files and playback stuttering and latency caused by pre-decryption, enabling real-time decryption and playback of encrypted multimedia files.
[0075] This invention provides a multimedia file playback method that involves several steps, including protocol decryption, decapsulation, decoding, and rendering. The main focus is on the protocol decryption step. Taking encrypted video data streams as an example, (after calling a specified protocol through the ffmpeg layer to stream the data of the target encrypted multimedia file, i.e., the encrypted video file data), the encrypted video file data is decrypted to obtain the encrypted video data stream. (Through the application layer) the encrypted video data stream is decrypted to obtain encapsulated data (i.e., the decrypted data stream). (Through the ffmpeg layer) the encapsulated data is decapsulated to obtain encoded data. (Through the ffmpeg layer) the encoded data is decoded to obtain image data. (Through the player engine) the image data is rendered, and (through the screen) the video is played. Figure 3 As shown.
[0076] Specifically, the multimedia file playback method in the embodiments of the invention provides an architecture for real-time decryption and playback of encrypted multimedia files. After the player engine is connected to the application, its multimedia file playback function can be implemented through three layers: the application layer, the player engine SDK layer, and the ffmpeg layer. The processing flow of the multimedia file playback method corresponding to the application layer, the player engine SDK layer, and the ffmpeg layer is as follows: Figure 4As shown below, the processing flow of multimedia file playback methods corresponding to the application layer, player engine SDK layer, and ffmpeg layer is explained in detail.
[0077] See Figure 5 The diagram illustrates another embodiment of a method for playing a multimedia file, which includes the following steps:
[0078] Step S501: Obtain the specified protocol name and storage address of the target encrypted multimedia file through the application layer, and concatenate the specified protocol name and storage address to obtain the address information of the target encrypted multimedia file. The specified protocol name is used by the ffmpeg layer to call the specified protocol to stream the target encrypted multimedia file based on the storage address.
[0079] In the multimedia field, different types of encrypted multimedia files (e.g., encrypted video files) correspond to different streaming protocols. The corresponding streaming protocol can be identified by the protocol name preceding the disk address (i.e., the save address, e.g., the disk address of the encrypted video, / D / media / test.mp4). For example, if the video address (i.e., the save address) starts with http: / / , it indicates that the address is an HTTP video stream, and ffmpeg will read the video stream via the HTTP protocol; if the video address (i.e., the save address) starts with File: / / , it indicates that the address is a local video file, and ffmpeg will read the video stream via the file protocol. Since ffmpeg cannot read encrypted multimedia files using the CCSecretProtocol, it is necessary to add the protocol name CCMediaDataSource before the multimedia file address (e.g., the disk address of the encrypted video), i.e., specify the protocol name. The specified protocol name is then concatenated with the save address to obtain the address information of the target encrypted multimedia file, for example, CCMediaDataSource: / D / media / test.mp4.
[0080] In one implementation, before step 501, the multimedia file to be encrypted is classified to obtain first data and second data. The first data is used to indicate the data before a preset byte position in the multimedia file to be encrypted, and the second data is used to indicate the data after the preset byte position in the multimedia file to be encrypted. The first data is encrypted based on a preset stream encryption algorithm, and the second data is subjected to single-label permutation to obtain the encrypted multimedia file.
[0081] The data at the preset byte position consists of all data preceding the preset byte position; for example, the data preceding the preset byte position is the first 32kb of data. The multimedia file to be encrypted is categorized into first data and second data to distinguish between the header data and the data outside the header data. The first data, which is the data preceding the preset byte position in the multimedia file to be encrypted, is intended to include the header data; that is, the first data contains the header data.
[0082] To facilitate application-level use and considering the stringent computational requirements of decryption algorithms when implementing real-time decryption of encrypted data streams on mobile devices, this embodiment of the invention provides a simple built-in default encryption algorithm based on the characteristics of the target encrypted multimedia file (encrypted video). The specific process is as follows: Figure 6 As shown, the first data is the data before the preset byte position (the first 32kb) of the multimedia file to be encrypted (hereinafter referred to as the first 32kb data). The second data is used to indicate the data after the preset byte position in the multimedia file to be encrypted, that is, the data after the first 32kb (hereinafter referred to as the subsequent data). Taking the preset stream encryption algorithm (Rivest Cipher 4, RC4) as an example, the multimedia file to be encrypted is classified to obtain the first 32kb data and the subsequent data. Based on the RC4 algorithm, the first 32kb data is encrypted, and the subsequent data is subjected to a single table substitution. The encrypted first 32kb data and the encrypted subsequent data are merged to obtain the encrypted multimedia file.
[0083] It should be noted that if a complex encryption algorithm (e.g., the RC4 stream cipher algorithm) is used to encrypt the first data, then the mapping table used to encrypt the second data (single table substitution) is the mapping table calculated when encrypting the first data. If a non-complex encryption algorithm (e.g., the RC4 stream cipher algorithm) is used to encrypt the first data, then the mapping table used to encrypt the second data (single table substitution) is a mapping table that is recalculated separately.
[0084] In practical use, the application can choose a suitable encryption and decryption algorithm. When the encryption and decryption algorithm used is not a complex encryption algorithm (e.g., stream cipher RC4) and single-table permutation, there is no need to distinguish between the first and second data. That is, there is no need to classify the multimedia file to be encrypted to obtain the first and second data. The first data is encrypted by the preset stream cipher RC4, and the second data is subjected to single-table permutation. The built-in algorithm used in this embodiment (i.e., a complex encryption algorithm (e.g., stream cipher RC4) and single-table permutation) distinguishes between the first and second data because some encryption algorithms have too much computational complexity when decrypting, which will burden the performance of the mobile terminal. If the terminal is a personal computer (PC), a more complex algorithm can be used for greater security. Moreover, the random string generated by the stream cipher RC4 and single-table permutation encryption method can be used for the calculation of the permutation table.
[0085] Specifically, a state vector and a mapping table of preset length are initialized respectively to obtain the initialized state vector and the initialized mapping table; an initial password of preset length is generated based on the input password, and the initial password is truncated to obtain the target password; the initialized state vector is replaced to obtain the replaced initialized state vector; the target mapping table is generated based on the replaced initialized state vector and the initialized mapping table; the multimedia file to be encrypted is classified to obtain first data and second data, where the first data indicates the data before a preset byte position in the multimedia file to be encrypted, and the second data indicates the data after the preset byte position in the multimedia file to be encrypted; based on a preset stream encryption algorithm, the first data is encrypted based on the target password, and the second data is encrypted based on the target mapping table; the encrypted first data and the encrypted second data are merged to obtain the encrypted multimedia file.
[0086] For example, the first step is to initialize a state vector of length 256 and a mapping table of length 256, resulting in an initialized state vector S: S = {0, 1, 2, 3, ..., 255} and an initialized mapping table M: M = {0, 1, 2, 3, ..., 255}. The second step is to generate an initial password of length 256 based on the input password. If the initial password length is greater than or equal to 256, the first 256 characters are truncated. If the initial password length is less than 256, the target password is generated cyclically. For example, if the initial password is 1, 2, 3, 4, 5, 6, the target password is T = {1, 2, 3, 4, 5, 6, 1, 2, 3, 4, 5, 6, 1, ..., 4, 6}, where each character is an ASCII character. Special symbols and letters are represented by their corresponding ASCII values (numbers) in this paper; the third step: perform a replacement operation on the initialization state vector S, and the replaced initialization state vector has a certain degree of randomness; the fourth step: use the replaced initialization state vector and the initialization mapping table M to generate the target mapping table, which stores a randomized and non-repeating set of ASCII characters generated according to the target password; the fifth step: encrypt the first data (i.e., the data before the preset byte position of the multimedia file to be encrypted, i.e., the first n bytes (n≥32*1024)) based on the target password using the RC4 algorithm (achieved by performing an XOR operation), encrypt the second data using the target mapping table, and merge the encrypted first data and the encrypted second data to obtain the encrypted multimedia file.
[0087] Step S502: Through the player engine layer, the address information of the target encrypted multimedia file is passed into the ffmpeg layer by calling the preset ffmpeg layer interface.
[0088] The address information of the target encrypted multimedia file is passed to ffmpeg by calling the ffmpeg interface through the player engine SDK layer.
[0089] By adding a custom protocol name (specifying the protocol name) before the save address of the target encrypted multimedia file, it is possible to randomly read all stream addresses and play the target encrypted multimedia file corresponding to all read stream addresses.
[0090] Step S503: The specified protocol is called through the ffmpeg layer to stream the target encrypted multimedia file and obtain the encrypted data stream.
[0091] By calling a specified protocol through the ffmpeg layer, the target encrypted multimedia file is read in a streaming manner through the specified protocol. After obtaining the encrypted data stream, the ffmpeg layer sends the encrypted data stream to the application layer through the buffer parameter of the callback function.
[0092] In one implementation, the execution process of step S503 includes: obtaining the address information of the target encrypted multimedia file through the ffmpeg layer, parsing the address information to obtain the specified protocol name and the storage address; locating the specified protocol based on the specified protocol name; and reading the target encrypted multimedia file from the external storage in a streaming manner into memory based on the storage address using the specified protocol to obtain an encrypted data stream.
[0093] The ffmpeg layer can be used to obtain the retrieval information of the target encrypted multimedia file. This retrieval information can be the filename, storage location, or address of the target encrypted multimedia file, where the storage address is an external storage address, such as a disk path. The retrieval information is used to match (search) the stored disk to obtain the address information of the corresponding target encrypted multimedia file. The address information of the target encrypted multimedia file is parsed to obtain the specified protocol name and storage address. As an example, and not a limitation, the specified protocol name in this embodiment is CCMediaDataSource. The specified protocol is located by the specified protocol name CCMediaDataSource. As an example, and not a limitation, the specified protocol in this embodiment is CCSecretProtocol. The disk is a type of external storage. As an example, and not a limitation, the external storage in this embodiment is a disk. The target encrypted multimedia file is read from the stored disk into memory in a streaming manner based on the storage address using the specified protocol CCSecretProtocol to obtain an encrypted data stream.
[0094] By calling the specified protocol in the ffmpeg layer to stream the target encrypted multimedia file, the encrypted data stream is obtained, thus realizing the protocol decryption function of the ffmpeg layer tool.
[0095] In another implementation, step S503 includes: calling a specified protocol to obtain the protocol context based on the specified protocol name, and setting the file size in the disk to be read in a single operation based on the protocol context; obtaining a seek value, setting the file offset of the target encrypted multimedia file to the position corresponding to the seek value based on the save address, and obtaining the file read position; calling a preset read function, and reading the target encrypted multimedia file into memory as a stream based on the file read position and file size, and obtaining an encrypted data stream. Specifically, calling a specified protocol to obtain the protocol name from the Uniform Resource Locator (URL), obtaining the protocol context based on the specified protocol name, and setting the file size in the disk to be read in a single operation based on the protocol context; determining whether a seek operation is required; if not, not executing; if so, obtaining the corresponding seek value, setting the file offset of the target encrypted multimedia file to the position corresponding to the seek value based on the save address, and obtaining the file read position; calling a preset read function, and reading the target encrypted multimedia file into memory as a stream based on the file read position and file size, and obtaining an encrypted data stream.
[0096] In ffmpeg, data stream reading operations are implemented through URLProtocols. Different streaming media protocols correspond to different URLProtocols. These URLProtocols have a unified external interface to facilitate unified processing by ffmpeg. For example, there are external interfaces for opening streams (url_open), reading streams (url_read), writing streams (url_write), seeking streams (url_seek), and closing streams (url_close). The specific implementation of each external interface varies depending on the streaming protocol type. For example, the url_open interface opens a local file in a file reading protocol (such as the specified protocol CCSecretProtocol), while in an HTTP streaming protocol, it establishes a TCP connection to the server. During playback, ffmpeg locates the specified protocol URLProtocol based on the protocol name preceding the target encrypted multimedia file's save address and uses that URLProtocol to perform relevant operations on the target encrypted multimedia file.
[0097] The ffmpeg layer calls a specified protocol to obtain the protocol context based on the specified protocol name, and sets the file size stored on the disk for a single read based on the protocol context (e.g., size = 32768). This can be achieved by setting the initial size of the content read in a single read, obtaining the file status on the disk based on the protocol context, and setting the file size stored on the disk for a single read based on the file status and the initial size of the content read in a single read. File offset positioning is then performed: based on the save address, the file offset position of the target encrypted multimedia file is set to the position corresponding to the seek value, thus obtaining the file read... The file read position is the target position for reading data from the target encrypted multimedia file during the seek operation. The file offset position is used to indicate the position after adding the offset to the beginning of the file (i.e., the target position mentioned above). For example, if the target encrypted multimedia file is 10kb in size (for illustrative purposes only), the file offset position is the point corresponding to the offset (5kb) from the beginning of the target encrypted multimedia file, that is, the position corresponding to the 5th kilobyte of the target encrypted multimedia file. The preset read function (ccsecret_read) is called to read the target encrypted multimedia file into memory as a stream based on the file position and file size, thus obtaining the encrypted data stream.
[0098] By using a pre-defined protocol, the ffmpeg layer is able to randomly read target encrypted multimedia files and obtain an encrypted data stream.
[0099] Step S504: Decrypt the encrypted data stream through the application layer to obtain the decrypted data stream.
[0100] In one implementation, the steps of decrypting the encrypted data stream through the application layer to obtain the decrypted data stream include: calling a pre-set password initialization decryption module through the application layer, decrypting the first data in the encrypted data stream based on the stream encryption algorithm and obtaining the inverse mapping table, and decrypting the second data in the encrypted data stream based on the inverse mapping table to obtain the decrypted data stream.
[0101] It should be noted that if a complex encryption algorithm (e.g., the RC4 stream cipher algorithm) is used to encrypt the first data, then the inverse mapping table used to decrypt the second data is the inverse mapping table calculated when encrypting the first data. If a non-complex encryption algorithm (e.g., the RC4 stream cipher algorithm) is used to encrypt the first data, then the inverse mapping table used to decrypt the second data is a separately recalculated inverse mapping table.
[0102] In practical use, the application can choose the appropriate encryption and decryption algorithm. When the encryption and decryption algorithm used is not a complex encryption algorithm (e.g., stream cipher RC4) and a single table permutation, there is no need to distinguish between the first data and the second data during decryption. That is, there is no need to decrypt the first data in the encrypted data stream based on the stream cipher algorithm and decrypt the second data in the encrypted data stream based on the inverse mapping table.
[0103] The execution process of the first four steps of decrypting the data stream by calling the pre-set password initialization and decryption module through the application layer is similar to the execution process of the first four steps of encryption. It also requires the generation of an initialization state vector and a target mapping table. The subsequent steps are as follows: Generate an inverse mapping table; Decrypt the first data in the encrypted data stream based on the target password by calling the RC4 algorithm through the application. Since the original value can be obtained by performing two XOR operations with the same value, and an XOR operation was performed during encryption, it can be calculated again during decryption; Decrypt the second data in the encrypted data stream based on the inverse mapping table to obtain the decrypted data stream. Since the decryption of the inverse mapping table is performed on a character-by-character basis, the data to be decrypted can be any segment of the encrypted data stream. It supports random access operations such as seek during playback of the target multimedia file. It can be seen that the time complexity of decryption is O(n) level (where n is the length of the encrypted data stream) and the same as the memory copy complexity, which can meet the stringent requirements of mobile devices and embedded devices for computational complexity.
[0104] In one implementation, the steps of decrypting the encrypted data stream through the application layer to obtain the decrypted data stream include: feeding the encrypted data stream into a preset player engine layer, and feeding the encrypted data stream into the application layer through the player engine layer; and replacing the original file header data of the encrypted data stream through the application layer to obtain the decrypted data stream.
[0105] Taking encrypted multimedia files, specifically encrypted videos, as an example, since the main parameter information of encrypted videos is usually stored in the video header, some applications use a simple method of replacing the video header to encrypt the video. This involves replacing the header of the multimedia file to be encrypted, and then, during video playback, finding both the original header and the video file with the replaced header, replacing them to revert to a complete video for playback. However, this method is insecure, especially since the video file with the original header is stored on the disk and easily accessible to users. To enhance the security of this method (header replacement encryption / decryption), this invention provides a solution, such as... Figure 7As shown, the encrypted data stream is the header data of the replaced header file, i.e., the replacement data. The ffmpeg layer passes the replacement data (target encrypted file) and its corresponding file location to the player engine SDK layer. The player engine SDK layer then passes the replacement data and file location to the application layer. The application layer replaces the original file header data in the encrypted data stream based on the replacement data and file location, obtaining the original header data, i.e., the decrypted data stream. This encrypted data stream is the header data after replacing the original file header data. The player engine SDK layer sends the original header data to the ffmpeg layer, which decapsulates and decodes the original header data to obtain the original video content (i.e., the data to be played), and then passes the original video content back to the player engine SDK layer, i.e., the data is returned to the player engine SDK layer unchanged.
[0106] In one implementation, the step of replacing the original file header data in the encrypted data stream to obtain the decrypted data stream through the application layer includes: obtaining the offset and read data length of the encrypted data stream based on a preset callback function through the application layer; determining whether the encrypted data stream corresponds to the original multimedia file header based on the offset and read data length; if the encrypted data stream corresponds to the original multimedia file header, obtaining the target data in the encrypted data stream; and replacing the target data with the header data of the original multimedia file to obtain the decrypted data stream.
[0107] Because the callback function of CCSecretProtocol contains a file descriptor, the application layer can use the callback function to obtain the offset and length of the current file data (i.e., the encrypted data stream). When it finds that the read data contains video header content (i.e., multimedia header content), it can directly replace the read data in memory with the actual video header data (i.e., the original file header data) and return it to the player engine SDK. Therefore, through the application, the offset and length of the encrypted data stream are obtained based on the preset callback function; based on the offset and length of the read data, it is determined whether the encrypted data stream corresponds to the original multimedia file header; if the encrypted data stream does not correspond to the original multimedia file header, no processing is performed; if the encrypted data stream corresponds to the original multimedia file header, the target data in the encrypted data stream is obtained; the target data is replaced with the header data of the original multimedia file to obtain the decrypted data stream. The target data in the encrypted data stream is used to indicate meaningless data after replacement. This data does not belong to the original multimedia file (original multimedia file) but is a piece of meaningless data that is artificially created, such as randomly generated data.
[0108] For example, a video file is 100 bytes long (this is just an example). The first 10 bytes are the video header (i.e., the original multimedia file header), and the last 90 bytes are the video content. During encryption, the first 10 bytes are replaced with 10 bytes of meaningless data (i.e., the target data), such as all zeros. During decryption, these 100 bytes of data are read byte by byte, forming an encrypted data stream. If the currently read byte is the 3rd byte, which belongs to the header position of the original video, then the application layer replaces it with the data corresponding to the 3rd byte in the header file (i.e., the header data of the original multimedia file) and returns it to ffmpeg. If the currently read data is the 50th byte, which is not in the header position, then it is returned to ffmpeg as is.
[0109] By playing the encrypted data stream with the replaced header directly at the application layer, there is no need to temporarily save the complete video containing the real header, which reduces the risk of the encrypted data stream being cracked.
[0110] Step S505: The decrypted data stream is played through the player engine layer and the ffmpeg layer.
[0111] The ffmpeg layer decrypts and decodes the data stream to obtain the data to be played. Specifically, the ffmpeg layer parses the decrypted data stream into the corresponding encapsulation format data to decapsulate it, resulting in a decapsulated data stream. This decapsulated data stream is then decoded to obtain the data to be played, which is then sent to the player engine layer. The player engine layer renders the data to be played and displays it on a screen or other display device. In detail, the ffmpeg layer separates the decrypted data stream into corresponding multimedia compressed encoded data, i.e., it decapsulates the decrypted data stream. The decapsulated data stream after decryption is actually an encapsulated data stream (e.g., mp4, flv, etc. are all encapsulated data streams). The encapsulated data stream can be an encapsulated audio data stream, an encapsulated video data stream, or more often, a mixture of audio and video data. For example, if the decapsulated data stream is mixed audio and video encoded data, the decoded multimedia compressed encoded data is separated into audio and video data streams. The ffmpeg layer decodes the compressed multimedia data into uncompressed raw data, thus obtaining the data to be played.
[0112] This invention provides an architecture and method for real-time decryption and playback of encrypted multimedia files based on ffmpeg's modifiable encryption and decryption algorithms. It adds a specific protocol, CCSecretProtocol, for real-time decryption and playback to ffmpeg's existing URLProtocol protocol suite. When playing a target encrypted multimedia file, it enables random reading (occurring during seek operations) and real-time decryption and playback. Encryption and decryption do not involve segmentation or temporary storage of the target encrypted multimedia file, thus preventing content leakage.
[0113] By separating the playback logic of the player engine from the decryption logic of the target encrypted multimedia file, the application layer can freely define encryption and decryption algorithms, and the various processes are seamlessly connected. This solves the problem that the decryption scheme cannot be modified after the application layer connects to the player engine SDK layer. Furthermore, the multimedia file playback method provided by this invention operates at the decryption protocol layer, thus it is applicable to all current encapsulation and encoding formats. It provides a default encryption and decryption algorithm, and testing has confirmed that its resource consumption is low, meeting the performance requirements of mobile devices while ensuring data security.
[0114] The aforementioned multimedia file playback method not only achieves seamless integration of data reading, decryption, and playback by having the encrypted data corresponding to the target encrypted multimedia file flow as a data stream between the application layer, player engine layer, and ffmpeg layer, thus solving the problems of ffmpeg's inability to read encrypted files and playback stuttering and latency caused by pre-decryption, but also enables real-time decryption and playback of encrypted multimedia files. Furthermore, it facilitates SDK integration with software, allows for free definition of encryption and decryption algorithms, reduces the maintenance cost of the SDK itself, and enables random reading of all stream addresses and playback of the encrypted data streams corresponding to all read stream addresses. Encryption and decryption do not involve segmentation or temporary storage of the target multimedia file, preventing content leakage and meeting the performance requirements of mobile devices while ensuring data security.
[0115] For the corresponding method embodiments described above, see [link to relevant documentation]. Figure 8 The diagram shown is a schematic of a multimedia file playback device.
[0116] The reading module 801 is used to call a specified protocol through the ffmpeg layer to stream the target encrypted multimedia file and obtain an encrypted data stream.
[0117] The decryption module 802 is used to decrypt the encrypted data stream through the application layer to obtain the decrypted data stream;
[0118] The playback module 803 is used to process the decrypted data stream through the player engine layer and the ffmpeg layer.
[0119] The aforementioned multimedia file playback device calls a specified protocol through the ffmpeg layer to stream the target encrypted multimedia file, obtaining an encrypted data stream. The application layer then decrypts the encrypted data stream, obtaining a decrypted data stream. Finally, the player engine layer and the ffmpeg layer process the decrypted data stream for playback. In this method, the encrypted data corresponding to the target encrypted multimedia file flows as a data stream between the application layer, player engine layer, and ffmpeg layer, achieving seamless integration of data reading, data decryption, and data playback. This solves the problems of ffmpeg's inability to read encrypted files and playback stuttering and latency caused by pre-decryption, enabling real-time decryption and playback of encrypted multimedia files.
[0120] Multimedia file playback devices also include:
[0121] The splicing module 804 is used to obtain the specified protocol name and storage address of the target encrypted multimedia file through the application layer, and splice the specified protocol name and storage address to obtain the address information of the target encrypted multimedia file. The specified protocol name is used by the ffmpeg layer to call the specified protocol to stream the target encrypted multimedia file based on the storage address through the specified protocol.
[0122] The transmission module 805 is used to pass the address information of the target encrypted multimedia file into the ffmpeg layer by calling the preset ffmpeg layer interface through the player engine layer.
[0123] The reading module 801 is also used to: obtain the address information of the target encrypted multimedia file through the ffmpeg layer, and parse the address information to obtain the specified protocol name and storage address;
[0124] Locate the specified protocol based on the specified protocol name;
[0125] By specifying a protocol and based on the storage address, the target encrypted multimedia file is read into memory in a streaming manner from the stored disk, resulting in an encrypted data stream.
[0126] The reading module 801 is also used to: call a specified protocol to obtain the protocol context based on the specified protocol name, and set the file size stored in the external storage for a single read based on the protocol context;
[0127] Obtain the seek value, and based on the save address, set the file offset of the target encrypted multimedia file to the position corresponding to the seek value to obtain the file read position;
[0128] The preset read function is called to read the target encrypted multimedia file into memory as a stream, based on the file read position and file size, thus obtaining an encrypted data stream.
[0129] The decryption module 802 is also used to: stream encrypted data into a preset player engine layer, and stream encrypted data into the application layer through the player engine layer;
[0130] The encrypted data stream is decrypted by replacing the header data of the original file at the application layer.
[0131] The decryption module 802 is also used to: obtain the offset of the encrypted data stream and the length of the read data based on a preset callback function through the application layer;
[0132] Based on the offset and the length of the read data, determine whether the encrypted data stream corresponds to the original multimedia file header file;
[0133] If the encrypted data stream corresponds to the header file of the original multimedia file, then obtain the target data in the encrypted data stream;
[0134] The target data is replaced with the header data of the original multimedia file to obtain the decrypted data stream.
[0135] Multimedia file playback devices also include:
[0136] The classification module 806 is used to classify the multimedia file to be encrypted to obtain first data and second data. The first data is used to indicate the data before the preset byte position in the multimedia file to be encrypted, and the second data is used to indicate the data after the preset byte position in the multimedia file to be encrypted.
[0137] The encryption module 807 is used to encrypt the first data based on a preset stream encryption algorithm and perform a single-table permutation on the second data to obtain an encrypted multimedia file.
[0138] The decryption module 802 is also used to: call a preset password to initialize the decryption module through the application layer, decrypt the first data in the encrypted data stream based on the stream encryption algorithm, obtain the inverse mapping table, and decrypt the second data in the encrypted data stream based on the inverse mapping table to obtain the decrypted data stream.
[0139] This embodiment also provides an electronic device, including a processor and a memory. The memory stores machine-executable instructions that can be executed by the processor. The processor executes the machine-executable instructions to implement the aforementioned method for playing multimedia files. This electronic device can be a server or a terminal device.
[0140] See Figure 9As shown, the electronic device includes a processor 900 and a memory 901. The memory 901 stores machine-executable instructions that can be executed by the processor 900. The processor 900 executes the machine-executable instructions to implement the aforementioned method for playing multimedia files.
[0141] Furthermore, Figure 9 The electronic device shown also includes a bus 902 and a communication interface 903. The processor 800, the communication interface 903, and the memory 901 are connected via the bus 902.
[0142] The memory 901 may include high-speed random access memory (RAM) or non-volatile memory, such as at least one disk storage device. Communication between this system network element and at least one other network element is achieved through at least one communication interface 903 (which can be wired or wireless), such as the Internet, wide area network, local area network, or metropolitan area network. The bus 902 may be an ISA bus, PCI bus, or EISA bus, etc. The bus can be divided into address bus, data bus, control bus, etc. For ease of representation, Figure 9 The symbol is represented by a single double-headed arrow, but this does not mean that there is only one bus or one type of bus.
[0143] The processor 900 may be an integrated circuit chip with signal processing capabilities. In implementation, each step of the above method can be completed by the integrated logic circuitry in the hardware of the processor 900 or by instructions in software form. The processor 900 may be a general-purpose processor, including a Central Processing Unit (CPU), a Network Processor (NP), etc.; it may also be a Digital Signal Processor (DSP), an Application Specific Integrated Circuit (ASIC), a Field-Programmable Gate Array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. It can implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of this invention. The general-purpose processor may be a microprocessor or any conventional processor. The steps of the methods disclosed in the embodiments of this invention can be directly manifested as execution by a hardware decoding processor, or execution by a combination of hardware and software modules in the decoding processor. The software module can reside in a readily available storage medium in the art, such as random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, or registers. This storage medium is located in memory 901. The processor 900 reads the information from memory 901 and, in conjunction with its hardware, completes the steps of the method described in the foregoing embodiments.
[0144] This embodiment also provides a machine-readable storage medium storing machine-executable instructions. When the machine-executable instructions are called and executed by the processor, the machine-executable instructions cause the processor to implement the above-mentioned multimedia file playback method.
[0145] The multimedia file playback method, apparatus, electronic device, and storage medium computer program product provided in the embodiments of the present invention include a computer-readable storage medium storing program code. The instructions included in the program code can be used to execute the methods in the preceding method embodiments. For specific implementation, please refer to the method embodiments, which will not be repeated here.
[0146] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the specific working process of the system and apparatus described above can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.
[0147] Furthermore, in the description of the embodiments of the present invention, unless otherwise explicitly specified and limited, the terms "installation," "connection," and "linking" should be interpreted broadly. For example, they can refer to a fixed connection, a detachable connection, or an integral connection; they can refer to a mechanical connection or an electrical connection; they can refer to a direct connection or an indirect connection through an intermediate medium; and they can refer to the internal connection of two components. Those skilled in the art can understand the specific meaning of the above terms in the present invention based on the specific circumstances.
[0148] If a function is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of this invention, or the part that contributes to the prior art, or a part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods of the various embodiments of this invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.
[0149] In the description of this invention, it should be noted that the terms "center," "upper," "lower," "left," "right," "vertical," "horizontal," "inner," and "outer," etc., indicate the orientation or positional relationship based on the orientation or positional relationship shown in the accompanying drawings. They are used only for the convenience of describing the invention and for simplifying the description, and do not indicate or imply that the device or element referred to must have a specific orientation, or be constructed and operated in a specific orientation. Therefore, they should not be construed as limitations on the invention. Furthermore, the terms "first," "second," and "third" are used for descriptive purposes only and should not be construed as indicating or implying relative importance.
[0150] Finally, it should be noted that the above embodiments are merely specific implementations of the present invention, used to illustrate the technical solutions of the present invention, and not to limit it. The scope of protection of the present invention is not limited thereto. Although the present invention has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that any person skilled in the art can still modify or easily conceive of changes to the technical solutions described in the foregoing embodiments within the technical scope disclosed in the present invention, or make equivalent substitutions for some of the technical features; and these modifications, changes, or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of the present invention, and should all be covered within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.
Claims
1. A method of playing a multimedia file, characterized by, The method includes: The specified protocol is called through the ffmpeg layer to read the target encrypted multimedia file in a streaming manner through the specified protocol, and an encrypted data stream is obtained. The specified protocol is a structure type used for decryption in the ffmpeg layer. The encrypted data stream is the data obtained after decrypting the data of the target encrypted multimedia file that is being streamed. The encrypted data stream is decrypted at the application layer to obtain the decrypted data stream; The decrypted data stream is played through the player engine layer and the ffmpeg layer; Before the step of calling a specified protocol through the ffmpeg layer to stream the target encrypted multimedia file and obtain the encrypted data stream, the method further includes: The application layer obtains the specified protocol name and storage address of the target encrypted multimedia file, and concatenates the specified protocol name with the storage address to obtain the address information of the target encrypted multimedia file. The specified protocol name is used by the ffmpeg layer to call the specified protocol to stream the target encrypted multimedia file based on the storage address. The address information of the target encrypted multimedia file is passed into the ffmpeg layer by calling the preset ffmpeg layer interface through the player engine layer.
2. The method of claim 1, wherein, The step of calling a specified protocol through the ffmpeg layer to stream the target encrypted multimedia file and obtain an encrypted data stream includes: The address information of the target encrypted multimedia file is obtained through the ffmpeg layer, and the address information is parsed to obtain the specified protocol name and storage address; Locate the specified protocol based on the specified protocol name; The target encrypted multimedia file is read into memory in a streaming manner from the stored disk based on the specified storage address using the specified protocol, thus obtaining an encrypted data stream.
3. The method of claim 2, wherein, The step of reading the target encrypted multimedia file from the stored disk in a streaming manner into memory based on the specified protocol and the storage address to obtain an encrypted data stream includes: The specified protocol is invoked to obtain the protocol context based on the specified protocol name, and the file size in the disk to be read in a single operation is set based on the protocol context; Obtain the seek value, and based on the storage address, set the file offset position of the target encrypted multimedia file to the position corresponding to the seek value to obtain the file read position; A preset read function is invoked to read the target encrypted multimedia file into memory in a stream manner, based on the file read position and the file size, thereby obtaining an encrypted data stream.
4. The method of claim 1, wherein, The step of decrypting the encrypted data stream through the application layer to obtain the decrypted data stream includes: The encrypted data stream is fed into a preset player engine layer, and then fed into the application layer through the player engine layer. The encrypted data stream is decrypted by replacing the original file header data through the application layer.
5. The method of claim 4, wherein, The step of replacing the original file header data of the encrypted data stream through the application layer to obtain the decrypted data stream includes: The application layer is used to obtain the offset and read data length of the encrypted data stream based on a preset callback function; Based on the offset and read data length, it is judged whether the encrypted data stream corresponds to the original multimedia file header file; If the encrypted data stream corresponds to the original multimedia file header file, the target data in the encrypted data stream is obtained; The target data is replaced with the header data of the original multimedia file to obtain a decrypted data stream.
6. The method according to any one of claims 1-3, characterized in that, Before the step of calling a specified protocol through the ffmpeg layer to stream read the target encrypted multimedia file through the specified protocol to obtain an encrypted data stream, the method further includes: Classifying the multimedia file to be encrypted to obtain first data and second data, the first data being used to indicate data before a preset byte position of the multimedia file to be encrypted, and the second data being used to indicate data after the preset byte position of the multimedia file to be encrypted; Encrypting the first data based on a preset stream encryption algorithm and performing single table replacement on the second data to obtain an encrypted multimedia file.
7. The method of claim 6, wherein, The step of decrypting the encrypted data stream through the application layer to obtain a decrypted data stream includes: A preset password initialization decryption module is called through the application layer, the first data in the encrypted data stream is decrypted based on the stream encryption algorithm, and an inverse mapping table is obtained, the second data in the encrypted data stream is decrypted based on the inverse mapping table to obtain a decrypted data stream.
8. An apparatus for playing a multimedia file, characterized by comprising: The multimedia file playing device includes: A reading module is configured to call a specified protocol through the ffmpeg layer to stream read a target encrypted multimedia file through the specified protocol to obtain an encrypted data stream, the specified protocol being a structure type used for protocol resolution in the ffmpeg layer, and the encrypted data stream being data obtained by resolving the data of the stream read target encrypted multimedia file; A decryption module is configured to decrypt the encrypted data stream through the application layer to obtain a decrypted data stream; A playing module is configured to play process the decrypted data stream through the player engine layer and the ffmpeg layer; The multimedia file playing device further includes: A splicing module is configured to obtain a specified protocol name and a save address of a target encrypted multimedia file through the application layer, and splice the specified protocol name and the save address to obtain address information of the target encrypted multimedia file, wherein the specified protocol name is used to call a specified protocol through the ffmpeg layer to stream read the target encrypted multimedia file based on the save address; A transmission module is configured to call a preset ffmpeg layer interface through the player engine layer to transmit the address information of the target encrypted multimedia file into the ffmpeg layer.
9. An electronic device, comprising: The processor executes the machine executable instructions to implement the multimedia file playing method of any one of claims 1-7.
10. A machine-readable storage medium, characterized in that, The machine readable storage medium stores machine executable instructions that, when invoked and executed by a processor, cause the processor to implement the method of playing a multimedia file according to any one of claims 1-7.
Citation Information
Patent Citations
Method and apparatus for playing video data streams
CN107318045A