Video playing method and device and electronic equipment

By starting two threads to load image data and audio data respectively during video playback, and playing data after determining that the other thread has completed the data loading, the problem of audio and audio pictures not synchronized in video playback is solved, and the effect of the audio data and image data being played at the same time after both are loaded is achieved.

CN119815093AActive Publication Date: 2025-04-11GREAT WALL MOTOR CO LTD
View PDF 8 Cites 0 Cited by

Patent Information

Application Number
CN202411857291.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-17
Publication Date
2025-04-11
Estimated Expiration
2044-12-17

AI Technical Summary

Technical Problem

During video playback, the audio data may be out of synchronization due to the separate storage of image data and audio data.

Method used

By starting two threads to load the image data and audio data of the video to be played, each thread has completed the data loading and after each thread has completed the data loading, it plays the data loaded by itself to ensure that the audio data and image data start playing at the same time after both are loaded.

Benefits of technology

It effectively reduces the probability of audio and video out of synchronization, ensuring that the audio data and image data can be played at the same time during video playback.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119815093A_ABST
    Figure CN119815093A_ABST
Patent Text Reader

Abstract

The invention provides a video playing method and device and electronic equipment, and the method is applied to the technical field of video processing, and comprises the steps: starting two threads in a video playing process, respectively loading image data and audio data of a to-be-played video, and after each thread completes the data loading, outputting the image data and the audio data of the to-be-played video; and when it is determined that the other thread completes data loading, the data loaded by the thread is played, and the image data and the audio data can be played after the audio data and the image data are loaded. According to the video playing method provided by the invention, even if the audio data and the image data are not loaded at the same time, the audio data and the image data can be played at the same time, so that the probability of occurrence of a sound and picture desynchrony condition can be reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of video processing technology, and more specifically, to a video playback method, device and electronic device in the field of video processing technology. Background Art

[0002] Videos usually consist of two parts: image data and audio data. In order to reduce storage space and improve transmission efficiency, image data and audio data may be stored separately. When image data and audio data are stored separately, during video playback, image data and audio data will be loaded from two locations for playback, which may cause the problem of audio and video being out of sync. Summary of the invention

[0003] The present application provides a video playback method, device and electronic device, which can reduce the probability of audio and video being out of sync during video playback.

[0004] In a first aspect, a video playback method is provided, the method comprising:

[0005] Start two threads to load the image data and audio data of the video to be played respectively;

[0006] After each of the threads completes data loading, if it is determined that another of the threads has completed data loading, it plays the data loaded by itself to play the video to be played.

[0007] In the embodiment of the present application, during the video playback process, two threads are started to load the image data and audio data of the video to be played respectively. After each thread completes the data loading, it plays the data loaded by itself when it is determined that the other thread has completed the data loading. The image data and the audio data can be played after the audio data and the image data have completed the loading. In this way, even if the audio data and the image data are not loaded at the same time, the audio data and the image data can be played at the same time, thereby reducing the probability of the occurrence of the situation where the audio and the image are not synchronized.

[0008] Optionally, if it is determined that the other thread has completed data loading, then playing the data loaded by itself includes: obtaining a marker object created before the two threads are started;

[0009] After the object performs a preset operation, if it is determined that the marked object has undergone the preset operation twice, the data loaded by itself is played.

[0010] In an embodiment of the present application, by marking whether the image data and audio data have been loaded by marking the number of operations on the marking object, it is convenient for the two threads to play their own loaded data when they determine that the other party has completed data loading, so that the audio data and image data can be played simultaneously when both the audio data and the image data have been loaded.

[0011] Optionally, the marking object is a locking count, and after performing a preset operation on the marking object, if it is determined that the marking object has undergone the preset operation twice, the data loaded by itself is played, including: obtaining a lock for the locking count to lock the locking count; wherein the lock is created before the two threads are started, and the initial value of the locking count indicates that both the image data and the audio data have not been loaded; after performing the preset operation on the locking count, releasing the lock to unlock the locking count; wherein the preset operation is used to increase the locking count by a preset value or decrease the locking count by a preset value; after releasing the lock, if it is determined that the locking count reaches a target value, the data loaded by itself is played; wherein the target value indicates that both the image data and the audio data have been loaded.

[0012] In an embodiment of the present application, when two threads operate on the locking times, the locking times can be locked by a lock to prevent the two threads from operating on the locking times at the same time, thereby avoiding the situation where the locking times are judged incorrectly, and further preventing the problem of image data and audio data starting to play at different times due to incorrect judgment of the locking times.

[0013] Optionally, playing the data loaded by itself includes: if another thread is in a waiting state, sending a notification to the other thread to notify the other thread to play the loaded data at a target time after the current time; wherein the current time is separated from the target time by a preset time length; after sending the notification to the other thread, playing the data loaded by itself at the target time.

[0014] In an embodiment of the present application, when each thread plays its own loaded data, it plays the loaded data at a target time after the current time, and notifies the other thread to play the loaded data at the target time. The two threads can play their own loaded audio data at the target time at the same time, thereby reducing the probability of audio and video being out of sync.

