Subtitling replacement method, apparatus, device, storage medium, and program product

By constructing a balanced index tree with timestamps as nodes and a priority mechanism, the problem of inflexible subtitle updates is solved, enabling frame-level dynamic replacement of subtitles during video playback. This improves the flexibility and efficiency of subtitle updates and ensures the timeliness and stability of subtitle display.

CN122227017APending Publication Date: 2026-06-16CHONGQING CHANGAN AUTOMOBILE CO LTD

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
CHONGQING CHANGAN AUTOMOBILE CO LTD
Filing Date
2026-04-03
Publication Date
2026-06-16

AI Technical Summary

Technical Problem

Current technology cannot flexibly update subtitles, resulting in long processing times when frequently modifying or adapting to multiple languages, which makes it difficult to meet the needs of rapid iteration in short videos, interactive dramas, and other similar content.

Method used

By constructing a timestamp-based balanced index tree, using timestamps to build an initial binary search tree for nodes and performing balance adjustments, the system achieves fast retrieval and accurate matching of subtitle replacement instructions. It also combines a priority mechanism to handle conflicts between multiple instructions and employs a secure transmission protocol to ensure data integrity and source credibility.

Benefits of technology

It enables frame-level dynamic replacement of subtitles during video playback, improving the flexibility and efficiency of subtitle updates, ensuring the timeliness, uniqueness, and stability of subtitle display, and meeting the needs of multilingual adaptation and real-time error correction.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN122227017A_ABST
    Figure CN122227017A_ABST
Patent Text Reader

Abstract

The application provides a subtitle replacement method, device, equipment, storage medium and program product. It relates to the technical field of multimedia, and the method comprises the following steps: based on at least one pre-acquired subtitle replacement instruction, a balanced index tree is established with a timestamp as a node; in the process of video playing, a target timestamp of a target frame is acquired, and based on the target timestamp and the balanced index tree, a target subtitle replacement instruction is searched; if the original text in the target subtitle replacement instruction is consistent with the original subtitle text of the target frame, the original subtitle text is replaced with the replacement text in the target subtitle replacement instruction, a target subtitle is generated, and when the video plays to the target frame, the target subtitle is displayed. The method realizes the ordered arrangement and quick retrieval of the subtitle replacement instruction by constructing the balanced index tree with the timestamp as the node, and in combination with the target timestamp positioning the corresponding target subtitle replacement instruction, the efficiency and flexibility of the subtitle replacement can be greatly improved, and the replacement process is accurate and controllable.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of multimedia technology, and in particular to a method, apparatus, device, storage medium, and program product for subtitle replacement. Background Technology

[0002] With the continuous development of multimedia technology, subtitles have become an indispensable part of multimedia content. To adapt to the global distribution trend of multimedia content, the same video content often needs to be accompanied by subtitles in different languages. At the same time, with the rise of emerging business formats such as short videos and interactive dramas, the frequency of subtitle updates has also increased, which places higher demands on the flexibility of subtitle replacement.

[0003] In related technologies, subtitles are typically hard-coded and embedded directly into the video frame to generate a video file with subtitles. However, when subtitles need to be modified or updated, the entire video file must be remade, which is time-consuming and results in poor flexibility in replacing subtitles. Summary of the Invention

[0004] One objective of this invention is to provide a subtitle replacement method to improve the flexibility of subtitle replacement; a second objective is to provide a subtitle replacement device; a third objective is to provide an electronic device; a fourth objective is to provide a computer-readable storage medium; and a fifth objective is to provide a computer program product.

[0005] To achieve the above objectives, the technical solution adopted by the present invention is as follows:

[0006] A method for replacing subtitles, comprising:

[0007] Based on at least one pre-acquired subtitle replacement instruction, a balanced index tree is built with timestamps as nodes. The subtitle replacement instruction includes a display timestamp, the original text, and the replacement text.

[0008] During video playback, the target timestamp of the target frame is obtained, and based on the target timestamp and the balanced index tree, the target subtitle replacement instruction is found, wherein the display timestamp in the target subtitle replacement instruction is consistent with the target timestamp;

[0009] If the original text in the target subtitle replacement instruction is consistent with the original subtitle text of the target frame, then the original subtitle text is replaced with the replacement text in the target subtitle replacement instruction to generate the target subtitle;

[0010] When the video plays to the target frame, the target subtitle is displayed.

[0011] Based on the above technical means, frame-level accurate dynamic replacement of subtitles can be achieved during video playback without re-encoding the video or replacing the entire subtitle file. By using a balanced index tree to achieve fast retrieval of replacement instructions, the efficiency and flexibility of replacement can be greatly improved while ensuring the accuracy of subtitle replacement. This meets the diverse needs of subtitle updates, multilingual adaptation, real-time error correction, and personalized insertion in scenarios such as short videos and interactive dramas.

[0012] Furthermore, the step of building a balanced index tree based on at least one pre-acquired subtitle replacement instruction, using timestamps as nodes, includes:

[0013] Construct an initial binary search tree based on the display timestamp in the at least one subtitle replacement instruction as a node;

[0014] The initial binary search tree is balanced by left and / or right rotation operations to obtain the balanced index tree.

[0015] Based on the above technical means, by constructing an initial binary search tree and performing balancing adjustments, the balance of the index tree can be ensured, avoiding extremely inefficient situations during the search process. This improves the speed of finding target subtitle replacement instructions based on timestamps and effectively guarantees the real-time nature of subtitle replacement during video playback.

[0016] Furthermore, the step of finding the target subtitle replacement instruction based on the target timestamp and the balanced index tree includes:

[0017] The root node of the balanced index tree is determined as the starting node, and the target timestamp is compared with the display timestamp of the starting node;

[0018] When the display timestamp of the starting node is consistent with the target timestamp, the candidate subtitle replacement instruction corresponding to the starting node is determined as the target subtitle replacement instruction;

[0019] If the target timestamp is greater than the display timestamp of the starting node, then the right child node of the starting node is updated to the new starting node; if the target timestamp is less than the display timestamp of the starting node, then the left child node of the starting node is updated to the new starting node.

[0020] Repeat the above process until the target subtitle replacement instruction is found.

[0021] Based on the aforementioned technical means, the specific retrieval logic of the balanced index tree is clarified. By gradually comparing timestamps and iteratively updating the starting node, the target subtitle replacement instruction can be accurately located without traversing all replacement instructions, thereby further improving retrieval efficiency and ensuring that the replacement instruction of the corresponding frame can still be quickly matched in high-speed video playback scenarios, effectively guaranteeing the timeliness of subtitle replacement.

[0022] Furthermore, the subtitle replacement instruction also includes a priority mechanism, and determining the candidate subtitle replacement instruction corresponding to the starting node as the target subtitle replacement instruction includes:

[0023] If the starting node corresponds to multiple candidate subtitle replacement instructions, then the priority of the multiple candidate subtitle replacement instructions is obtained;

[0024] Based on the priority, the candidate subtitle replacement instruction with a preset priority is selected from the multiple candidate subtitle replacement instructions as the target subtitle replacement instruction.

[0025] Based on the above technical means, by setting priorities and selecting replacement instructions according to preset priorities, conflict scenarios of multiple replacement instructions under the same timestamp can be flexibly dealt with, and the target instruction that meets the business needs can be quickly locked. While improving the flexibility of subtitle replacement, the uniqueness of subtitle display results is guaranteed, and display chaos or content conflict caused by the superposition of multiple instructions is avoided.

[0026] Furthermore, before establishing a balanced index tree based on at least one pre-acquired subtitle replacement instruction, using timestamps as nodes, the method further includes:

