Audio-visual data synchronization method and related product
By adjusting the playback speed and display strategy of visual data, the problem of audio and visual data being out of sync in multi-player scenarios is solved, synchronous playback of audio-visual data is achieved, buffering and lags are avoided, and user experience is improved.
Patent Information
- Application Number
- CN202410717130.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-06-04
- Publication Date
- 2024-09-03
AI Technical Summary
In complex scenarios where multiple players play at the same time, the playback progress of audio and visual data is easily out of sync, resulting in buffering, freezing, and black screens, which affects the user experience.
By obtaining the playback progress of the audio data, adjust the playback speed of the visual data or perform display processing to synchronize it with the audio data, including double-speed playback and display strategies, such as discarding or delaying the display frame fragments, to ensure that the visual data is consistent with the audio Data synchronization.
There is no need to pause the player, reducing progress buffering or lagging, enabling synchronous playback of audio-visual data and improving user experience.
Smart Images

Figure CN118590693A
Abstract
Description
Technical Field
[0001] The embodiments of the present application relate to the field of audio technology, and in particular to an audio-visual data synchronization method and related products. Background Art
[0002] As information playback technology matures, users can simultaneously experience audio and video through terminals, such as recording or playing at least two of the following data: audio, video, and lyrics (the latter two can be collectively referred to as visual data). However, audio data and visual data are usually independent of each other, so they need to be recorded and played through different players. For example, when a song is played through the terminal's audio player, a song video (MV, Music Video) related to the song is played through the terminal's video player, and lyrics of a certain style can be rendered through the terminal's lyrics player.
[0003] However, the architecture implemented by each player is different. During the recording and playback process, problems such as decoding or network transmission may cause the playback progress of each player to be out of sync, resulting in a combination of asynchronous audio and video data, such as currently playing a certain audio segment, but at the same time showing the frame fragments or lyrics corresponding to other audio segments. In order to allow each player to maintain synchronous playback, the existing method is to use a detection device to regularly detect the playback time of each player. If a problem of asynchronous progress is found, such as the playback time of any player exceeds a threshold, all players need to be paused, and each player needs to be searched (Seek) in turn to find the playback position of the audio and video synchronization in each player.
[0004] In a complex scenario where multiple players are playing at the same time (which can be referred to as a multiple player scenario), in order to synchronize the playback progress between the data, all players are paused and the Seek action is performed multiple times. This can easily cause buffering progress, freezes, or black screens, thereby causing new synchronization issues. It is difficult to achieve the ideal data synchronization playback effect, affecting the user experience. Summary of the invention
[0005] The audio-visual data synchronization method and related products provided in the embodiments of the present application provide a variety of data synchronization strategies based on the idea of "chasing" audio progress to meet the needs of synchronous playback of different types of visual data and audio data in complex scenarios of multiple players.
[0006] The first aspect of the embodiments of the present application provides an audio-visual data synchronization method and related products, including:
[0007] Acquire at least one type of visual data that is not synchronized with the audio playback progress of the audio data; the audio data is processed and played by an audio player, and the at least one type of visual data is processed and played by at least one visual player;
[0008] If it is determined that the visual player does not support processing frame segments in the visual data based on the audio playback progress, the playback speed of the audio data is kept unchanged, and based on the time difference between the audio data and the visual data, the target speed and the visual segments in the visual data that will be played at the target speed are determined, so that the visual data as a whole is played synchronously with the audio data because the visual segments are played at the target speed.
[0009] Optionally, after acquiring at least one type of visual data that is not synchronized with the audio playback progress of the audio data, the method further includes:
[0010] If it is determined that the visual player supports processing frame fragments in the visual data based on the audio playback progress, the visual player is adjusted to display some frame fragments in the visual data based on the audio playback progress, so that the processed visual data is played synchronously with the audio data.
[0011] Optionally, the performing display processing on some frame segments in the visual data includes:
[0012] Obtaining a display threshold and a frame loss threshold determined based on the audio playback progress; the display threshold indicates a time difference that a frame segment in the visual data is allowed to be played later than a corresponding audio segment in the audio data;
[0013] For each frame segment in the visual data, determine the comparison result of the display time of the frame segment with the display threshold or the frame loss threshold, and process the frame segment according to the display strategy corresponding to the comparison result; the display strategy includes display, discard or delayed display.
[0014] Optionally, the processing the frame fragments according to the display strategy corresponding to the comparison result includes:
[0015] If the display time of the frame segment is within the positive and negative range of the display threshold, the frame segment is displayed normally;
[0016] If the display time of the frame segment is less than the display threshold, or the display time of the frame segment is greater than or equal to the frame loss threshold, discard the frame segment or the adaptation frame related to the frame segment;
[0017] If the display time of the frame segment is within the interval formed by the display threshold and the frame loss threshold, the sleep time of the frame segment is determined, and the frame segment is normally displayed until the sleep time ends.
[0018] Optionally, determining the sleep time of the frame segment includes:
[0019] The dormancy time of the frame segment is determined based on the audio and video time difference and the normal decoding time of the frame segment by the video player; the audio and video time difference refers to the playback time difference between the frame segment and the audio segment of the corresponding content.
[0020] Optionally, if it is determined that the visual player does not support processing frame segments in the visual data based on the audio playback progress, the method further includes:
[0021] If the visual data is in a paused state, the visual data is restored to a playback state of being played at an initial speed; at least part of the visual segments in the visual data after the playback is restored will be adjusted to the target speed for playback.
[0022] Optionally, the step of regulating the visual player to display some frame segments in the visual data based on the audio playback progress includes:
[0023] Selecting a resource player; the resource player is one of the at least one visual player or other players, and the resource player supports accessing and regulating the at least one visual player;
[0024] Based on the audio playback progress associated with the resource player and the class information inherited by the resource player, the at least one visual player is substituted to perform display processing on at least one frame segment of the played visual data, so that the processed visual data is played synchronously with the audio data.
[0025] Optionally, if the distribution position of the end of the visual segment in the visual data is after a preset position, the method further includes:
[0026] Obtaining a position difference between the distribution position and the preset position;
[0027] The distribution position is retracted at least by the position gap to obtain a new visual segment whose terminal distribution position is prior to or equal to the preset position, and the new visual segment will be adjusted to play at the target speed.
[0028] Optionally, after determining a target speed and a visual segment in the visual data to be played at the target speed according to the time difference between the audio data and the visual data, the method further comprises:
[0029] For the remaining segments played at the initial multiple speed of the visual data, detecting whether the remaining segments are played synchronously with the audio playback progress; the remaining segments are segments of the visual data after the visual segments;
[0030] If not synchronized, mark the abnormal segment in the remaining segments that is not synchronized with the audio playback progress, and obtain the time difference generated by the abnormal segment; determine the next target speed and the visual segment in the abnormal segment to be played at the next target speed according to the time difference; the time difference is the difference between the time information of the abnormal segment and the time information of the corresponding audio segment, and the next target speed is used to reduce the time difference;
[0031] If the time difference is greater than the preset difference, the segment after the most recently determined visual segment is taken as the next remaining segment, and the process returns to the step of detecting whether the remaining segment is played in sync with the audio playback progress, until the most recently obtained time difference is less than or equal to the preset difference.
[0032] The method described in the first aspect of the present application can be implemented by using the content described in the second aspect of the present application during specific implementation.
[0033] A second aspect of an embodiment of the present application provides an electronic device, including: a processor and a memory;
[0034] The processor is configured to communicate with the memory and execute instructions in the memory to implement the method described in the first aspect of the embodiment of the present application or any specific implementation of the first aspect.
[0035] A third aspect of an embodiment of the present application provides a computer-readable storage medium, which stores computer instructions. When the computer instructions are executed by a processor, they implement the method described in the first aspect of the embodiment of the present application or any specific implementation of the first aspect.
[0036] A fourth aspect of an embodiment of the present application provides a computer program product, which includes computer instructions. When the computer instructions are executed by a processor, they implement the method described in the first aspect of the embodiment of the present application or any specific implementation of the first aspect.
[0037] It can be seen from the above technical solutions that the embodiments of the present application have at least the following advantages:
[0038] Faced with the complex scenario of multiple players playing various types of data such as audio and video at the same time, the embodiment of the present application provides strategies for different visual players based on the idea of aligning the audio playback progress, including playing the visual data at double speed, so that the playback progress of each visual player can be synchronized with the audio playback progress. Among them, in the process of synchronizing the progress of visual data, the embodiment of the present application does not need to pause each player, which effectively reduces the operation time when there are many players, and the possible progress buffer delay or jamming, so as to avoid causing new synchronization problems and ensure the user's audio-visual dual experience. BRIEF DESCRIPTION OF THE DRAWINGS
[0039] In order to more clearly illustrate the technical solutions in the embodiments of the present application, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in the present application. For ordinary technicians in this field, other drawings can also be obtained based on these drawings.
[0040] It should be noted that, although the steps in the process diagrams (if any) involved in the embodiments are drawn in sequence as indicated by the arrows, unless otherwise specified herein, there is no strict order restriction on the execution of these steps, and these steps can be executed in other orders. Moreover, at least a portion of the steps in the flowcharts involved in the embodiments may include multiple steps or multiple stages, and these steps or stages are not necessarily executed at the same time, but can be executed at different times, and the execution order of these steps or stages is not necessarily sequential, but can be executed in turn or alternately with other steps or at least a portion of the steps or stages in other steps.
[0041] Figure 1 A schematic diagram of the architecture of the audio-visual data synchronization method according to an embodiment of the present application;
[0042] Figure 2.1 , Figure 2.2 A flowchart of the audio-visual data synchronization method according to an embodiment of the present application;
[0043] Figure 3 , Figure 4 A player assembly architecture diagram of the audio-visual data synchronization method according to an embodiment of the present application;
[0044] Figure 5 This is another flowchart of the audio-visual data synchronization method according to an embodiment of the present application;
[0045] Figure 6 A schematic diagram of the synchronization effect of the audio-visual data synchronization method according to an embodiment of the present application;
[0046] Figure 7 A schematic diagram of the structure of an electronic device according to an embodiment of the present application. DETAILED DESCRIPTION
[0047] In order to make the purpose, technical solutions and advantages of the present application clearer, the present application will be further described in detail below in conjunction with the accompanying drawings. The described embodiments should not be regarded as limiting the present application. All other embodiments obtained by ordinary technicians in the field without making creative work are within the scope of protection of this application.
[0048] The terms "first", "second", "third", "fourth", etc. (if any) in the specification and claims and drawings of the present application are used to distinguish similar objects, and are not necessarily used to describe a specific order or sequence. It should be understood that the data used in this way can be interchangeable where appropriate, so that the embodiments described herein can be implemented in an order other than that illustrated or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusions, for example, a process, method, system, product or device that includes a series of steps or units is not necessarily limited to those steps or units that are clearly listed, but may include other steps or units that are not clearly listed or inherent to these processes, methods, products or devices.
[0049] In the following description, similar expressions such as "a specific implementation" or "a specific example" are involved, which describe a subset of all possible embodiments, but it can be understood that "a specific implementation" or "a specific example" can be the same subset or different subsets of all possible embodiments, and can be combined with each other without conflict. In the following description, the term multiple refers to at least two. In some specific examples, the numerical value mentioned in this application reaches the threshold value (if any), which may include the case where the former is greater than the latter of the threshold value; if similar expressions such as "any" or "at least one" are mentioned, it can specifically refer to any one of the listed examples or any combination of these examples.
[0050] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art to which this application belongs. The terms used herein are only for the purpose of describing the embodiments of this application and are not intended to limit this application.
[0051] To facilitate understanding and explanation, before further detailed description of the present application, the nouns and terms involved in the embodiments of the present application will be explained, and the nouns and terms involved in the embodiments of the present application are subject to the following explanations.
[0052] The method provided in the embodiment of the present application can be applied to Figure 1 In the application environment shown, the terminal 102 communicates with the server 101 through the network, and the data storage system 100 can store the data that the server 101 needs to process. The data storage system 100 can be integrated on the server 101, or it can be placed on the cloud or other network servers. The terminal 102 can be, but is not limited to, various personal computers, laptops, smart phones, tablet computers and portable wearable devices. The portable wearable device can be a smart watch, a smart bracelet, a head-mounted device, etc. The server 101 can be implemented as an independent server or a server cluster consisting of multiple servers.
[0053] Terminal 102 can obtain audio data and at least one type of visual data input by the user, and send the audio data and visual data to server 101. If the audio playback progress of the visual data is not synchronized with the audio data, server 101 can determine whether the visual player used to process and play the visual data supports it, and process the frame segments in the visual data based on the audio playback progress information; if supported, server 101 can control the visual player to send and display some frame segments in the visual data based on the audio playback progress information, so that the visual data finally received by terminal 102 can be played synchronously with the audio data. If not supported, server 101 can keep the playback speed of the audio data unchanged, and determine the target speed and the visual segments in the visual data that will be played at the target speed based on the time difference between the audio data and the visual data, so that the entire visual data is played synchronously with the audio data because the visual segments are played at the speed.
[0054] It should be noted that the method provided in the embodiment of the present application can be implemented jointly by the terminal device and the server as described above, or it can be implemented entirely on the server side, or it can be implemented entirely on the terminal device side. The specific method can be determined according to the actual application scenario and is not limited here.
[0055] The method of the present application will be described in further detail below.
[0056] See also Figure 2.1 In a first aspect, the present application provides a specific embodiment of an audio-visual data synchronization method, which includes the following operation steps:
[0057] Step 211: Acquire at least one type of visual data that is not synchronized with the audio playback progress of the audio data.
[0058] The audio data is processed and played by an audio player, and at least one type of visual data is processed and played by at least one visual player.
[0059] like Figure 3As shown in the figure, each player Player (or renderer Render) can be divided into audio renderer (AudioRender), video renderer (VideoRender) and effect renderer (EffectRender). Taking the singing (K song) scene as an example, AudioRender is an audio renderer in the K song software that plays music and realizes the recording function; VideoRender is a video renderer responsible for MV resource playback in the K song software, mainly ijkPlayer, MediaPlayer, ExoPlayer and ffpayer; EffectRender is a visual renderer responsible for special effect playback in the K song software, mainly PagePlayer (page player) and AlphaPlayer (animation player).
[0060] like Figure 4 As shown, in the karaoke software architecture, there are generally multiple players playing at the same time. For example, audio players such as "KSingPlayer (recording player) or AudioPlayer" are combined with at least one visual player among "ExoPlayer, MediaPlayer, iJkPlayer, PagPlayer, AlphaPlayer, LyricPlayer, MIDIPlayer, ScorePlayer" for playing. The reason for this combination is that on different devices (TV, song request machine, car equipment, mobile phone, Internet of Things IOT device, etc.), using a certain player may have compatibility problems or performance problems. Therefore, this combination can effectively solve such problems. In this multi-player scenario with multiple players, since the players are isolated from each other, and at the same time each player automatically plays content data (such as audio, video, lyrics and other data streams) according to its own clock, it is easy to have the problem of asynchronous playback progress. Therefore, it is necessary to provide an audio-visual data synchronization method so that when at least one visual player and an audio player (such as KSingPlayer or AudioPlayer) play data simultaneously, each player can maintain a playback clock progress synchronized with the audio player, that is, follow or align the clock mechanism of the audio player (or playback clock synchronization) to ensure that the data streams played by each player remain synchronized, such as audio and video synchronization.
[0061] It should be supplemented that the above-mentioned multi-player scenario: a scenario where multiple or multiple players are playing at the same time, such as a karaoke player, an MV player, and a special effects player are playing at the same time. Audio and video synchronization: refers to the strict correspondence between each frame of the video player rendering and each sound being played by the audio player, and there is no audio-visual deviation that can be distinguished by the human ear and naked eye, such as the phenomenon that the lip shape of the characters on the screen does not correspond to the audio expression. Playback clock synchronization: refers to achieving synchronization of the playback clocks between multiple players, such as synchronizing the playback speed between audio and video, and aligning the timestamps of audio and video to ensure that the audio and video play the corresponding frames at the same time point. KSingPlayer: A player in the karaoke software that implements the core functions of karaoke, such as original accompaniment switching, recording, microphone hardware detection, intelligent accompaniment, and work preservation.
[0062] Step 212: If it is determined that the visual player does not support processing frame segments in the visual data based on the audio playback progress, the playback speed of the audio data is kept unchanged, and the visual segments in the visual data are speed-varied so that the entire visual data is played synchronously with the audio data because the visual segments are played at double the speed.
[0063] Step 212 can be referred to as a variable speed synchronization strategy. Specifically, if the visual player does not support processing frame segments in the visual data based on the audio playback progress information, the playback speed of the audio data is kept unchanged, and the target speed and the visual segments in the visual data that will be played at the target speed (such as speeding up or slowing down) are determined based on the time difference between the audio data and the visual data, so that the entire visual data is played synchronously with the audio data because the visual segments are played at a double speed.
[0064] In summary, in the face of complex scenarios where multiple players pre-play various types of data simultaneously (such as audio combined with video, lyrics, and at least one type of visual data in motion effects), the embodiment of the present application provides strategies for different visual players based on the idea of aligning the audio playback progress, including playing the visual data at double the speed, so that the playback progress of various visual players can be synchronized with the audio playback progress. Among them, in the process of synchronizing the progress of visual data, the embodiment of the present application does not need to pause each player, which effectively reduces the operation time when there are many players, and the possible progress buffer delay or jamming, so as to avoid causing new synchronization problems and ensure the user's audio-visual dual experience.
[0065] Based on the above example descriptions, some specific possible implementation examples will be provided below. In actual applications, the implementation contents between these examples can be combined or implemented separately as needed according to the corresponding functional principles and application logic. If implemented in combination, the execution order between the combined examples can be determined according to their respective processing logics, which can be determined by the actual scenario.
[0066] See also Figure 2.2 to Figure 6 ,based on Figure 2.1 The present application provides another specific embodiment of an audio-visual data synchronization method, which includes the following steps:
[0067] Step 221: Acquire at least one type of visual data that is not synchronized with the audio playback progress of the audio data.
[0068] Step 222: Determine whether the visual player supports processing the frame segments in the visual data based on the audio playback progress information.
[0069] In actual applications, not all visual players support adjusting their internal clock mechanism with the help of clock information provided by other external players to change the visual player's internal visual data frame delivery strategy (which can be called supporting custom clocks). Therefore, it is necessary to distinguish different visual players and deploy subsequent response strategies accordingly, so that other visual players except audio players in multi-player scenarios can automatically align or follow the progress of the audio player autonomously.
[0070] In actual applications, step 222 "determine whether the visual player supports processing frame segments in the visual data based on the audio playback progress information" may not actually exist. For example, you can directly jump to execute the operation steps after step 222.
[0071] Step 223: If supported, the visual player is regulated to perform display processing on some frame segments in the visual data based on the audio playback progress information, so that the processed visual data is played synchronously with the audio data.
[0072] Under the main requirement of playing audio, the main thing is to keep the audio smooth as much as possible. In addition, because the human body is more sensitive to audio playback, the goal of synchronizing multiple players is mainly based on the progress of audio, so that other visual data can follow the progress of audio to achieve synchronous playback of each data stream. Of course, the audio playback progress is selected as the time basis for synchronization because audio playback has a more stable sampling rate, so using audio timestamps as the synchronization basis is relatively stable.
[0073] Step 223 may be referred to as a custom clock or clock following strategy. Exemplarily, when there are multiple types of visual players, for a visual player that supports a custom clock (such as iJkPlayer, ExoPlayer, or PagPlayer), the audio player may transmit the (current) audio playback progress (or playback position) information of the audio data to the visual player through the clock interface. Afterwards, the visual player may be prompted to perform display processing on some frame segments in the visual data based on the audio playback progress information, and the processing process or result may include discarding or delaying the playback of some frame segments.
[0074] based on Figure 2.1 In some specific examples, the operation of "performing display processing on some frame segments in the visual data" in step 223 may specifically include: obtaining a display threshold and a frame drop threshold determined based on the audio playback progress information; the display threshold indicates the time difference that the frame segments in the visual data are allowed to be played later than the corresponding audio segments in the audio data; for each frame segment in the visual data, determining the comparison result between the display time of the frame segment and the display threshold or the frame drop threshold, and processing the frame segment according to the display strategy corresponding to the comparison result; the display strategy includes display, discard or delayed display.
[0075] In the karaoke scene architecture, each player has different interfaces. For example, the system player MediaPlayer and the audio player (KSingPlayer or AudioPlayer) cannot correct the playback time through time. They each have their own clock and cannot affect each other. At the same time, the players are isolated from each other, but for visual players that support custom clocks, such as ExoPlayer, even if ExoPlayer and KSingPlayer are isolated from each other, because ExoPlayer is very extensible, a clock interface (MediaClock) can be added to the ExoPlayer renderer to intervene in ExoPlayer's own clock, so that the clocks of ExoPlayer and audio players can be synchronized. The principle of achieving synchronization can be summarized as follows: ExoPlayer can display the frames in the visual data, drop frames (or skip frames), or wait (i.e., delay display) according to the audio playback progress information passed in by the interface to achieve synchronization. The specific display processing to be performed on a certain frame segment can be determined according to the comparison result of the display time of the frame segment with the display threshold or the frame loss threshold, as described below. The above-mentioned MediaClock or media clock: a reference tool for realizing the decoding progress and playback progress control of the player.
[0076] In some specific examples, the operation of "processing the frame segment according to the display sending strategy corresponding to the comparison result" may specifically include: if the display sending time of the frame segment is within the positive and negative intervals of the display sending threshold, the frame segment is normally displayed; if the display sending time of the frame segment is less than the display sending threshold, or the display sending time of the frame segment is greater than or equal to the frame dropping threshold, the frame segment or the adaptation frame related to the frame segment is discarded; if the display sending time of the frame segment is within the interval formed by the display sending threshold and the frame dropping threshold, the sleep time of the frame segment is determined, and the frame segment is normally displayed until the end of the sleep time.
[0077] Taking video data as an example (other types of visual data such as lyrics or special effects can be implemented similarly), it can be assumed that the display sending threshold of the video frame segment is syncTime, and the abnormal threshold (i.e., the frame dropping threshold) is unexpectTime. Generally speaking, the absolute value of syncTime is less than the absolute value of unexpectTime. SyncTime and unexpectTime are two thresholds used to control video synchronization; the display sending time of a certain video frame segment can be assumed to be PTS (Presentation Time Stamp), indicating when this frame should be displayed. Since the human body is more sensitive to audio than to video, syncTime can be interpreted as the time range within which the video can be slower than the audio. Beyond this value, the human body will notice that the audio and video are not aligned. Of course, for most people, the value of syncTime can be larger, and the specific value is not limited. For a video frame segment, the main implementation steps of the above display sending processing strategy can be as follows:
[0078] A. If -syncTime <= PTS <= syncTime, the video frame is displayed. The formula -syncTime <= PTS <= syncTime defines the PTS range of a normally displayed frame. If the PTS of the video frame falls within this range, then the frame will be normally displayed (i.e., allowed to be played and displayed on the terminal through the player); this range takes into account the positive and negative values of syncTime and can represent allowing a small buffer interval before and after the synchronization time point for the video frame to cope with possible decoding delays or network jitters and other situations. The above decoding refers to the process of converting the resource into a resource that can be normally played.
[0079] B. If PTS < syncTime, the video frame is discarded. When PTS < -syncTime, it means that the timestamp of the video frame is earlier than the expected synchronization time (such as the playback time point of the corresponding audio segment). This usually indicates that the video decoding speed is too fast or the playback speed of the audio player is too slow. Therefore, in order to avoid the video playing ahead of the audio, this premature video frame can be selected to be discarded. Generally, the frame dropping operation helps to cope with videos with a large number of video group frames.
[0080] C. If PTS>=unexpectTime, discard the adaptation frame of the video frame. UnexpectTime is an abnormal threshold, and its absolute value is usually larger than the absolute value of syncTime. It is used to define a larger time range. PTS outside this range indicates that the video frame is seriously ahead of or seriously behind the synchronization time. When PTS>=unexpectTime, it means that the playback time difference between the video frame and the audio player is too large. You can choose to discard the video frame or the related adaptation frame to avoid serious mismatch between video and audio.
[0081] D. If syncTime<=PTS<=unexpectTime, put the display thread to sleep appropriately, that is, delay or wait for display, so as to ensure the appropriate display frequency. When PTS falls between syncTime and unexpectedTime, it means that although the video frame is delayed, it has not reached the level of needing to be discarded. At this time, in order to adjust the display speed of the video frame, you can choose to let the thread sleep for a while to slow down the display frequency so as to match the playback speed of the audio player.
[0082] It can be seen from the above description that the embodiment of the present application can dynamically adjust the video display strategy according to the PTS of the video frame and the set threshold, ensure the synchronization between the video and the audio, make the video playback smoother and more coherent, and improve the user experience. It should be noted that the above AD strategy and threshold are used for exemplary description rather than limitation, because the above AD strategy and threshold settings may vary due to factors such as application scenarios, hardware performance or network conditions during specific implementation, and need to be adjusted and optimized according to actual conditions.
[0083] In some specific examples, the above-mentioned operation of "determining the sleep time of the frame fragment" may specifically include: determining the sleep time of the frame fragment based on the audio and video time difference and the normal decoding time of the frame fragment by the video player; the audio and video time difference refers to the playback time difference between the frame fragment and the audio segment of the corresponding content.
[0084] Still taking the video frame segment as an example, the audio segment corresponding to the video frame content (i.e., the segment with synchronized audio and video) can be determined to judge the play time difference between the video frame and the aforementioned audio segment. Afterwards, a more reasonable sleep time for the frame segment can be determined based on the audio and video time difference and the normal decoding time of the video player for the frame segment to reduce the progress difference between the video frame and the aforementioned audio segment.
[0085] Step 224: If not supported, keep the playback speed of the audio data unchanged, and perform speed-changing processing on the visual segments in the visual data, so that the entire visual data is played synchronously with the audio data because the visual segments are played at double speed.
[0086] From the above description, it can be seen that the embodiments of the present application provide a variety of alternative strategies for different visual players, including a strategy for regulating the visual player to display a portion of the frame fragments in the visual data, or a strategy for playing the visual data at double the speed, so that the playback progress of various visual players can be synchronized with the audio playback progress.
[0087] In actual applications, the variable speed synchronization strategy is more universal than the above step 223 (custom clock strategy), because almost all players currently support variable speed synchronization, but in terms of effect, the custom clock strategy is better than the variable speed synchronization strategy. The so-called variable speed synchronization in the embodiment of the present application refers to that the audio player keeps the playback speed of the audio unchanged, and the visual players such as the video player and the special effects player use the method of slowing down or speeding up to achieve the synchronous playback of visual data such as video and motion effects with the audio. In other words, the provision of the variable speed synchronization strategy is to deal with the fact that some visual players do not support custom clocks, such as MediaPlayer, which cannot intervene in the clock. At this time, it can be adjusted to follow the progress of the audio player by means of variable speed.
[0088] based on Figure 2.1 In some specific examples, the specific implementation logic of step 224 can be summarized as follows: the audio keeps the playback speed unchanged, the visual player slows down or speeds up the visual segment of length S, and resumes normal playback at the original 1x speed for the remaining segments after the S position, so as to align the progress of the video data with the progress of the audio playback. Taking the scenario of MediaPlayer combined with KSingPlayer as an example, the specific logic can be as follows:
[0089] Calculate the time difference gapOffset between MediaPlayer and KSingPlayer, such as gapOffset = MediaPlayer time information - KSingPlayer time information. gapOffset may be a negative value. If it is a negative value, it means that the MediaPlayer plays slowly and the video needs to be accelerated; if it is a positive value, it means that the MediaPlayer plays quickly and needs to be decelerated; the above time information may include time significance information such as the playback time point of the frame fragment.
[0090] Afterwards, the calculated gapOffset can be substituted into the kinematic vector formula S*speed*1-S*1=gapOffset (S is the number of seconds, 1 represents the normal speed) to calculate the target speed and the duration S of the segment to be played at the speed multiple (i.e., determine the visual segment to be played at a variable speed). Of course, a recursive algorithm is used in this calculation process, in which the priority is to ensure that speed>=0.25 (the reason can be seen below). It can be understood that speed can be used to calculate S step by step. For example, to ensure that speed>=0.25 is met, try to make S<=5 seconds (you can set a suitable value other than 5 according to actual conditions). If it cannot be met, S can be greater than 5, but in general, speed cannot be less than 0.25. The S that meets the requirements should be less than the total duration of the visual data. Of course, the conditions may require other speeds other than 0.25, which can be determined by the needs and are not limited here.
[0091] The following is an example of a possible implementation process of recursively solving speed and S.
[0092] Possible implementation process 1. The vector formula S*speed*1-S*1=gapOffset can be converted to S=gapOffset / (speed-1), that is, the value of S depends on speed and gapOffset. Since speed must be greater than or equal to 0.25, you can start from speed=0.25 and increase the value of speed until you find S that meets the conditions:
[0093] Step 1. Initialize speed to 0.25.
[0094] Step 2. Check whether gapOffset is divisible by speed-1. If so, S = gapOffset / (speed-1).
[0095] Step 3. If S is positive, it can be considered that the solution has been found.
[0096] Step 4. If S is not a positive number or gapOffset cannot be divided by speed-1, you can gradually increase the value of speed, for example, by a small amount of 0.01 each time, and then return to step 2 and repeat steps 2 to 4 until you find S and speed that meet the conditions, or determine that there is no solution.
[0097] Similar to possible implementation process one, possible implementation process two may be to first initialize a larger speed value (such as 2.0) to try to find a suitable S. If a suitable S cannot be found (it is still large), then gradually reduce the speed value starting from this speed value until a suitable S is found (which may be slightly larger than the preset 5 seconds). However, in general, speed>=0.25 must be ensured.
[0098] The following explains why speed>=0.25 is required. If the clock-following solution is used, the visual data in the pause state does not need to be processed. However, for players that do not support clock-following, if variable speed synchronization is used, such as the system player MediaPlayer, if the speed is 0, the MediaPlayer will consider it as calling pause. Variable speed in the pause state can easily cause new synchronization problems, or even fail to solve existing synchronization problems. Therefore, the speed cannot be less than 0.25 times the speed for this purpose.
[0099] based on Figure 2.1 As an example content, if the variable speed synchronization strategy is chosen to be implemented, the embodiment of the present application may also include that since the speed setting of the player may be reset to resume or pause, before calling the resume or pause program, the visual data must be resumed at the original speed (i.e., first restored to normal playback state and then variable speed synchronization). Specifically: if the visual data is in a paused state, the visual data is restored to a playback state at the initial speed; at least part of the visual fragments in the visual data after the resumption of playback will be adjusted to the target speed for playback.
[0100] It should be noted that if the user actively pauses during the speed change, there will obviously be a certain conflict with the speed change logic. The purpose of resuming the normal playback state is to avoid the conflict, that is, the speed should be changed when the player is playing normally, rather than when it is paused. In other words, the action of resuming the normal playback state here is mainly aimed at handling the logical conflict of the user's active pause. Based on the description here, it should be noted that the above speed cannot be 0, otherwise the visual player such as MediaPlayer will think that pause has been called and will not implement the speed change synchronization strategy.
[0101] based on Figure 2.1 As an example content, if a variable speed synchronization strategy is chosen to be implemented, the embodiment of the present application may also include: if the distribution position of the end of the visual segment in the visual data is after the preset position, then the position difference between the distribution position and the preset position is obtained; the distribution position is retracted by at least the position difference to obtain a new visual segment whose end distribution position is prior to or equal to the preset position, and the new visual segment will be adjusted to the target speed for playback.
[0102] For example, the preset position may be a position before the end of the visual data, such as the position of 10 seconds before the end of the visual data with a total duration of 50 seconds. The preset position may be determined according to the actual situation. It is generally believed that if the visual segment selected for double-speed playback is too long, it may affect the audio-visual effect or waste synchronization resources. Therefore, the visual segment to be played at double speed may be shortened to compensate, that is, the position of the reverse seek to end the double-speed playback is more appropriate.
[0103] Since the audio and video may still be out of sync again due to various reasons after the clock is synchronized, it is necessary to periodically check whether the audio and video clips are synchronized. Figure 2.1 , as a possible implementation method, if the variable speed synchronization strategy is chosen to be implemented, the embodiment of the present application may also include: for the remaining segments played at the initial speed of the visual data, detecting whether the remaining segments are synchronized with the audio playback progress when they are played; the remaining segments are the segments after the visual segments in the visual data; if they are not synchronized, marking the abnormal segments in the remaining segments that are not synchronized with the audio playback progress, and obtaining the time difference generated by the abnormal segments; according to the time difference, determining the next target speed and the visual segment in the abnormal segment to be played at the next target speed; the time difference is the difference between the time information of the abnormal segment and the time information of the corresponding audio segment, and the next target speed is used to reduce the time difference; if the time difference is greater than the preset difference, the segment after the latest determined visual segment is used as the next remaining segment, and returning to the step of detecting whether the remaining segments are synchronized with the audio playback progress when they are played, until the latest time difference is less than or equal to the preset difference.
[0104] Exemplarily, if the audio clip is not played completely within the preset time length after the audio and video synchronization is performed, during this process, if it is detected that the remaining clips (such as the last 42 seconds of a 50-second video) are not played synchronously with the audio playback progress, the operation can be similar to step 224 above, and some of the remaining clips can be selected for speed change until the audio clip is played completely, so that the remaining clips as a whole are synchronized with the audio playback progress because at least one clip is speed-changed, that is, the asynchronous gap between the audio and video (i.e., the time difference) is gradually reduced in segments.
[0105] The above mainly illustrates that each visual player can implement synchronization strategy for visual data to achieve multi-player synchronization, but it is possible that a player can be selected to substitute or coordinate the synchronization strategy for visual data of each visual player. Substitution here can be understood as guidance or replacement of the operation flow of each visual player. Figure 2.1As an example content of the present invention, as a possible implementation method, the specific implementation process of the above step 223 may include: selecting a resource player; the resource player is one of the at least one visual player or other players, and the resource player supports accessing and regulating at least one visual player; based on the audio playback progress information associated with the resource player and the class information inherited by the resource player, replacing at least one visual player to send and display at least one frame of the played visual data, so that the processed visual data is played synchronously with the audio data.
[0106] As a feasible solution, you can use the high scalability of ExoPlayer to connect all streams (audio, video, lyrics, animation and other media streams) and players as components to ExoPlayer to achieve better results. The main steps are as follows:
[0107] 1. Use ExoPlayer resource management class MergingMediaSource to merge all data streams (audio, video, lyrics, animation and other media streams). The merging here is not synchronization of progress, but merging animation, MIDI, lyrics, scorer, audio (including HQ audio), video (various bitstreams) into multiple streams, and then implementing different players. At the same time, use the clock mechanism inside ExoPlayer (independent clocks such as audio clock) to synchronously render various data streams, so that audio and video synchronization can also be achieved.
[0108] 2. Inherit the ExoPlayer player BaseRendererer class to implement different functions, such as special effects, advertising, lyrics, etc. In other words, the resource player can be expanded into various players that can adapt to various visual data.
[0109] 3. Rewrite the ExoPlayer player management module to achieve simultaneous playback of multiple streams. Since ExoPlayer lacks logic for MIDI (beat), lyrics coloring, scoring, animation, etc., and does not support the simultaneous playback of two audio or video, it is necessary to implement some rendering logic by itself. At the same time, for some special mp4 animations, it is necessary to support the simultaneous playback of at least two videos or two audios. Therefore, the scope of changes is mainly decapsulation, track screening, player pairing, etc. For example, ExoPlayer decodes multiple streams into data streams of each track and sends them to the adapted players for processing. The adapted players here can be player components that are uniformly trimmed by the internal clock of ExoPlayer. Of course, whether a resource player can be used to replace each player to synchronize the data stream requires consideration of the actual compatibility effects such as system model (such as Andrio or iOS) and / or audio usage scenarios (such as simply listening to and watching audio and video, or recording singing and watching videos, etc.).
[0110] 4. Use the internal clock of ExoPlayer to automatically synchronize. The difference from the above custom clock process is that the clock used here is the internal clock of the single player ExoPlayer, and there is no need to expose the interface to obtain it; while the custom clock is when multiple players are playing at the same time, the clock logic of each player renderer is modified, and the interface needs to be exposed to the outside to pass in the time base, such as the time base provided and passed in by other players outside the video player through this interface.
[0111] The above mainly uses video as an example. For visual data such as lyrics, MIDI (beat), and motion effects, similar synchronization operations can be used, such as for videos, so that they match the playback speed of the audio. For example, the synchronization of lyrics includes allowing the lyrics to actively follow the progress of the audio playback. Through the active detection device, if it is found that the playback time is too long, the playback time is actively compensated. If the lyrics lag behind the audio, the display time of the lyrics is shortened or accelerated, or the time increment is reduced. If the lyrics are earlier than the audio, the time interval for each update of the lyrics is reduced or the lyrics are slowed down, so that the lyrics change more smoothly and match the playback speed of the audio.
[0112] In summary, the embodiments of the present application can be used in scenarios where multiple players are used at the same time. Through customized clock or variable speed synchronization strategies, other players except the audio player can automatically align the audio player autonomously, that is, to ensure that the playback time of the visual data can be synchronized with the audio time, and the synchronization process does not require pauses, does not freeze, has low control difficulty, high synchronization success rate, and short time consumption, and is easy to meet international standards (such as the International Telecommunication Union audio delay perception standard).
[0113] like Figure 5 As shown, the embodiment of the present application can implement different types of players through custom clocks or variable speed synchronization strategies, so as to achieve synchronization between players in a manner of "chasing" the audio progress, and provide a good synchronization experience. Specifically, when multiple players are playing at the same time, the audio playback progress can be notified at regular intervals, and the audio playback progress information can be encapsulated, such as encapsulating TimeLine (including information such as the current progress or decoding position); determine whether the current visual player supports a custom clock. If it supports a custom clock, implement its MediaClock interface for the visual player to receive the audio playback progress information, so that the visual player can perform frame dropping, display sending, and waiting processing based on this to achieve synchronization. If the custom clock is not supported, a variable speed synchronization strategy is adopted, including calculating the target speed and the visual segment to be played at that speed, accelerating or decelerating the visual segment by itself, and finally achieving synchronization. In this way, the playback progress of visual data such as video, lyrics, MIDI, scorers, and canvases can be synchronized with the audio, such as generating Figure 6 The frame rate alignment effect is shown.
[0114] Compared to Figure 2.1 The examples shown illustrate that the above-mentioned additional or detailed example contents or possible implementation methods do not necessarily have to be executed during the specific implementation. If more than two examples or possible implementation methods are added, these examples or possible implementation methods can be implemented in combination or separately. If implemented in combination, the execution order between the combined examples can be determined according to their respective processing logic, which can be determined according to the actual scenario.
[0115] See also Figure 7 The electronic device 700 of the embodiment of the present application may include one or more processors (such as central processing units (CPU)) 701 and a memory 705, in which one or more applications or data are stored.
[0116] The memory 705 may be a volatile storage or a persistent storage. The program stored in the memory 705 may include one or more modules, each of which may include a series of instruction operations in the electronic device. Furthermore, the central processor 701 may be configured to communicate with the memory 705 and execute a series of instruction operations in the memory 705 on the electronic device 700.
[0117] The electronic device 700 may also include one or more power supplies 702, one or more wired or wireless network interfaces 703, one or more input and output interfaces 704, and / or one or more operating systems, such as Windows ServerTM, Mac OS XTM, UnixTM, LinuxTM, FreeBSDTM, etc.
[0118] The central processor 701 can execute the operations performed by the aforementioned first aspect or any specific method embodiment of the first aspect, and the details will not be repeated here.
[0119] The present application provides a computer-readable storage medium, comprising instructions, which, when executed on a computer, enable the computer to execute the method described in the first aspect or any specific implementation of the first aspect.
[0120] The present application provides a computer program product comprising instructions or a computer program. When the computer program product is run on a computer, the computer is enabled to execute the method described in the first aspect or any specific implementation of the first aspect.
[0121] It is understood that in various embodiments of the present application, the sequence number of each step does not mean the order of execution, and the execution order of each step should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application. The operation content added or refined in each example scheme of the above method, system or device (if any) does not necessarily have to be executed in the specific implementation. If more than two operations are added, these operations can be implemented in combination or separately, depending on the actual scenario.
[0122] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working process of the system (if any) and device described above can refer to the corresponding process in the aforementioned method embodiment, and will not be repeated here.
[0123] In the several embodiments provided in the present application, it should be understood that the disclosed devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of units is only a logical function division. There may be other division methods in actual implementation. For example, multiple units or components can be combined or integrated into another system or device, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be through some interfaces, indirect coupling or communication connection of devices or units, which can be electrical, mechanical or other forms.
[0124] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.
[0125] In addition, each functional unit in each embodiment of the present application may be integrated into one processing unit, or each unit may exist physically separately, or two or more units may be integrated into one unit. The above-mentioned integrated unit may be implemented in the form of hardware or in the form of software functional units.
[0126] If the integrated unit is implemented in the form of 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 the present application is essentially or the part that contributes to the prior art or all or part of the technical solution can be embodied in the form of a software product. The computer software product (or computer program product) is stored in a storage medium, including a number of instructions to enable a computer device (which can be a personal computer, a business server or a network device, etc.) to perform all or part of the steps of the various embodiments of the present application. The aforementioned storage medium includes: U disk, mobile hard disk, read-only memory (ROM, read-only memory), random access memory (RAM, random access memory), disk or optical disk and other media that can store program codes.
Claims
1. A method for synchronizing audiovisual data, characterized in that: include: Acquire at least one type of visual data that is not synchronized with the audio playback progress of the audio data; The at least one type of visual data is processed and played by at least one visual player; If it is determined that the visual player does not support processing frame segments in the visual data based on the audio playback progress, the playback speed of the audio data is kept unchanged, and based on the time difference between the audio data and the visual data, the target speed and the visual segments in the visual data that will be played at the target speed are determined, so that the visual data as a whole is played synchronously with the audio data because the visual segments are played at the target speed.
2. The audio-visual data synchronization method according to claim 1, characterized in that: After acquiring at least one type of visual data that is not synchronized with the audio playback progress of the audio data, the method further includes: If it is determined that the visual player supports processing frame fragments in the visual data based on the audio playback progress, the visual player is adjusted to display some frame fragments in the visual data based on the audio playback progress, so that the processed visual data is played synchronously with the audio data.
3. The audio-visual data synchronization method according to claim 2, characterized in that: The display processing of some frame segments in the visual data includes: Obtaining a display threshold and a frame loss threshold determined based on the audio playback progress; the display threshold indicates a time difference that a frame segment in the visual data is allowed to be played later than a corresponding audio segment in the audio data; For each frame segment in the visual data, determine the comparison result of the display time of the frame segment with the display threshold or the frame loss threshold, and process the frame segment according to the display strategy corresponding to the comparison result; the display strategy includes display, discard or delayed display.
4. The audio-visual data synchronization method according to claim 3, characterized in that: The processing of the frame fragments according to the display strategy corresponding to the comparison result includes: If the display time of the frame segment is within the positive and negative range of the display threshold, the frame segment is displayed normally; If the display time of the frame segment is less than the display threshold, or the display time of the frame segment is greater than or equal to the frame loss threshold, discard the frame segment or the adaptation frame related to the frame segment; If the display time of the frame segment is within the interval formed by the display threshold and the frame loss threshold, the sleep time of the frame segment is determined, and the frame segment is normally displayed until the sleep time ends.
5. The audio-visual data synchronization method according to claim 4, characterized in that: The determining of the sleep time of the frame segment comprises: The dormancy time of the frame segment is determined based on the audio and video time difference and the normal decoding time of the frame segment by the video player; the audio and video time difference refers to the playback time difference between the frame segment and the audio segment of the corresponding content.
6. The audio-visual data synchronization method according to claim 2, characterized in that: The step of regulating the visual player to display some frame segments in the visual data based on the audio playback progress includes: Selecting a resource player; the resource player is one of the at least one visual player or other players, and the resource player supports accessing and regulating the at least one visual player; Based on the audio playback progress associated with the resource player and the class information inherited by the resource player, the at least one visual player is substituted to perform display processing on at least one frame segment of the played visual data, so that the processed visual data is played synchronously with the audio data.
7. The audio-visual data synchronization method according to claim 1, characterized in that: If it is determined that the visual player does not support processing frame segments in the visual data based on the audio playback progress, the method further includes: If the visual data is in a paused state, the visual data is restored to a playback state of being played at an initial speed; at least part of the visual segments in the visual data after the playback is restored will be adjusted to the target speed for playback.
8. The audio-visual data synchronization method according to claim 1, characterized in that: If the distribution position of the end of the visual segment in the visual data is after the preset position, the method further includes: Obtaining a position difference between the distribution position and the preset position; The distribution position is retracted at least by the position gap to obtain a new visual segment whose terminal distribution position is prior to or equal to the preset position, and the new visual segment will be adjusted to play at the target speed.
9. The audio-visual data synchronization method according to claim 1, characterized in that: After determining the target speed and the visual segment in the visual data to be played at the target speed according to the time difference between the audio data and the visual data, the method further includes: For the remaining segments played at the initial multiple speed of the visual data, detecting whether the remaining segments are played synchronously with the audio playback progress; the remaining segments are segments of the visual data after the visual segments; If not synchronized, mark the abnormal segment in the remaining segments that is not synchronized with the audio playback progress, and obtain the time difference generated by the abnormal segment; determine the next target speed and the visual segment in the abnormal segment to be played at the next target speed according to the time difference; the time difference is the difference between the time information of the abnormal segment and the time information of the corresponding audio segment, and the next target speed is used to reduce the time difference; If the time difference is greater than the preset difference, the segment after the most recently determined visual segment is taken as the next remaining segment, and the process returns to the step of detecting whether the remaining segment is played in sync with the audio playback progress, until the most recently obtained time difference is less than or equal to the preset difference.
10. An electronic device, characterized in that: include: Processor and memory; The processor is configured to communicate with the memory and execute instructions in the memory to implement the data access method according to any one of claims 1 to 9.