[0015] Optionally, if it is determined that another thread has completed data loading, then playing the data loaded by itself includes: decoding the loaded data; after decoding is completed, if it is determined that another thread has completed data loading and decoding, then playing the data loaded by itself.

[0016] In an embodiment of the present application, after each thread completes loading and decoding of the data, it plays the data after determining that another thread has completed loading and decoding of the data. This can eliminate the time difference caused by the different decoding times of the audio data and the image data, thereby further reducing the probability of audio and video being out of sync.

[0017] Optionally, starting two threads to respectively load image data and audio data of the video to be played includes: starting one of the two threads to load first data; wherein the first data is the one with larger data volume between the image data and the audio data; after starting one of the threads, starting the other of the two threads to load second data after a target time interval; wherein the second data is another data between the image data and the audio data other than the first data.

[0018] In an embodiment of the present application, based on the difference in data volume between audio data and image data, a thread is started first to load data with a large data volume, and then another thread with a small data volume is started after a certain interval. This can shorten the time it takes for the two threads to be started at the same time and reduce the power consumption of the electronic device.

[0019] Optionally, before starting another of the two threads to load the second data after the interval target duration, the method also includes: determining a first difference between the data volume of the first data and the data volume of the second data; determining the target duration based on the first difference; wherein the first difference is positively correlated with the target duration.

[0020] In an embodiment of the present application, the difference between the data volume of the first data and the data volume of the second data is set to be positively correlated with the target duration, which can shorten the duration of simultaneous startup of the two threads as much as possible, thereby reducing the power consumption of the electronic device.

[0021] Optionally, after completing data loading, each of the threads plays the data loaded by itself if it is determined that another thread has completed data loading, including: determining a second difference between the data volume of the image data and the data volume of the audio data; when the second difference is greater than a preset difference, after completing data loading, each of the threads plays the data loaded by itself if it is determined that another thread has completed data loading.

[0022] In an embodiment of the present application, when the difference between the data volume of image data and the data volume of audio data is greater than a preset difference, each thread plays the data loaded by itself after completing data loading and determining that another thread has completed data loading. When the difference between the data volume of image data and the data volume of audio data is less than or equal to the preset difference, each thread directly plays the data loaded by itself after completing data loading, which can simplify the audio playback process.

[0023] In a second aspect, a video playback device is provided, the device comprising:

[0024] A loading module is used to start two threads to load the image data and audio data of the video to be played respectively;

[0025] The playing module is used for each thread to play the data loaded by itself after completing data loading, so as to play the video to be played if it is determined that another thread has completed data loading.

[0026] In a third aspect, an electronic device is provided, comprising a memory for storing executable program code; and a processor for calling and running the executable program code from the memory, so that the electronic device executes a method in any possible implementation of the first aspect.

[0027] In a fourth aspect, an electronic device program product is provided, the electronic device program product comprising: an executable program code, when the executable program code is run on an electronic device, the electronic device executes the method in any possible implementation manner of the above-mentioned first aspect.

[0028] In a fifth aspect, a readable storage medium is provided, which stores an executable program code. When the executable program code runs on an electronic device, the electronic device executes the method in any possible implementation of the first aspect. BRIEF DESCRIPTION OF THE DRAWINGS

[0029] Figure 1 is a flowchart of a video playback method provided by an embodiment of the present application;

[0030] Figure 2 It is a flowchart of a video playback method provided in an embodiment of the present application;

[0031] Figure 3 is a structural schematic diagram of a video playback device provided in an embodiment of the present application;

[0032] Figure 4 It is a structural schematic diagram of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0033] The technical solution in the present application will be described clearly and in detail below in conjunction with the accompanying drawings. In the description of the embodiments of the present application, unless otherwise specified, " / " means or, for example, A / B can mean A or B: "and / or" in the text is only a description of the association relationship of associated objects, indicating that there can be three relationships, for example, A and / or B can mean: A exists alone, A and B exist at the same time, and B exists alone. In addition, in the description of the embodiments of the present application, "multiple" means two or more than two.

[0034] In the following, the terms "first" and "second" are used for descriptive purposes only and are not to be understood as suggesting or implying relative importance or implicitly indicating the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include one or more of the features.

[0035] Videos usually consist of two parts: image data and audio data. Image data refers to the picture information in the video, including a series of continuously changing static pictures, and audio data refers to the sound information contained in the video, including a series of continuously changing audio frames. In related technologies, in order to save storage space and improve transmission efficiency, it has become a common method to store audio data and image data in a video separately.

[0036] Since the video includes audio data and image data, two threads are usually started at the same time when playing the video. One thread loads the image data from the storage location of the image data into the buffer and then plays it, and the other thread loads the audio data from the storage location of the audio data into the buffer and then plays it. The amount of image data is generally larger than the amount of audio data, so the time taken to load image data is generally longer than the time taken to load audio data. In this way, the audio data is often loaded before the image data and starts to play before the image data, resulting in the audio and video being out of sync.