[0027] Download the subtitle configuration file from the server using a secure transmission protocol;

[0028] The signature of the subtitle configuration file is verified, and if the verification is successful, the at least one subtitle replacement instruction is extracted from the subtitle configuration file.

[0029] Based on the above technical means, by downloading the subtitle configuration file from the server and verifying its signature through a secure transmission protocol before establishing the balanced index tree, the integrity and source credibility of the obtained subtitle replacement instructions can be ensured, preventing the instructions from being tampered with or damaged, and providing a safe and reliable data guarantee for subsequent subtitle replacement operations.

[0030] Furthermore, the subtitle replacement instruction also includes a replacement style corresponding to the replacement text. If the original text in the target subtitle replacement instruction is consistent with the original subtitle text of the target frame, then the original subtitle text is replaced with the replacement text in the target subtitle replacement instruction to generate the target subtitle, including:

[0031] Construct a replacement event, the replacement event including the replacement text and the replacement style corresponding to the replacement text;

[0032] The replacement event is pushed to the rendering thread via a lock-free circular queue, so that the rendering thread asynchronously generates a target caption including the replacement text in the back buffer according to the replacement style.

[0033] Based on the above technical means, by constructing a replacement event containing the replacement text and the corresponding replacement style, the complete transmission of replacement information can be achieved. Furthermore, by pushing the replacement event through a lock-free circular queue, the replacement logic and rendering logic can be effectively decoupled, thread blocking can be avoided, and the processing efficiency of subtitle replacement can be improved.

[0034] Furthermore, displaying the target subtitle when the video plays to the target frame includes:

[0035] When the video plays to the target frame, the pointers of the front buffer and the back buffer are swapped, and the target subtitle is refreshed and output. The front buffer is used to store the current subtitle corresponding to the current frame, and the target frame is located after the current frame.

[0036] Based on the aforementioned technical means, by exchanging the pointers of the pre-buffer and post-buffer to refresh the output target subtitles, the subtitles can be refreshed and displayed quickly, effectively avoiding abnormal phenomena such as stuttering and flickering during the subtitle replacement process. At the same time, by dividing the storage between the pre-buffer and post-buffer, it is possible to ensure that the target subtitles are displayed synchronously with the target frame, improving the stability of the subtitle display and thus providing users with a smooth viewing experience.

[0037] Furthermore, the method also includes:

[0038] If the target subtitle replacement instruction is not found based on the target timestamp and the balanced index tree, the original subtitle text of the target frame will be displayed when the video is played to the target frame.

[0039] Based on the aforementioned technical means, in scenarios where no target subtitle replacement instruction is found, the original subtitle text of the target frame can be displayed by default, which can effectively avoid problems such as missing subtitles and display abnormalities, and ensure the continuity of video viewing.

[0040] A subtitle replacement device, comprising:

[0041] The first processing module is used to build a balanced index tree with timestamps as nodes based on at least one pre-acquired subtitle replacement instruction. The subtitle replacement instruction includes a display timestamp, the original text, and the replacement text.

[0042] The lookup module is used to obtain the target timestamp of the target frame during video playback, and to look up the target subtitle replacement instruction based on the target timestamp and the balanced index tree, wherein the display timestamp in the target subtitle replacement instruction is consistent with the target timestamp;

[0043] The second processing module is used to replace the original subtitle text with the replacement text in the target subtitle replacement instruction if the original text in the target subtitle replacement instruction is consistent with the original subtitle text of the target frame, thereby generating the target subtitle;

[0044] The display module is used to display the target subtitle when the video is played to the target frame.

[0045] An electronic device includes: a memory and a processor;

[0046] The memory stores computer-executed instructions;

[0047] The processor executes the computer execution instructions stored in the memory, causing the processor to perform the above-described subtitle replacement method.

[0048] A computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, are used to implement the above-described subtitle replacement method.

[0049] A computer program product includes a computer program that, when executed by a processor, is used to implement the above-described subtitle replacement method.

[0050] The beneficial effects of this invention are:

[0051] (1) It can realize frame-level dynamic replacement and update of subtitles during video playback without re-encoding the video or replacing the entire subtitle file. The replacement instructions can be quickly retrieved through timestamps and balanced index trees. While ensuring the accuracy of subtitle replacement, it can greatly improve the efficiency of subtitle update and configuration flexibility, and meet the diverse needs of scenarios such as multilingual switching, real-time error correction, and advertising insertion.

[0052] (2) By balancing the index tree structure and hierarchical retrieval logic, the subtitle replacement instructions can be efficiently organized and quickly located without having to traverse and search all instructions. This effectively simplifies the retrieval process, improves matching efficiency, ensures timely response and stable and reliable operation of subtitle replacement during video playback, and guarantees the overall smoothness of video playback and subtitle display.

[0053] (3) By using the priority mechanism and original text verification, the conflict problem of multiple subtitle replacement instructions under the same timestamp can be effectively dealt with, ensuring that the subtitle display result is unique, accurate and controllable, avoiding display confusion, content conflict or incorrect replacement, and improving the reliability and standardization of subtitle replacement. Attached Figure Description

[0054] Figure 1 Flowchart of the subtitle replacement method provided in the embodiments of this application Figure 1 ;

[0055] Figure 2 This is a schematic diagram of a balanced index tree structure provided in an embodiment of this application;

[0056] Figure 3 Flowchart of the subtitle replacement method provided in the embodiments of this application Figure 2 ;

[0057] Figure 4 This is a schematic diagram of the structure of an initial binary search tree provided in an embodiment of this application;

[0058] Figure 5 A flowchart illustrating an example of the subtitle replacement method provided in this application;

[0059] Figure 6 This is a schematic diagram of the subtitle replacement device provided in the embodiments of this application;

[0060] Figure 7 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Detailed Implementation

[0061] The embodiments of the present invention will be described below with reference to the accompanying drawings and preferred embodiments. Those skilled in the art can easily understand other advantages and effects of the present invention from the content disclosed in this specification. The present invention can also be implemented or applied through other different specific embodiments, and various details in this specification can also be modified or changed based on different viewpoints and applications without departing from the spirit of the present invention. It should be understood that the preferred embodiments are only for illustrating the present invention and not for limiting the scope of protection of the present invention.

[0062] It should be noted that the illustrations provided in the following embodiments are only schematic representations of the basic concept of the present invention. Therefore, the drawings only show the components related to the present invention and are not drawn according to the actual number, shape and size of the components in the actual implementation. In the actual implementation, the form, quantity and proportion of each component can be arbitrarily changed, and the layout of the components may also be more complex.

[0063] First, the background technology involved in this application will be explained in detail.

[0064] With the continuous development of internet and multimedia technologies, video has become a major medium for information dissemination and entertainment consumption. Subtitles, as an important component of video content, not only help viewers overcome language barriers but also provide a more user-friendly viewing experience for different user groups, significantly improving the accessibility and reach of video content.

[0065] During video distribution, the same video content often requires subtitles in multiple languages ​​to meet the needs of users in different regions. Meanwhile, with the rise of new formats such as short videos, interactive dramas, and live streaming, the frequency of subtitle updates has increased, placing higher demands on the flexibility and real-time nature of subtitle replacement. For example, after publishing their work, short video creators may need to quickly modify the subtitle content (such as correcting typos and supplementing translations) based on real-time user feedback or trending topics to improve the video's dissemination and viewing experience.