[0037] In order to solve the above technical problems, an embodiment of the present application provides a video playback method, which can be applied in electronic devices, such as mobile phones, electronic devices, tablet computers, host terminals (Host Unit Terminal, HUT) in vehicles, etc. But not limited to this. In this method, when playing a video, two threads are started to load the image data and audio data in the video (hereinafter referred to as the video to be played) respectively. After each thread completes the data loading, it determines whether the other thread has completed the data loading. After determining that the other thread has also completed the data loading, it starts playing the data that has been loaded separately with the other thread at the same time. In this way, even if the audio data and image data are not loaded at the same time, the two threads can start playing the audio data and image data at the same time, thereby reducing the probability of the occurrence of the audio and video being out of sync.

[0038] See also Figure 1 , Figure 1 is a flowchart of a video playback method provided by an embodiment of the present application. The execution subject of the method may be an electronic device, such as Figure 1 As shown, the method comprises the following steps:

[0039] Step 101: Start two threads to load the image data and audio data of the video to be played respectively.

[0040] Exemplarily, when the electronic device receives a video playback instruction input by the user, it can respond to the video playback instruction, determine the video to be played that the video playback instruction indicates to be played, and then create two threads and start the two threads to load the image data and audio data in the video to be played respectively.

[0041] In one embodiment, after creating two threads, the electronic device can start the two threads at the same time, one thread (hereinafter referred to as the audio thread) corresponds to the audio data, accesses the storage location of the audio data, and loads the audio data from the storage location to the buffer, and the other thread (hereinafter referred to as the image thread) corresponds to the image data, accesses the storage location of the image data, and loads the image data from the storage location to the buffer.

[0042] In actual applications, the amount of image data in the same video is generally larger than the amount of audio data. When the two threads are started at the same time, the audio thread may complete data loading before the image thread. Of course, the amount of audio data in some videos may also be larger than the amount of image data. When the two threads are started at the same time, the image thread may complete data loading before the audio thread.

[0043] Step 102: After each thread completes data loading, if it determines that another thread has completed data loading, it plays the data loaded by itself to play the video to be played.

[0044] In one embodiment, each thread can send a notification message to another thread after completing data loading. Correspondingly, each thread determines that the other thread has completed data loading when receiving a notification message sent by another thread after completing data loading. In combination with the above example, after the audio thread and the image thread are started at the same time, the audio thread determines whether the notification message sent by the image thread is received when the audio thread completes the loading of the audio data. If the notification message sent by the image thread is not received, a notification message is sent to the image thread and the audio thread enters a waiting state. After entering the waiting state, if the audio thread receives a notification message sent by the image thread after completing data loading, the loaded audio data can be started to be played. And, when the audio thread completes the loading of the audio data, if it determines that the notification message sent by the image thread has been received, it can be determined that the image thread has also completed the loading of the image data, and the audio thread can start to play the audio data.

[0045] Correspondingly, when the image thread completes loading of the image data, it determines whether it has received the notification information sent by the audio thread. If it has not received the notification information sent by the audio thread, it sends a notification information to the audio thread and enters a waiting state. After entering the waiting state, if the image thread receives the notification information sent by the audio thread after completing the loading of the audio data, it can start playing the loaded image data. And, when the image thread completes loading of the image data, if it determines that it has received the notification information sent by the audio thread, it can be determined that the audio thread has also completed the loading of the audio data, and the image thread can start playing the image data.

[0046] In this way, each thread plays the data it has loaded when it completes loading its own data and determines that the other thread has also completed loading its data. This allows the audio data to be played after the image data is loaded, and the image data to be played after the audio data is loaded, thus avoiding the problem of audio and video being out of sync.

[0047] In the embodiment of the present application, during the video playback process, two threads are started to load the image data and audio data of the video to be played respectively. After each thread completes the data loading, it plays the data loaded by itself when it is determined that the other thread has completed the data loading. The image data and the audio data can be played after the audio data and the image data have completed the loading. In this way, even if the audio data and the image data are not loaded at the same time, the audio data and the image data can be played at the same time, thereby reducing the probability of the occurrence of the situation where the audio and the image are not synchronized.

[0048] Optionally, if it is determined that another thread has completed data loading, the data loaded by itself is played, including:

[0049] Get the marker object created before the two threads are started;

[0050] After performing a preset operation on the marked object, if it is determined that the marked object has undergone two preset operations, the data loaded by itself is played.

[0051] In one embodiment, the electronic device may create a tag object while creating two threads. After starting the two threads, each thread first performs a preset operation on the tag after completing data loading, and then determines whether the tag object has undergone two preset operations. If two preset operations have been performed, it is determined that both threads have performed one operation on the tag object, that is, both threads have completed data loading. After determining that the tag object has undergone two preset operations, each thread starts playing the data loaded by itself.

[0052] Exemplarily, the tag object can be a shared variable. When creating a shared variable, the electronic device can set the initial value of the shared variable, and the initial value indicates that both threads have not completed data loading. For example, the initial value of the shared variable can be set to 0, and the preset operation is, for example, an add 1 operation. After starting the audio thread and the image thread, after the audio thread completes the loading of the audio data, it can first add 1 to the shared variable, and then determine whether the shared variable is 2. If it is determined that the shared variable is 2, it is determined that the image thread has also performed an add 1 operation on the shared variable. The shared variable has undergone two preset operations. At this time, it can be determined that the image thread has completed the loading of the image data, and the audio thread can start playing the loaded audio data.

[0053] On the contrary, when the audio thread determines that the shared variable is 1, it determines that the image thread has not added 1 to the shared variable, and the shared variable has only undergone one preset operation. At this time, it can be determined that the image thread has not completed the loading of the image data, and the audio thread enters the waiting state. After entering the waiting state, the audio thread continues to monitor the shared variable. When it detects that the shared variable has become 2, it determines that the image thread has completed the loading of the image data and starts playing the audio data. At this time, the image thread can determine that the shared variable is 2, the audio thread has completed the loading of the audio data, and the image thread can start playing the loaded image data.

[0054] Correspondingly, after completing the loading of the image data, the image thread can first add 1 to the shared variable, and then determine whether the shared variable is 2. If it is determined that the current value of the shared variable is 2, it is determined that the audio thread has also performed an addition 1 operation on the shared variable. The shared variable has undergone two preset operations. At this time, it can be determined that the audio thread has completed the loading of the audio data, and the image thread can start playing the loaded image data.

[0055] On the contrary, when the image thread determines that the shared variable is 1, it determines that the audio thread has not added 1 to the shared variable, and the shared variable has only undergone one preset operation. At this time, it can be determined that the audio thread has not completed the loading of the audio data, and the image thread enters the waiting state. After entering the waiting state, the image thread continues to monitor the shared variable. When it detects that the shared variable has become 2, it is determined that the audio thread has completed the loading of the audio data, and the image thread can start playing the image data. At this time, the audio thread can determine that the shared variable is 2, the image thread has completed the loading of the image data, and the audio thread can start playing the loaded audio data.

[0056] In an embodiment of the present application, by marking whether the image data and audio data have been loaded by marking the number of operations on the marking object, it is convenient for the two threads to play their own loaded data when they determine that the other party has completed data loading, so that the audio data and image data can be played simultaneously when both the audio data and the image data have been loaded.

[0057] Optionally, the marking object may be a lock count. After performing a preset operation on the marking object, if it is determined that the marking object has undergone two preset operations, the loaded data is played, including:

[0058] Acquire a lock with a lock count to lock the lock count; wherein the lock is created before the two threads are started, and the initial value of the lock count indicates that both the image data and the audio data have not been loaded;

[0059] After performing a preset operation on the number of lock times, releasing the lock to unlock the number of lock times; wherein the preset operation is used to increase the number of lock times by a preset value or decrease the preset value;

[0060] After releasing the lock, if it is determined that the number of lock attempts reaches the target value, the loaded data is played; wherein the target value indicates that both the image data and the audio data have been loaded.

[0061] In one implementation, before starting two threads, the electronic device can create a lock count and set an initial value of the lock count, the initial value indicating that both threads have not completed data loading, and can create a lock for the lock count. After completing data loading, each thread first acquires the lock, locks the lock count, and then performs a preset operation on the lock count.

[0062] Exemplarily, the initial value of the number of locks can be set to 2, and the preset operation can be to reduce the number of locks by 1 (1 is the preset value). When the number of locks is 0 (i.e., the target value), it means that both threads have completed data loading. After starting the audio thread and the image thread, the audio thread can first obtain the lock of the number of locks after completing the loading of the audio data. If the lock of the number of locks is obtained, it is determined that the number of locks is not locked by the image thread. The audio thread can lock the number of locks through the acquired lock to prevent the image thread from operating the number of locks at this time. At this time, the audio thread can subtract 1 from the number of locks. After completing the subtraction operation, the audio thread releases the lock to unlock the number of locks. Then, the audio thread determines whether the number of locks is 0. If it is determined that the number of locks is 0, it is determined that the image thread has completed the loading of the image data, and the audio data can start playing the audio data. If it is determined that the number of locks is 1, it is determined that the image thread has not completed the loading of the image data, and the audio thread enters a waiting state.

[0063] After entering the waiting state, the audio thread continues to monitor the number of locks. When it detects that the number of locks has become 0, it determines that the image thread has completed the loading of the image data and starts playing the audio data. At this time, the image thread can determine that the number of locks is 0, the audio thread has completed the loading of the audio data, and the image thread can start playing the loaded image data.

[0064] Correspondingly, after completing the loading of the image data, the image thread can first obtain the lock of the lock count. If the lock of the lock count is obtained, it is determined that the lock count has not been locked by the audio thread. The image thread can lock the lock count through the acquired lock to prevent the audio thread from operating the lock count at this time. At this time, the image thread can subtract 1 from the lock count. After completing the subtraction operation, the image thread releases the lock to unlock the lock count. Then, the image thread determines whether the lock count is 0. If it is determined that the lock count is 0, it is determined that the audio thread has completed the loading of the image data, and the image data can start playing the image data. If it is determined that the lock count is 1, it is determined that the audio thread has not completed the loading of the audio data, and the image thread enters a waiting state.

[0065] After entering the waiting state, the image thread continues to monitor the number of locks. When the number of locks becomes 0, it is determined that the audio thread has completed the loading of the audio data and starts playing the audio data. At this time, the audio thread can determine that the number of locks is 0, the image thread has completed the loading of the image data, and the audio thread can start playing the loaded audio data.