[0066] In related technologies, subtitles are typically hard-coded and directly embedded into the video frame to generate subtitled video files. However, while this method ensures strict synchronization between the subtitles and the video, once generated, the subtitles are permanently bound to the video frame. When the subtitle content needs modification or updating, it's impossible to adjust the subtitles individually; the entire video file must be re-encoded, including re-encoding the video frame and re-embedding the subtitles. This process is time-consuming and requires significant computing resources. For video content that requires frequent subtitle updates or adaptation to multiple languages, this approach lacks flexibility and fails to meet the demands of rapid iteration.

[0067] Based on the above problems, the technical concept of this application is as follows: By pre-obtaining at least one subtitle replacement instruction containing a display timestamp, original text, and replacement text, and constructing a balanced index tree with the display timestamp as a node, the subtitle replacement instructions are organized and indexed in an orderly manner. During video playback, the target timestamp of the target frame is obtained. Leveraging the efficient search characteristics of the balanced index tree, the subtitle replacement instruction matching the target timestamp is located. Furthermore, by comparing the consistency between the original text and the original subtitle text of the target frame, the accuracy of the replacement operation is ensured. Only when the two match is the original subtitle text replaced with the replacement text, generating the target subtitle, which is then displayed during playback of the target frame. Through this method, frame-level precise dynamic replacement of subtitles during video playback can be achieved without re-compressing the video file, effectively improving the flexibility of subtitle updates.

[0068] The technical solution of this application and how it solves the above-mentioned technical problems will be described in detail below with specific embodiments. These specific embodiments can be combined with each other, and the same or similar concepts or processes may not be described again in some embodiments. The embodiments of this application will be described below with reference to the accompanying drawings.

[0069] Figure 1 Flowchart of the subtitle replacement method provided in the embodiments of this application Figure 1 .like Figure 1 As shown, the method includes:

[0070] S101. Based on at least one pre-acquired subtitle replacement instruction, establish a balanced index tree with timestamps as nodes.

[0071] The execution subject of this application embodiment can be an electronic device or a subtitle replacement device installed in an electronic device. The subtitle replacement device can be implemented by software or by a combination of software and hardware. The subtitle replacement device can be a processor in the electronic device. For ease of understanding, the following description will use an electronic device as the execution subject.

[0072] The subtitle replacement instruction includes a Presentation Time Stamp (PTS), the original text, and the replacement text. The presentation time stamp is used to clearly identify the video playback time node corresponding to the subtitle replacement operation, corresponding to the playback sequence of the video frames; the original text corresponds to the original subtitle content in the video that needs to be replaced, and can be identified using the original text fingerprint to ensure the uniqueness and matching accuracy of the original text; the replacement text corresponds to the subtitle content that needs to be displayed after the replacement.

[0073] During video encoding and playback, the calculation of the display timestamp depends on the correspondence between the time base and the playback duration. The time base is used to define the unit of time scale; for example, one second is divided into 90,000 time scales, with each scale corresponding to 1 / 90,000 of a second. The display timestamp of each frame is the total number of time scales elapsed from the start of the video to the current frame. This can be obtained by converting the playback duration of the current frame to the time base, thus accurately identifying the playback sequence of each frame with an integer number. This representation avoids the decimal errors that may arise from directly using seconds, providing a precise timing basis for subsequent timestamp-based subtitle replacement instruction retrieval and subtitle-frame synchronized display.

[0074] Optionally, after obtaining all subtitle replacement instructions, a balanced index tree for fast retrieval can be constructed using the display timestamp in each subtitle replacement instruction as a node identifier. In specific implementation, an initial binary search tree can be constructed based on the display timestamp in at least one subtitle replacement instruction as a node; the initial binary search tree can then be balanced by left and / or right rotation operations to obtain a balanced index tree.

[0075] Specifically, left and right rotation operations refer to balancing operations that adjust the structure of a binary search tree. By changing the parent-child relationship and connection direction between nodes, the height and distribution of the initial binary search tree are optimized so that the binary search tree maintains structural balance after multiple insertions or updates of nodes, thus avoiding the problem of excessively long retrieval paths.

[0076] Figure 2 This is a schematic diagram of a balanced index tree structure provided in an embodiment of this application. Figure 2As shown, this balanced index tree uses the display timestamp from at least one subtitle replacement instruction as a node. It is obtained by constructing an initial binary search tree and then balancing it through left and / or right rotation operations. Each node is identified by its display timestamp, which is an integer number calculated based on a time base. The root node has a display timestamp of 9000, its left child node corresponds to display timestamp 4500, and its right child node corresponds to display timestamp 13500. The left child node further extends to a left child node 1 with display timestamp 2250 and a right child node 1 with display timestamp 6750. The right child node further extends to a left child node 2 with display timestamp 11250 and a right child node 2 with display timestamp 15750. The tree structure is balanced, enabling fast retrieval based on display timestamps.

[0077] In the above implementation, the initial binary search tree can be built first based on the display timestamp to realize the ordered storage of subtitle replacement instructions. Then, the tree structure can be balanced and adjusted by left rotation and / or right rotation operations to keep the balanced index tree structurally balanced and highly stable, thereby reducing the decline in retrieval efficiency caused by tree structure imbalance.

[0078] S102. During video playback, obtain the target timestamp of the target frame, and find the target subtitle replacement instruction based on the target timestamp and the balanced index tree.

[0079] During video playback, electronic devices can track the playback progress and synchronously acquire the video frames to be played as target frames. The target frame is located after the current frame and represents the next frame or more frames to be rendered and displayed. Acquiring the target frame and its timestamp in advance allows sufficient processing time for subtitle replacement operations, preventing issues such as subtitles being out of sync with the video.

[0080] Optionally, the target frame can be determined as follows: During video playback, based on the display timestamp of the currently playing video frame (current frame), and combined with the preset pre-read depth, select video frames that are sequentially after the current frame and within the pre-read range.

[0081] Furthermore, the electronic device can parse the acquired target frame and extract the target timestamp corresponding to the target frame. The calculation method is the same as that of the display timestamp, which depends on the correspondence between the time base and the playback duration.

[0082] Finally, the electronic device can use the parsed target timestamp as a search keyword to perform a search operation in the pre-built balanced index tree. According to the node comparison rules of the balanced index tree, the target timestamp is compared with the display timestamps of each node in the tree in turn, gradually narrowing the search range. When a node that is completely consistent with the target timestamp is found, the subtitle replacement instruction associated with that node can be determined as the target subtitle replacement instruction, and the search matching is completed. If no node that is consistent with the target timestamp is found, it is determined that the current target frame does not need to perform subtitle replacement operation, and the subsequent target frames are processed.

[0083] S103. If the original text in the target subtitle replacement instruction is the same as the original subtitle text in the target frame, then the original subtitle text is replaced with the replacement text in the target subtitle replacement instruction to generate the target subtitle.

[0084] Specifically, after determining the target subtitle replacement instruction, the validity of the subtitle replacement can be verified. If the original text in the target subtitle replacement instruction is consistent with the original subtitle text of the target frame, the target frame is determined to meet the subtitle replacement conditions. The electronic device can immediately perform the subtitle replacement operation, clear the original subtitle text in the target frame, and load the replacement text in the target subtitle replacement instruction.

[0085] Optionally, the specific verification rules are as follows: The original text contained in the target subtitle replacement instruction and the original subtitle text built into the target frame can be extracted separately. First, the two text segments are formatted and standardized to unify the text encoding format, line breaks, space format and punctuation. Then, a character-by-character comparison is used to fully verify the character sequence, character case, special symbols, etc. of the two text segments. At the same time, the length of the two text segments is checked to ensure the accuracy of the verification results.