[0066] In an embodiment of the present application, when two threads operate on the locking times, the locking times can be locked by a lock to prevent the two threads from operating on the locking times at the same time, thereby avoiding the situation where the locking times are judged incorrectly, and further preventing the problem of image data and audio data starting to play at different times due to incorrect judgment of the locking times.

[0067] Optionally, play your own loaded data, including:

[0068] If the other thread is in a waiting state, a notification is sent to the other thread to notify the other thread to play the loaded data at a target time after the current time; wherein the current time and the target time are separated by a preset time length;

[0069] After sending a notification to another thread, play the data loaded by itself at the target time.

[0070] In one implementation, after each thread completes data loading and determines that another thread has completed data loading, it may send a notification to another thread in a waiting state, notifying the other thread to start playing data at a target time with a preset time interval from the current time.

[0071] Exemplarily, the preset duration is, for example, 200 milliseconds. When the audio thread completes data loading before the image thread, the audio thread determines that the image thread has not completed data loading when completing data loading, and enters a waiting state. After the image thread completes loading of the image data, when determining that the audio thread has completed data loading, it can determine a target moment 200 milliseconds after the current moment, and then send a notification to the audio thread in the waiting state, notifying the audio thread to start playing the audio data at the target moment 200 milliseconds after receiving the notification. After sending the notification, the image thread first waits for 200 milliseconds, and then starts playing the image data after waiting for 200 milliseconds. Correspondingly, after receiving the notification, the audio thread switches from the waiting state to the running state, and then first waits for 200 milliseconds, and then starts playing the audio data at the target moment after waiting for 200 milliseconds.

[0072] Similarly, when the image thread completes data loading before the audio thread, when the image thread completes data loading, if it determines that the audio thread has not completed data loading, it will enter a waiting state. After the audio thread completes the loading of the audio data, it can determine the target moment 200 milliseconds after the current moment when it determines that the image thread has completed data loading, and then send a notification to the image thread, notifying the image thread to start playing the image data at the target moment 200 milliseconds after receiving the notification. After sending the notification, the audio thread first waits for 200 milliseconds, and then starts playing the audio data at the target moment 200 milliseconds later. Correspondingly, after receiving the notification, the image thread switches from the waiting state to the running state, and then first waits for 200 milliseconds, and then starts playing the image data at the target moment 200 milliseconds later.

[0073] The specific value of the preset duration can be set according to actual needs, and this embodiment does not limit this.

[0074] In an embodiment of the present application, when each thread plays the data it has loaded, it plays the data it has loaded at a target time after the current time, and notifies another thread in a waiting state to play the loaded data at the target time. The two threads can play their respective loaded audio data at the target time at the same time, thereby reducing the probability of audio and video being out of sync.

[0075] Optionally, if it is determined that another thread has completed data loading, the data loaded by itself is played, including:

[0076] Decode the loaded data;

[0077] After decoding is completed, if it is determined that another thread has finished loading the data and decoding, the data loaded by itself is played.

[0078] In one embodiment, after each thread completes data loading, it first decodes the data loaded by itself. After decoding is completed, if it is determined that another thread has completed data loading and decoding, it starts to play the data loaded and decoded by itself. Exemplarily, after the audio thread completes the loading of audio data, it can first decode the audio data. After decoding is completed, it obtains the lock of the number of locks. If the lock of the number of locks is obtained, it is determined that the number of locks is not locked by the image thread. The audio thread can lock the number of locks through the obtained lock to prevent the image thread from operating the number of locks at this time. At this time, the audio thread can subtract 1 from the number of locks. After completing the subtraction operation, the audio thread releases the lock to unlock the number of locks. Then, the audio thread determines whether the number of locks is 0. If it is determined that the number of locks is 0, it is determined that the image thread has completed the loading and decoding of the image data, and the audio data can start to play the audio data. If it is determined that the number of locks is 1, it is determined that the image thread has not completed the loading of the image data (or has completed the loading of the image data but has not completed the decoding), and the audio thread enters a waiting state.

[0079] After entering the waiting state, the audio thread continues to monitor the number of locks. When it detects that the number of locks has become 0, it determines that the image thread has completed the loading and decoding of the image data and starts playing the audio data. At this time, the image thread can determine that the number of locks is 0, the audio thread has completed the loading and decoding of the audio data, and the image thread can start playing the loaded and decoded image data.

[0080] Exemplarily, when the audio thread completes loading and decoding of audio data, it determines whether it has received notification information sent by the image thread. If it has not received notification information sent by the image thread, it sends notification information to the image thread and enters a waiting state. After entering the waiting state, if the audio thread receives notification information sent by the image thread after completing loading and decoding of image data, it can start playing the decoded audio data. Also, when the audio thread completes loading and decoding of audio data, if it determines that it has received notification information sent by the image thread, it can be determined that the image thread has also completed loading and decoding of image data, and the audio thread can start playing audio data.

[0081] In actual applications, due to the amount and format of audio data and image data, the time taken for decoding audio data and image data may be different. Even if the audio data and image data are loaded at the same time, the different decoding times may cause the audio data and image data to start playing at different time points, resulting in the problem of audio and video being out of sync.

[0082] In an embodiment of the present application, after each thread completes loading and decoding of the data, it plays the data after determining that another thread has completed loading and decoding of the data. This can eliminate the time difference caused by the different decoding times of the audio data and the image data, thereby further reducing the probability of audio and video being out of sync.

[0083] Optionally, two threads are started to load the image data and audio data of the video to be played respectively, including:

[0084] Start one of the two threads to load first data; wherein the first data is the one with larger data volume between the image data and the audio data;

[0085] After starting one thread, another thread of the two threads is started after a target time interval to load second data; wherein the second data is another data of the image data and the audio data except the first data.

[0086] In one embodiment, after creating two threads, the electronic device may first start a thread to start loading the one with a larger data volume between the image data and the audio data, and then start another thread to load the other data after an interval of a target duration. Exemplarily, after receiving a video playback instruction, the electronic device may obtain the encoding information of the audio data, determine the data volume of the audio data according to the encoding information of the audio data, and obtain the encoding information of the image data, and determine the data volume of the image data according to the encoding information of the image data. Then, the data volume of the audio data and the data volume of the image data are compared. If the data volume of the audio data is less than the data volume of the image data, it can be determined that the first data with a larger data volume is the image data, and the data with a smaller data volume is the second data. Afterwards, the electronic device may first start a thread to load the image data with a larger data volume. After starting one thread, another thread is started after an interval of a target duration to load the audio data with a smaller data volume.

[0087] Similarly, if it is determined that the amount of audio data is greater than the amount of image data, the first data can be determined to be audio data and the second data to be image data. Afterwards, the electronic device can first start a thread to load audio data, and then start another thread to load image data after a target time interval.

[0088] In actual applications, the more threads an electronic device starts at the same time, the greater the power consumption of the electronic device.

[0089] In an embodiment of the present application, based on the difference in data volume between audio data and image data, a thread is started first to load data with a large data volume, and then another thread with a small data volume is started after a certain interval. This can shorten the time it takes for the two threads to be started at the same time and reduce the power consumption of the electronic device.

[0090] Optionally, before starting another thread of the two threads to load the second data after the target time interval, the method may further include:

[0091] determining a first difference between the amount of data of the first data and the amount of data of the second data;

[0092] The target duration is determined according to the first difference; wherein the first difference is positively correlated with the target duration.

[0093] Exemplarily, after determining that the data volume of the image data is greater than the data volume of the audio data, the electronic device may calculate the difference between the data volume of the audio data and the amount of the image data to obtain a first difference. Then, the electronic device may calculate the target duration based on the first difference, and the larger the first difference, the longer the target duration. For example, a proportional coefficient between the target duration and the first difference may be preset, and the proportional coefficient is greater than 1. After each determination of the first difference, the product of the first difference and the proportional coefficient may be calculated, and the product may be used as the target duration.

[0094] The above are merely illustrative examples, and the method for determining the target duration based on the difference between the data volume of the first data and the data volume of the second data may include but is not limited to the above examples.

[0095] In an embodiment of the present application, the difference between the data volume of the first data and the data volume of the second data is set to be positively correlated with the target duration, which can shorten the duration of the two threads starting and running at the same time as much as possible, thereby reducing the power consumption of the electronic device.

[0096] Optionally, after each thread completes data loading, if it determines that another thread has completed data loading, it plays the data loaded by itself, including:

[0097] determining a second difference between the amount of data of the image data and the amount of data of the audio data;

[0098] In the case where the second difference is greater than the preset difference, after each thread completes data loading, if it is determined that another thread has completed data loading, it plays the data loaded by itself.

[0099] Among them, the preset difference can be a smaller value. When the second difference is less than or equal to the preset difference, it means that the data volume of the image data and the data volume of the audio data are slightly different, and the probability of audio and video being out of sync is small. When the second difference is greater than the preset difference, it means that the data volume of the image data and the data volume of the audio data are significantly different, and the probability of audio and video being out of sync is high.

[0100] In one embodiment, after starting two threads, the difference between the data volume of image data and the data volume of audio data (i.e., the second difference) can be determined first, and then when the second difference is greater than the preset difference, steps 101 to 102 are executed, and when the second difference is less than or equal to the preset difference, each thread directly plays the loaded data after completing data loading.

[0101] In an embodiment of the present application, when the difference between the data volume of image data and the data volume of audio data is greater than a preset difference, each thread plays the data loaded by itself after completing data loading and determining that another thread has completed data loading. When the difference between the data volume of image data and the data volume of audio data is less than or equal to the preset difference, each thread directly plays the data loaded by itself after completing data loading, which can simplify the audio playback process.

[0102] See also Figure 2 , Figure 2 It is a flowchart of a video playback method provided in an embodiment of the present application.

[0103] like Figure 2 As shown, the method comprises the following steps:

[0104] Step 201: Create a lock and set the number of lock times.

[0105] Step 202: Create and start two threads.

[0106] In this embodiment, after receiving the video playback instruction, the electronic device first sets the number of lock times, the initial value of which can be set to 2, and a lock can be created at the same time. After that, the electronic device can create and start two threads, one thread for loading and playing audio data, and the other thread for loading and playing image data. After each thread is started, steps 203 to 208 are executed.