[0086] If the above verification confirms that the original text in the target subtitle replacement instruction is completely consistent with the original subtitle text of the target frame, then the current target frame is determined to meet the subtitle replacement conditions, and the subsequent replacement operation is executed; if the verification finds that the two texts are inconsistent, the specific location and type of difference of the text inconsistency can be recorded in the log file, including missing characters, character errors, format mismatch, etc., and then the log file is stored for subsequent traceability and investigation.

[0087] After the replacement operation is completed, a target subtitle adapted to the target frame can be generated. This target subtitle is adapted to the playback timing and screen content of the target frame, and is completely consistent with the replacement text in the target subtitle replacement instruction.

[0088] In one alternative implementation, if no target subtitle replacement instruction is found based on the target timestamp and the balanced index tree, the original subtitle text of the target frame is displayed when the video is played to the target frame.

[0089] In practice, if a node matching the target timestamp is not found after a search is completed in the balanced index tree based on the target timestamp, it can be determined that there is no corresponding target subtitle replacement instruction. In this case, no modification can be made to the original subtitle text of the target frame.

[0090] In the above implementation, for scenarios where no target subtitle replacement instruction is found, the original subtitle text of the target frame can be displayed by default to avoid blank subtitles or abnormal display. By retaining the original subtitle text as the default output, it can be ensured that each frame has corresponding subtitle content to display, thereby maintaining the continuity and stability of subtitle display and ensuring that users can obtain a complete and coherent subtitle viewing experience in different playback scenarios.

[0091] S104. When the video plays to the target frame, display the target subtitle.

[0092] Specifically, electronic devices can monitor the video playback progress, compare the current video playback timestamp with the target timestamp of the target frame in real time, and display the target subtitles when the video playback progresses to the timing position indicated by the target timestamp of the target frame.

[0093] In one optional implementation, the subtitle replacement instruction also includes a replacement style corresponding to the replacement text. The replacement style may include parameters such as font style, font size, font color, subtitle transparency, display position offset, and border style. During the display of the target subtitle, the electronic device can extract the replacement style in the subtitle replacement instruction and render the replacement text according to the replacement style.

[0094] In addition, during the display of target subtitles, the rendered target subtitles can be overlaid on the target frame, so that the target subtitles are displayed in the corresponding position of the video frame according to the specified replacement style.

[0095] In this embodiment, a balanced index tree can be built based on at least one pre-acquired subtitle replacement instruction, using timestamps as nodes. During video playback, the target timestamp of the target frame is obtained, and the target subtitle replacement instruction is searched based on the target timestamp and the balanced index tree. If the original text in the target subtitle replacement instruction matches the original subtitle text of the target frame, the original subtitle text is replaced with the replacement text in the target subtitle replacement instruction, generating the target subtitle, which is then displayed when the video reaches the target frame. The subtitle replacement instruction includes a display timestamp, original text, and replacement text, and the display timestamp in the target subtitle replacement instruction matches the target timestamp. In this process, by constructing a balanced index tree using timestamps as nodes, the orderly organization and efficient retrieval of subtitle replacement instructions can be achieved. When it is necessary to adjust the subtitle content, the corresponding video frame can be quickly located based on the target timestamp to accurately complete the subtitle replacement operation, thereby significantly improving the flexibility and efficiency of subtitle replacement and ensuring that the replacement process is convenient, efficient, accurate, and controllable.

[0096] exist Figure 1 Based on the illustrated embodiment, the following, in conjunction with Figure 3 The above subtitle replacement method will be explained in further detail.

[0097] Figure 3 Flowchart of the subtitle replacement method provided in the embodiments of this application Figure 2 .like Figure 3 As shown, the method may include:

[0098] S301. Download the subtitle configuration file from the server via a secure transmission protocol.

[0099] Specifically, the server can generate corresponding subtitle configuration files according to actual business needs. These configuration files can include at least one subtitle replacement instruction. Electronic devices can establish communication with the server via a secure transmission protocol, initiate a download request for the subtitle configuration file, and download it from the server.

[0100] The server can refer to a server device with data storage, configuration file generation and network communication capabilities. It can generate at least one subtitle replacement instruction containing a display timestamp, original text and replacement text according to business scenario requirements (such as subtitle error correction, multilingual subtitle updates, advertising subtitle replacement, etc.), and integrate at least one subtitle replacement instruction into a subtitle configuration file.

[0101] Optionally, the subtitle replacement instruction may also include at least one of the following: replacement style, duration (frames), language encoding, and priority. The replacement style defines the display effect of the replacement text, and may specifically include parameters such as font size, font color, shadow, stroke, and color gradient to ensure the replacement text meets business display requirements. The duration (frames) determines the display length of the replacement text in the video, ensuring that the subtitle display is synchronized with the video playback rhythm and avoiding subtitles that are too short or too long. The language encoding adapts to subtitle display in different languages, supporting multilingual subtitle replacement to meet the viewing needs of different regions and users. The priority determines the execution order of multiple subtitle replacement instructions at the same timestamp, prioritizing instructions with higher priority to avoid replacement conflicts and ensure the orderly replacement of subtitles.

[0102] Optionally, the secure transmission protocol can be one or more of the following: Hypertext Transfer Protocol Secure (HTTPS), Secure File Transfer Protocol (SFTP), Secure Sockets Layer (SSL), and Transport Layer Security (TLS). These protocols are used to encrypt the communication content during data transmission, prevent data from being eavesdropped on, tampered with, or forged, and ensure the confidentiality and integrity of the subtitle configuration file transmitted between the server and the electronic device.

[0103] Optionally, during the download of subtitle configuration files via a secure transmission protocol, an incremental update mechanism based on HTTPETag and a resume function can also be supported. Specifically, when an electronic device initiates a download request, it can carry the ETag identifier of the locally cached subtitle configuration file. The server compares the ETag to determine if the subtitle configuration file has been updated. If not updated, it returns a corresponding status code informing the electronic device to directly use the local cache; if updated, it only transmits the changed content, effectively reducing the amount of duplicate data transmission and saving network bandwidth and download time. Simultaneously, the resume function can record the current download progress when the network is interrupted or download errors occur, and resume the download from the breakpoint after the network is restored, avoiding re-downloading completed parts of the file and improving the stability and efficiency of the subtitle configuration file download process.

[0104] Furthermore, during the download of subtitle configuration files, a priority queue can be generated based on actual needs. When multiple download requests exist simultaneously or multiple subtitle configuration files need to be downloaded, the priority queue can sort the download tasks based on factors such as the urgency of the subtitle configuration files, business importance, or user preferences, prioritizing the download of higher-priority subtitle configuration files. This ensures that, with limited network resources, the subtitle configuration file that best meets business expectations or user needs is obtained first, improving the overall efficiency and resource utilization of the download task.

[0105] S302. Perform signature verification on the subtitle configuration file. After successful verification, extract at least one subtitle replacement instruction from the subtitle configuration file.

[0106] After downloading the subtitle configuration file, it can be signed and verified to ensure its legitimacy and content integrity. Specifically, when generating the subtitle configuration file, the server can digitally sign the content using its private key and append the signature to the file. Upon receiving the subtitle configuration file, the electronic device can verify the signature using a pre-distributed public key from the server. If the verification passes, it indicates that the subtitle configuration file originated from a trusted server and has not been tampered with.