[0107] Step 203: Check whether the data loading is completed.

[0108] Step 204: Acquire the lock and decrement the number of lock attempts by 1.

[0109] Step 205: Release the lock.

[0110] Step 206: Determine whether the number of lock times is 0.

[0111] In this embodiment, after each thread is started, it loads the corresponding data and continuously monitors whether the data loading is completed. After the data loading is completed, the lock is first acquired to lock the loading times, then the locking times are reduced by 1, and the lock is released to unlock the locking times, and then it is determined whether the locking times is 0.

[0112] Step 207: Play the loaded data.

[0113] In this embodiment, each thread can play the loaded data after determining that the number of lock times is 0. When the number of lock times is decremented by 1 and it is determined that the number of lock times is not 0, it can enter the waiting state and continue to monitor the number of lock times. When the number of lock times is detected to be 0, the loaded data is played.

[0114] See also Figure 3 , Figure 3 It is a structural schematic diagram of a video playback device provided in an embodiment of the present application.

[0115] like Figure 3 As shown, the device 300 includes:

[0116] The loading module 301 is used to start two threads to load the image data and audio data of the video to be played respectively;

[0117] The playing module 302 is used for each thread to play the data loaded by itself to play the video to be played after completing data loading if it is determined that another thread has completed data loading.

[0118] Optionally, the playing module 302 is used to obtain the mark object created before the two threads are started; after performing a preset operation on the mark object, if it is determined that the mark object has undergone the preset operation twice, play the data loaded by itself.

[0119] Optionally, the marking object is the number of lock times, and the playback module 302 is specifically used to obtain the lock of the number of lock times to lock the number of lock times; wherein, the lock is created before the two threads are started, and the initial value of the number of lock times indicates that the image data and the audio data have not been loaded; after performing the preset operation on the number of lock times, releasing the lock to unlock the number of lock times; wherein the preset operation is used to increase the number of lock times by a preset value or decrease the preset value; after releasing the lock, if it is determined that the number of lock times reaches the target value, the data loaded by itself is played; wherein the target value indicates that both the image data and the audio data have been loaded.

[0120] Optionally, the playback module 302 is specifically used to send a notification to the other thread if the other thread is in a waiting state, so as to notify the other thread to play the loaded data at a target time after the current time; wherein the current time is separated from the target time by a preset time length; after sending the notification to the other thread, the loaded data is played at the target time.

[0121] Optionally, the playing module 302 is specifically used to decode the loaded data; after the decoding is completed, if it is determined that another thread has finished loading the data and decoding, the data loaded by itself is played.

[0122] Optionally, the startup module 301 is specifically used to start one of the two threads to load first data; wherein, the first data is the one with larger data volume between the image data and the audio data; after starting one of the threads, start the other of the two threads to load second data after a target time interval; wherein, the second data is the other data between the image data and the audio data except the first data.

[0123] Optionally, the startup module 301 is further used to determine a first difference between the data volume of the first data and the data volume of the second data; determine the target duration according to the first difference; wherein the first difference is positively correlated with the target duration.

[0124] Optionally, the playback module 302 is specifically used to determine a second difference between the data volume of the image data and the data volume of the audio data; when the second difference is greater than a preset difference, after each thread completes data loading, if it is determined that another thread has completed data loading, it plays the data loaded by itself.

[0125] Figure 4 It is a structural schematic diagram of an electronic device provided in an embodiment of the present application.

[0126] For example, Figure 4 As shown, the electronic device 400 includes: a memory 401 and a processor 402, wherein the memory 401 stores an executable program code 4011, and the processor 402 is used to call and execute the executable program code 4011 to perform a video playback method.

[0127] In addition, an embodiment of the present application also protects a video playback device, which may include a memory and a processor, wherein the memory stores executable program code, and the processor is used to call and execute the executable program code to perform a video playback method provided by an embodiment of the present application.

[0128] In this embodiment, the functional modules of the device can be divided according to the above method example. For example, each functional module can be corresponded, or two or more functions can be integrated into one processing module. The above integrated module can be implemented in the form of hardware. It should be noted that the division of modules in this embodiment is schematic and is only a logical function division. There may be other division methods in actual implementation.

[0129] In the case of dividing each functional module according to each function, the device may also include a determination module and a control module, etc. It should be noted that all relevant contents of each step involved in the above method embodiment can be referred to the functional description of the corresponding functional module, which will not be repeated here.

[0130] It should be understood that the device provided in this embodiment is used to execute the above-mentioned video playback method, and thus can achieve the same effect as the above-mentioned implementation method.

[0131] In the case of an integrated unit, the device may include a processing module and a storage module. When the device is applied to an electronic device, the processing module may be used to control and manage the actions of the electronic device. The storage module may be used to support the electronic device to execute mutual program codes, etc.

[0132] The processing module may be a processor or a controller, which may implement or execute various exemplary logic blocks, modules and circuits disclosed in the present application. The processor may also be a combination that implements computing functions, such as a combination of one or more microprocessors, a combination of digital signal processing (DSP) and a microprocessor, etc. The storage module may be a memory.