[0107] In one specific implementation, during the signature verification process, the electronic device can perform a hash calculation on the content of the subtitle configuration file to obtain the corresponding digest information. Then, it uses the public key to decrypt the signature and compares the decrypted digest with the calculated digest. If they match, the verification passes; if they do not match, it indicates that the subtitle configuration file may have been maliciously modified or damaged during transmission. In this case, the subtitle configuration file should be rejected, and the device can choose to re-download or use a locally cached backup subtitle configuration file to ensure the security and reliability of subsequent subtitle replacement operations.

[0108] Once verification is successful, the electronic device can parse and extract at least one required subtitle replacement instruction from the subtitle configuration file. Optionally, the subtitle configuration file is typically stored in a structured data format, such as JSON, XML, or Protocol Buffers, to facilitate data serialization and parsing. The electronic device can parse the configuration file according to predefined format specifications, extract the subtitle replacement instructions contained therein one by one, and store the extracted instructions in local memory or cache.

[0109] S303. Construct an initial binary search tree based on the display timestamp in at least one subtitle replacement instruction as a node.

[0110] After extracting at least one subtitle replacement instruction, an initial binary search tree can be constructed using the display timestamp in each subtitle replacement instruction as a node identifier.

[0111] In one specific implementation, each subtitle replacement instruction can be regarded as an independent node. The key value of the node is the display timestamp corresponding to the instruction, and the data associated with the node is the complete content of the instruction, including the original text, the replacement text, and optional replacement style, duration, language encoding, priority, and other additional information.

[0112] When constructing the initial binary search tree, the basic insertion rules of binary search trees are followed. That is, for any node in the tree, the value of all nodes in its left subtree is less than the value of that node, and the value of all nodes in its right subtree is greater than the value of that node.

[0113] Figure 4 This is a schematic diagram of an initial binary search tree structure provided in an embodiment of this application. Figure 4 As shown, this initial binary search tree is constructed using the display timestamp from at least one subtitle replacement instruction as nodes. The node with display timestamp 4500 is the root node, its left child is the node with display timestamp 2250, and its right child is the node with display timestamp 11250. In the left subtree of node 11250, a left child node 1 with display timestamp 6750 and a right child node 2 with display timestamp 9000 are further extended. In the right subtree of node 11250, a right child node 1 with display timestamp 13500 and a right child node 3 with display timestamp 15750 are successively extended. This initial binary search tree follows the basic ordering rule of binary search trees, that is, the value of all nodes in the left subtree is less than the root node, and the value of all nodes in the right subtree is greater than the root node.

[0114] In an optional implementation, before constructing the initial binary search tree, each subtitle replacement instruction can be format-validated to check the existence and expected types of necessary fields such as display timestamp, original text, and replacement text. If any instruction has missing fields or incorrect types, it is discarded and an exception is reported to ensure that the instruction data used to build the index are all valid instructions, thus avoiding subsequent retrieval errors due to data errors.

[0115] Furthermore, for instructions that pass verification, they can be written to a memory-mapped table in the form of "timestamp-record" key-value pairs, where the display timestamp is the key and the corresponding complete subtitle replacement instruction is the value. The memory-mapped table can quickly load instruction data into memory, providing efficient support for subsequent data access. After writing the memory-mapped table, an initial binary search tree is constructed using the display timestamp stored in the memory-mapped table as the node identifier, following the basic insertion rules of a binary search tree. Each node in the tree does not repeatedly store the complete instruction data; instead, it establishes an association with the key-value pair record in the memory-mapped table through pointers or references, ensuring data consistency.

[0116] S304. The initial binary search tree is balanced by left rotation and / or right rotation to obtain a balanced index tree.

[0117] Specifically, after constructing the initial binary search tree, the tree structure may become unbalanced due to different node insertion orders. For example, some branches may be too deep, leading to excessively long retrieval paths and affecting the efficiency of timestamp-based searches. Therefore, the initial binary search tree can be balanced using left and / or right rotation operations to transform it into a balanced index tree.

[0118] A left rotation involves using a given node as a pivot, promoting its right child to the new parent node, making the original node the left child of the new parent node, and simultaneously repositioning the new parent node's original left subtree into the original node's right subtree. A right rotation, conversely, uses a given node as a pivot, promoting its left child to the new parent node, making the original node the new parent node's right child, and simultaneously repositioning the new parent node's original right subtree into the original node's left subtree. Through these left and / or right rotations, the distribution of nodes can be adjusted without disrupting the ordered nature of the binary search tree, keeping the height difference between the left and right subtrees within a reasonable range.

[0119] For example, targeting Figure 4 The initial binary search tree shown has a deep right subtree, with nodes 11250, 13500, 15750, etc., extending from the right subtree of node 4500. This results in a long search path for this branch, affecting search efficiency. By adjusting the tree structure through appropriate left and / or right rotation operations, the tree structure can be optimized as follows: Figure 2 The balanced index tree shown.

[0120] S305. During video playback, obtain the target timestamp of the target frame, and search for the target subtitle replacement instruction based on the target timestamp and the balanced index tree.

[0121] During video playback, the electronic device can process video data frame by frame. Each frame parsed yields its corresponding display timestamp, which serves as the target timestamp. Based on this target timestamp, a search operation is performed within the constructed balanced index tree to determine if a subtitle replacement instruction matching that timestamp exists.

[0122] The specific search process is as follows: The root node of the balanced index tree is determined as the starting node. The target timestamp is compared with the display timestamp of the starting node. When the display timestamp of the starting node matches the target timestamp, the candidate subtitle replacement instruction corresponding to that starting node is determined as the target subtitle replacement instruction. If the target timestamp is greater than the display timestamp of the starting node, the right child node of the starting node is updated to the new starting node; if the target timestamp is less than the display timestamp of the starting node, the left child node of the starting node is updated to the new starting node. This comparison and node update process is repeated until the target subtitle replacement instruction is found.

[0123] In the above implementation, by using the root node of the balanced index tree as the starting node and comparing the target timestamp with the node display timestamp layer by layer, the subtitle replacement instruction matching the target frame can be quickly located. This search method fully utilizes the ordered and structurally balanced characteristics of the balanced index tree, eliminating half of the search range with each comparison, significantly improving search efficiency. Simultaneously, by iteratively updating the starting node, the accuracy and reliability of the search process can be ensured, providing precise instruction data support for subsequent subtitle replacement operations.

[0124] Optionally, the subtitle replacement instruction may also include a priority field to identify the importance of the instruction or the execution order. When multiple candidate subtitle replacement instructions correspond to the same starting node, the electronic device can obtain the priority information of each candidate instruction and select the instruction that meets the preset priority requirements from the multiple candidate instructions as the final target subtitle replacement instruction.

[0125] For example, if the same starting node corresponds to three candidate subtitle replacement instructions, their priorities are 10, 8, and 5, respectively. After obtaining the priority information of each candidate subtitle replacement instruction, the electronic device can filter them in descending order of priority and select the instruction with the highest priority (i.e., the instruction with priority 10) as the target subtitle replacement instruction.

[0126] In the above implementation, after finding the corresponding node based on the target timestamp, a priority mechanism is introduced to filter multiple candidate instructions. This ensures that when multiple replacement instructions exist at the same timestamp, the instructions with higher importance are executed first, avoiding display conflicts caused by multiple instructions taking effect at the same time and ensuring the uniqueness of the subtitle display results.

[0127] It should be noted that if multiple candidate subtitle replacement instructions have the same priority, the electronic device can further filter them by combining other parameters to determine the final target subtitle replacement instruction. For example, it can select based on the number of consecutive frames in the instruction, giving priority to instructions with a longer number of consecutive frames; it can also select based on the degree of matching between the language encoding and the current playback environment; or it can randomly select one as the target subtitle replacement instruction according to a preset random rule.

[0128] S306. If the original text in the target subtitle replacement instruction is the same as the original subtitle text in the target frame, then the original subtitle text is replaced with the replacement text in the target subtitle replacement instruction to generate the target subtitle.

[0129] Specifically, after locating the target subtitle replacement instruction, the electronic device can first extract the original text from the instruction and simultaneously obtain the original subtitle text of the target frame, comparing the two. If the comparison results match, it indicates that the subtitle content of the target frame is indeed the target content that needs to be replaced. In this case, the original subtitle text can be replaced with the replacement text in the target subtitle replacement instruction to generate the target subtitle.

[0130] In one specific implementation, the target subtitle replacement instruction may further include a replacement style corresponding to the replacement text. When subtitle replacement needs to be performed, a replacement event can be constructed, which contains the replacement text and its corresponding replacement style.

[0131] After a replacement event is constructed, the electronic device can push the replacement event to the rendering thread via a lock-free circular queue. Once the push is complete, the rendering thread can receive the replacement event and asynchronously generate the target subtitle containing the replacement text in the back buffer based on the replacement style contained in the event. The back buffer, as a background drawing area, can complete the preparation of the new subtitle without affecting the current screen display.

[0132] Optionally, during the construction and push of the replacement event, the following optimization method can be adopted for the specific processing mechanism after a successful search: The electronic device, as the main body for video playback, runs a player application internally. This player is responsible for core functions such as video data decoding, rendering, and output. The player contains a decoding thread and a rendering thread. The decoding thread is used to parse video data frame by frame and extract relevant time information, while the rendering thread is used to handle subtitle generation and image output tasks.

[0133] In each frame callback, after the decoding thread completes the search for the target timestamp based on the balanced index tree, if the target subtitle replacement instruction is matched, the replacement event construction process is triggered. To improve search accuracy, the decoding thread can convert the target timestamp into microseconds and compare it with the nodes in the balanced index tree. During the comparison process, a preset tolerance range (e.g., ±500 microseconds) is set to avoid missed matches caused by floating-point calculation errors.

[0134] After a target subtitle replacement instruction is hit, the decoding thread can construct a replacement event, which encapsulates the replacement text and its corresponding replacement style information. The replacement event can internally use smart pointers (such as std::shared_ptr) to manage memory, ensuring that the event is automatically released when passed between threads to prevent memory leaks.

[0135] Once constructed, the decoding thread can push replacement events to the rendering thread in the player via a lock-free circular queue. The lock-free circular queue is an efficient lock-free data structure for multi-threaded environments. Its core is a pre-allocated circular buffer, which uses read and write pointers to implement enqueue and dequeue operations.

[0136] In the subtitle replacement scenario, the decoding thread can quickly push the constructed replacement event to a lock-free circular queue, while the rendering thread reads the replacement event from the other end of the queue and asynchronously generates the target subtitle containing the replacement text in the back buffer according to the replacement style. Since the read and write operations do not interfere with each other and do not require waiting for the lock to be released, the push time can be controlled at the microsecond level, ensuring that the subtitle replacement process does not block the video decoding and rendering process, thus guaranteeing smooth playback.

[0137] In the above implementation, by constructing a replacement event containing the replacement text and corresponding replacement style, all the information required for subtitle replacement can be uniformly encapsulated, ensuring that the relevant data can be accurately and completely transmitted to subsequent processing stages. Pushing the encapsulated replacement event to the rendering thread through a lock-free circular queue decouples the replacement logic from the rendering logic, avoiding blocking issues caused by lock contention between threads, thereby improving the processing efficiency of subtitle replacement.

[0138] Optionally, to further optimize search performance, the electronic device can perform a cache preheating process on the balanced index tree after its construction is complete. In specific implementation, the electronic device can preload the first few subtitle replacement instruction records (e.g., the first 10) into the L1 cache of its central processing unit, so that the player can complete the retrieval of the target timestamp at a very fast speed in the early stage of video playback, reducing the response latency of the first frame subtitle replacement.

[0139] Optionally, for target frames that do not match the target subtitle replacement instruction, the decoding thread can perform no additional operations, and the player can directly follow the original subtitle rendering path, ensuring that the smoothness of video playback is not affected while guaranteeing zero resource overhead.

[0140] S307. When the video plays to the target frame, display the target subtitle.

[0141] Specifically, electronic devices can trigger a subtitle display operation when the video plays to the target frame, switching the target subtitles prepared in the back buffer to the foreground for display.

[0142] In one specific implementation, the rendering thread in the electronic device can employ a double-buffered texture scheme for subtitle display. The rendering thread maintains two display areas: a front buffer and a back buffer. The front buffer stores the currently displayed subtitle in the current frame, while the back buffer asynchronously generates the target subtitle to be displayed. When the video plays to the target frame, the pointers to the front and back buffers can be swapped, and the target subtitle is refreshed and output. The target frame is located after the current frame.

[0143] By swapping pointers, the target subtitles originally stored in the back buffer become the new front buffer content and are immediately displayed on the screen, while the original front buffer is converted to the back buffer. This process only involves updating memory addresses and does not involve copying or re-rendering actual data, so it can be completed in a very short time, achieving flicker-free subtitle output.

[0144] In the above implementation, the target subtitle is refreshed and output by swapping the pointers of the pre-buffer and post-buffer. This allows for subtitle switching to be completed in a very short time, effectively avoiding stuttering, flickering, and other abnormal phenomena that may occur during subtitle replacement. The division of labor between the pre-buffer and post-buffer ensures that the display and preparation of subtitles do not interfere with each other, guaranteeing that the target subtitle can be displayed precisely and synchronously with the target frame. This significantly improves the stability of subtitle display and provides users with a smoother and more comfortable viewing experience.

[0145] Optionally, during the subtitle display process, the electronic device can also record a subtitle replacement log for subsequent auditing or rollback operations. Each time a subtitle replacement is performed, relevant information about the replacement event (such as the target timestamp of the target frame, the original text, the replacement text, the replacement style, etc.) can be recorded in an encrypted log. When it is necessary to trace the subtitle replacement history or restore the state before the replacement in case of an anomaly, single-point rollback can be achieved by parsing the log, improving the reliability and maintainability of the subtitle replacement mechanism.

[0146] In this embodiment, a subtitle configuration file can be downloaded from the server via a secure transmission protocol, and the configuration file is signed and verified. Upon successful verification, at least one subtitle replacement instruction is extracted. An initial binary search tree is constructed using the display timestamps in each subtitle replacement instruction as nodes. The initial binary search tree is then balanced using left and / or right rotation operations to obtain a balanced index tree. During video playback, the target timestamp of the target frame is obtained, and the target subtitle replacement instruction is searched based on the target timestamp and the balanced index tree. If the original text in the target subtitle replacement instruction matches the original subtitle text of the target frame, a replacement event containing the replacement text and corresponding replacement style is constructed and pushed to the rendering thread via a lock-free circular queue. The target subtitle is then generated asynchronously in the back buffer. When the video reaches the target frame, the pointers of the front and back buffers are swapped, and the target subtitle is refreshed and output. In the above process, a balanced index tree is constructed using the displayed timestamp as a node, which enables rapid and accurate positioning of subtitle replacement instructions. This allows adjustments to subtitle content to be made without recreating the video file; replacement can be completed simply based on the target timestamp, significantly shortening the response time. At the same time, efficient thread communication is achieved through a lock-free circular queue, combined with a double buffering mechanism to achieve flicker-free subtitle refresh output, effectively ensuring smooth and stable subtitle switching. This significantly improves the flexibility of subtitle replacement, enabling it to easily meet diverse needs such as multilingual switching and real-time updates.