[0133] In addition, the device provided in the embodiments of the present application may specifically be a chip, component or module, and the chip may include a connected processor and memory; wherein the memory is used to store instructions, and when the processor calls and executes the instructions, the chip can execute a video playback method provided in the above embodiments.

[0134] This embodiment also provides a readable storage medium, in which executable program code is stored. When the executable program code is run on an electronic device, the electronic device executes the above-mentioned related method steps to implement a video playback method provided by the above embodiment.

[0135] This embodiment further provides an electronic device program product. When the electronic device program product is run on an electronic device, the electronic device executes the above-mentioned related steps to implement a video playback method provided by the above embodiment.

[0136] Among them, the device, readable storage medium, electronic device program product or chip provided in this embodiment are all used to execute the corresponding methods provided above. Therefore, the beneficial effects that can be achieved can refer to the beneficial effects in the corresponding methods provided above and will not be repeated here.

[0137] Through the description of the above implementation methods, technical personnel in the relevant field can understand that for the convenience and simplicity of description, only the division of the above-mentioned functional modules is used as an example. In actual applications, the above-mentioned functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above.

[0138] In the 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 modules or units is only a logical function division, and there may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another 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.

[0139] The above contents are only specific implementation methods of the present application, but the protection scope of the present application is not limited thereto. Any technician familiar with the technical field can easily think of changes or substitutions within the technical scope disclosed in the present application, which should be included in the protection scope of the present application. Therefore, the protection scope of the present application should be based on the protection scope of the claims.

Claims

1. A video playback method, characterized in that: The method comprises: Start two threads to load the image data and audio data of the video to be played respectively; After each of the threads completes data loading, if it is determined that another of the threads has completed data loading, it plays the data loaded by itself to play the video to be played.

2. The method according to claim 1, characterized in that If it is determined that another thread has completed data loading, then playing the data loaded by itself includes: Get the marker object created before the two threads are started; After performing a preset operation on the marked object, if it is determined that the marked object has undergone the preset operation twice, the data loaded by itself is played.

3. The method according to claim 2, characterized in that The marking object is the number of lock times. After performing a preset operation on the marking object, if it is determined that the marking object has undergone the preset operation twice, playing the data loaded by itself includes: Acquire the lock of the locking number to lock the locking number; wherein the lock is created before the two threads are started, and the initial value of the locking number indicates that the image data and the audio data have not been loaded; After performing the preset operation on the number of locking times, releasing the lock to unlock the number of locking times; wherein the preset operation is used to increase the number of locking times by a preset value or decrease the preset value; After releasing the lock, if it is determined that the number of lock times reaches a target value, the loaded data is played; wherein the target value indicates that both the image data and the audio data have been loaded.

4. The method according to claim 1, characterized in that The playing of the data loaded by itself includes: If the other thread is in a waiting state, a notification is sent to the other thread to notify the other thread to play the loaded data at a target time after the current time; wherein the current time and the target time are separated by a preset time length; After sending the notification to the other thread, the loaded data is played at the target time.

5. The method according to claim 1, characterized in that If it is determined that another thread has completed data loading, then playing the data loaded by itself includes: Decode the loaded data; After the decoding is completed, if it is determined that another thread has finished loading the data and decoding, the data loaded by itself is played.

6. The method according to claim 1, characterized in that The step of starting two threads to respectively load the image data and the audio data of the video to be played includes: Starting one of the two threads to load first data; wherein the first data is the one with larger data volume between the image data and the audio data; After starting one of the threads, another of the two threads is started after a target time interval to load second data; wherein the second data is another data of the image data and the audio data except the first data.

7. The method according to claim 6, characterized in that Before starting another of the two threads to load the second data after the interval target duration, the method further includes: determining a first difference between the amount of the first data and the amount of the second data; The target duration is determined according to the first difference; wherein the first difference is positively correlated with the target duration.

8. The method according to any one of claims 1 to 7, characterized in that After each of the threads completes data loading, if it is determined that another thread has completed data loading, then the loaded data is played, including: determining a second difference between the amount of data of the image data and the amount of data of the audio data; In the case where the second difference is greater than the preset difference, after each thread completes data loading, if it is determined that another thread has completed data loading, it plays the data loaded by itself.

9. A video playback device, characterized in that: The device comprises: A loading module is used to start two threads to load the image data and audio data of the video to be played respectively; The playing module is used for each thread to play the data loaded by itself after completing data loading, so as to play the video to be played if it is determined that another thread has completed data loading.

10. An electronic device, characterized in that: The electronic device comprises: A memory for storing executable program codes; A processor, configured to call and run the executable program code from the memory, so that the electronic device executes the method according to any one of claims 1 to 7.

Citation Information

Patent Citations

  • Method for simultaneously and synchronously playing multiple paths of audios and videos

    CN103731625A

  • Video display method, video player and electronic device

    CN105898501A

  • Audio and video synthesis method and device, equipment and storage medium

    CN114979766A

  • Method and device for converting text into video, electronic equipment and readable storage medium

    CN115034181A

  • Display device and audio and video data playing method

    CN117812397A