[0147] Furthermore, the subtitle replacement method provided in this application embodiment, through secure transmission and signature verification, can ensure the security and integrity of the subtitle configuration file transmission and parsing, and prevent the configuration from being illegally tampered with.

[0148] Figure 5 This is a flowchart illustrating an example of the subtitle replacement method provided in this application. Figure 5 As shown, the method includes:

[0149] S501. Generate a subtitle configuration file based on business requirements.

[0150] Specifically, the server can generate corresponding subtitle configuration files based on actual business needs, such as subtitle error correction, multi-language version adaptation, advertising insertion, or personalized content insertion. Each subtitle configuration file includes at least one subtitle replacement instruction, and each instruction includes, but is not limited to, displaying a timestamp, the original text, and the replacement text.

[0151] S502. Download the subtitle configuration file via a secure transmission protocol.

[0152] Specifically, electronic devices can establish communication with the server through secure transmission protocols (such as HTTPS, SFTP, etc.) and download subtitle configuration files from the server.

[0153] S503: Parse the subtitle configuration file and generate a balanced index tree.

[0154] Specifically, the electronic device can verify the signature of the downloaded subtitle configuration file to confirm its legitimate source and that its content has not been tampered with. After successful verification, at least one subtitle replacement instruction is extracted from the configuration file. Using the display timestamp in each instruction as a node, an initial binary search tree is constructed according to the basic insertion rules of a binary search tree. Then, the initial tree is balanced through left rotation and / or right rotation operations to finally generate a structurally balanced index tree.

[0155] In one optional implementation, the aforementioned balanced index tree can be implemented using a red-black tree structure. As a self-balancing binary search tree, a red-black tree automatically maintains its balance through color changes and rotations after inserting or deleting nodes by assigning each node a red or black label and following specific coloring rules. Compared to other balanced tree structures, the red-black tree's balancing strategy is relatively efficient, reducing maintenance overhead while maintaining retrieval performance. Therefore, implementing the balanced index tree as a red-black tree can further optimize the dynamic adjustment efficiency of the tree and improve the search performance of subtitle replacement instructions, while ensuring fast timestamp-based retrieval.

[0156] S504: Based on the balanced index tree, find the target subtitle replacement instruction in real time and trigger the replacement event.

[0157] Specifically, during video playback, the target timestamp of the target frame can be obtained and searched in the balanced index tree to determine the target subtitle replacement instruction that matches the target timestamp. If multiple candidate instructions are found, the final target subtitle replacement instruction is selected according to priority, and a replacement event containing the replacement text and corresponding replacement style is constructed.

[0158] S505 asynchronously generates target subtitles and achieves flicker-free refresh output.

[0159] Specifically, replacement events can be pushed to the rendering thread via a lock-free circular queue. The rendering thread then asynchronously generates the target subtitle in the back buffer based on the replacement style. When the video plays to the target frame, the pointers of the front and back buffers are swapped to achieve flicker-free refresh output of the target subtitle.

[0160] The subtitle replacement method provided in this application example, the specific implementation details of each step can be referred to the content of the foregoing embodiment, the implementation principle and beneficial effects are similar, and will not be repeated here.

[0161] Figure 6 This is a schematic diagram of the subtitle replacement device provided in an embodiment of this application. Figure 6 As shown, the subtitle replacement device 600 provided in this embodiment includes:

[0162] The first processing module 601 is used to build a balanced index tree with timestamps as nodes based on at least one pre-acquired subtitle replacement instruction. The subtitle replacement instruction includes a display timestamp, the original text, and the replacement text.

[0163] The lookup module 602 is used to obtain the target timestamp of the target frame during video playback, and to look up the target subtitle replacement instruction based on the target timestamp and the balanced index tree, wherein the display timestamp in the target subtitle replacement instruction is consistent with the target timestamp;

[0164] The second processing module 603 is used to replace the original subtitle text with the replacement text in the target subtitle replacement instruction if the original text in the target subtitle replacement instruction is consistent with the original subtitle text in the target frame, and generate the target subtitle.

[0165] Display module 604 is used to display target subtitles when the video plays to the target frame.

[0166] Furthermore, the first processing module 601 is specifically used for:

[0167] Construct an initial binary search tree based on the display timestamp in at least one subtitle replacement instruction as a node;

[0168] The initial binary search tree is balanced by left and / or right rotation operations to obtain a balanced index tree.

[0169] Furthermore, the lookup module 602 is specifically used for:

[0170] The root node of the balanced index tree is determined as the starting node, and the target timestamp is compared with the display timestamp of the starting node;

[0171] When the display timestamp of the starting node matches the target timestamp, the candidate subtitle replacement instruction corresponding to the starting node is determined as the target subtitle replacement instruction;

[0172] If the target timestamp is greater than the display timestamp of the starting node, then the right child node of the starting node will be updated to the new starting node; if the target timestamp is less than the display timestamp of the starting node, then the left child node of the starting node will be updated to the new starting node.

[0173] Repeat the above process until the target subtitle replacement instruction is found.

[0174] Furthermore, the subtitle replacement instruction also includes a priority lookup module 602, specifically used for:

[0175] If the starting node corresponds to multiple candidate subtitle replacement instructions, then obtain the priority of the multiple candidate subtitle replacement instructions;

[0176] Based on priority, select the candidate subtitle replacement instruction with the preset priority from multiple candidate subtitle replacement instructions as the target subtitle replacement instruction.

[0177] Furthermore, the first processing module 601 is also used for:

[0178] Download the subtitle configuration file from the server using a secure transmission protocol;

[0179] The signature of the subtitle configuration file is verified. Once the verification is successful, at least one subtitle replacement instruction is extracted from the subtitle configuration file.

[0180] Furthermore, the subtitle replacement instruction also includes the replacement style corresponding to the replacement text. The second processing module 603 is specifically used for:

[0181] Construct a replacement event, which includes the replacement text and the corresponding replacement style;

[0182] Replacement events are pushed to the rendering thread via a lock-free circular queue, allowing the rendering thread to asynchronously generate target captions, including the replacement text, in the back buffer based on the replacement style.

[0183] Furthermore, the display module 604 is specifically used for:

[0184] When the video plays to the target frame, the pointers of the pre-buffer and post-buffer are swapped, and the target subtitle is refreshed and output. The pre-buffer is used to store the current subtitle corresponding to the current frame, and the target frame is located after the current frame.

[0185] Furthermore, the display module 604 is also used for:

[0186] If the target subtitle replacement instruction is not found based on the target timestamp and the balanced index tree, the original subtitle text of the target frame will be displayed when the video plays to the target frame.

[0187] The subtitle replacement device provided in this embodiment can execute the method provided in the above method embodiment. Its implementation principle and technical effect are similar, and will not be described in detail here.

[0188] Figure 7 This is a schematic diagram of the structure of an electronic device provided in an embodiment of this application. Figure 7 As shown, the electronic device 700 provided in this embodiment can be a multimedia controller, cockpit domain controller, or driving domain controller in a vehicle, and this application does not limit it.

[0189] The electronic device 700 provided in this embodiment includes at least one processor 701 and a memory 702. Optionally, the device 700 further includes a communication component 704. The processor 701, memory 702, and communication component 704 are connected via a bus 703.

[0190] In the specific implementation process, at least one processor 701 executes computer execution instructions stored in memory 702, causing at least one processor 701 to execute the above-mentioned subtitle replacement method.

[0191] The specific implementation process of processor 701 can be found in the above method embodiments, and its implementation principle and technical effect are similar. It will not be repeated here.

[0192] In the above embodiments, it should be understood that the processor can be a Central Processing Unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), etc. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the method disclosed in this invention can be directly implemented by a hardware processor, or implemented by a combination of hardware and software modules within the processor.

[0193] The memory may include random access memory (RAM) and may also include non-volatile memory (NVM), such as at least one disk storage device.

[0194] The bus can be an Industry Standard Architecture (ISA) bus, a Peripheral Component Interconnect (PCI) bus, or an Extended Industry Standard Architecture (EISA) bus, etc. Buses can be categorized as address buses, data buses, control buses, etc. For ease of illustration, the buses shown in the accompanying drawings are not limited to a single bus or a single type of bus.

[0195] This application also provides a computer program product, including a computer program that, when executed by a processor, implements the above-described method.

[0196] This application also provides a computer-readable storage medium storing computer-executable instructions, which, when executed by a processor, implement the above-described method.

[0197] The aforementioned readable storage medium can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk. The readable storage medium can be any available medium accessible to a general-purpose or special-purpose computer.

[0198] An exemplary readable storage medium is coupled to a processor, enabling the processor to read information from and write information to the readable storage medium. Of course, the readable storage medium can also be a component of the processor. The processor and the readable storage medium can reside in an Application Specific Integrated Circuit (ASIC). Alternatively, the processor and the readable storage medium can exist as discrete components in the device.

[0199] The division of units is merely a logical functional division; in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be indirect coupling or communication connection through some interfaces, devices, or units, and may be electrical, mechanical, or other forms.

[0200] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.

[0201] In addition, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit.

[0202] 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.

[0203] Those skilled in the art will understand that all or part of the steps of the above-described method embodiments can be implemented by hardware related to program instructions. The aforementioned program can be stored in a computer-readable storage medium. When executed, the program performs the steps of the above-described method embodiments. The aforementioned storage medium includes various media capable of storing program code, such as ROM, RAM, magnetic disks, or optical disks.

[0204] Finally, it should be noted that other embodiments of the invention will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This invention is intended to cover any variations, uses, or adaptations of the invention that follow the general principles of the invention and include common knowledge or customary techniques in the art not disclosed herein, and is not limited to the precise structures described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of the invention is limited only by the appended claims.

[0205] The above embodiments are merely preferred embodiments provided to fully illustrate the present invention, and the scope of protection of the present invention is not limited thereto. Equivalent substitutions or modifications made by those skilled in the art based on the present invention are all within the scope of protection of the present invention.

Claims

1. A method for replacing subtitles, characterized in that, include: Based on at least one pre-acquired subtitle replacement instruction, a balanced index tree is built with timestamps as nodes. The subtitle replacement instruction includes a display timestamp, the original text, and the replacement text. During video playback, the target timestamp of the target frame is obtained, and based on the target timestamp and the balanced index tree, the target subtitle replacement instruction is found, wherein the display timestamp in the target subtitle replacement instruction is consistent with the target timestamp; If the original text in the target subtitle replacement instruction is consistent with the original subtitle text of the target frame, then the original subtitle text is replaced with the replacement text in the target subtitle replacement instruction to generate the target subtitle; When the video plays to the target frame, the target subtitle is displayed.

2. The method according to claim 1, characterized in that, The step of building a balanced index tree based on at least one pre-acquired subtitle replacement instruction, using timestamps as nodes, includes: Construct an initial binary search tree based on the display timestamp in the at least one subtitle replacement instruction as a node; The initial binary search tree is balanced by left and / or right rotation operations to obtain the balanced index tree.

3. The method according to claim 1, characterized in that, The process of finding the target subtitle replacement instruction based on the target timestamp and the balanced index tree includes: The root node of the balanced index tree is determined as the starting node, and the target timestamp is compared with the display timestamp of the starting node; When the display timestamp of the starting node is consistent with the target timestamp, the candidate subtitle replacement instruction corresponding to the starting node is determined as the target subtitle replacement instruction; If the target timestamp is greater than the display timestamp of the starting node, then the right child node of the starting node is updated to the new starting node; if the target timestamp is less than the display timestamp of the starting node, then the left child node of the starting node is updated to the new starting node. Repeat the above process until the target subtitle replacement instruction is found.

4. The method according to claim 3, characterized in that, The subtitle replacement instruction also includes a priority, and determining the candidate subtitle replacement instruction corresponding to the starting node as the target subtitle replacement instruction includes: If the starting node corresponds to multiple candidate subtitle replacement instructions, then the priority of the multiple candidate subtitle replacement instructions is obtained; Based on the priority, the candidate subtitle replacement instruction with a preset priority is selected from the multiple candidate subtitle replacement instructions as the target subtitle replacement instruction.

5. The method according to any one of claims 1-4, characterized in that, Before building a balanced index tree based on at least one pre-acquired subtitle replacement instruction, using timestamps as nodes, the method further includes: Download the subtitle configuration file from the server using a secure transmission protocol; The signature of the subtitle configuration file is verified, and if the verification is successful, the at least one subtitle replacement instruction is extracted from the subtitle configuration file.

6. The method according to any one of claims 1-4, characterized in that, The subtitle replacement instruction also includes a replacement style corresponding to the replacement text. If the original text in the target subtitle replacement instruction is consistent with the original subtitle text of the target frame, then the original subtitle text is replaced with the replacement text in the target subtitle replacement instruction to generate the target subtitle, including: Construct a replacement event, the replacement event including the replacement text and the replacement style corresponding to the replacement text; The replacement event is pushed to the rendering thread via a lock-free circular queue, so that the rendering thread asynchronously generates a target caption including the replacement text in the back buffer according to the replacement style.

7. The method according to claim 6, characterized in that, The step of displaying the target subtitle when the video plays to the target frame includes: When the video plays to the target frame, the pointers of the front buffer and the back buffer are swapped, and the target subtitle is refreshed and output. The front buffer is used to store the current subtitle corresponding to the current frame, and the target frame is located after the current frame.

8. The method according to any one of claims 1-4, characterized in that, The method further includes: If the target subtitle replacement instruction is not found based on the target timestamp and the balanced index tree, the original subtitle text of the target frame will be displayed when the video is played to the target frame.

9. A subtitle replacement device, characterized in that, include: The first processing module is used to build a balanced index tree with timestamps as nodes based on at least one pre-acquired subtitle replacement instruction. The subtitle replacement instruction includes a display timestamp, the original text, and the replacement text. The lookup module is used to obtain the target timestamp of the target frame during video playback, and to look up the target subtitle replacement instruction based on the target timestamp and the balanced index tree, wherein the display timestamp in the target subtitle replacement instruction is consistent with the target timestamp; The second processing module is used to replace the original subtitle text with the replacement text in the target subtitle replacement instruction if the original text in the target subtitle replacement instruction is consistent with the original subtitle text of the target frame, thereby generating the target subtitle; The display module is used to display the target subtitle when the video is played to the target frame.

10. An electronic device, characterized in that, include: Memory, processor; The memory stores computer-executed instructions; The processor executes computer execution instructions stored in the memory, causing the processor to perform the method as described in any one of claims 1-8.

11. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions, which, when executed by a processor, are used to implement the method as described in any one of claims 1-8.

12. A computer program product, characterized in that, Includes a computer program that, when executed by a processor, implements the method described in any one of claims 1-8.