A video playing method, device and electronic equipment

By starting two threads to load image and audio data separately during video playback, and then playing them simultaneously after both threads have finished loading, the problem of audio-visual asynchrony is solved, achieving higher synchronization and playback consistency.

CN119815093BActive Publication Date: 2026-04-10GREAT WALL MOTOR CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
GREAT WALL MOTOR CO LTD
Filing Date
2024-12-17
Publication Date
2026-04-10

AI Technical Summary

Technical Problem

During video playback, storing image and audio data separately causes audio-visual desynchronization.

Method used

Two threads are started to load image data and audio data respectively. After each thread finishes loading its data, it checks whether the other thread has finished loading its data. Then, when it confirms that the other thread has also finished loading its data, it plays the data it has loaded.

Benefits of technology

It reduces the probability of audio and video desynchronization, ensures that audio and image data start playing at the same time, and improves the synchronization of video playback.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119815093B_ABST
    Figure CN119815093B_ABST
Patent Text Reader

Abstract

The application provides a video playing method and device and electronic equipment, the method is applied to the technical field of video processing, and the method comprises the following steps: in a video playing process, two threads are started to load image data and audio data of a video to be played, each thread plays the data loaded by the thread after the data loading is completed, and the image data and the audio data can be played after the loading of the image data and the audio data is completed. The video playing method provided in the application can start to play the audio data and the image data at the same time even if the loading of the audio data and the image data is not completed at the same time, so that the probability of the occurrence of the situation that the audio and the image are not synchronized can be reduced.
Need to check novelty before this filing date? Find Prior Art

Description

TECHNICAL FIELD

[0001] The present application relates to the technical field of video processing, and more particularly, to a video playing method, device and electronic equipment. BACKGROUND

[0002] A video usually includes both image data and audio data, and in order to reduce storage space and improve transmission efficiency, the image data and the audio data can be stored separately. When the image data and the audio data are stored separately, in the video playing process, the image data and the audio data are loaded from two locations respectively for playing, and the problem of audio-visual asynchronization can occur. SUMMARY

[0003] The present application provides a video playing method, device and electronic equipment, which can reduce the probability of occurrence of the problem of audio-visual asynchronization in the video playing process.

[0004] In a first aspect, a video playing method is provided, which includes:

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

[0006] after each thread completes the data loading, if it is determined that the other thread completes the data loading, the data loaded by the thread is played to play the video to be played.

[0007] In the present application, in the video playing process, two threads are started to load image data and audio data of a video to be played respectively, and after each thread completes the data loading, the data loaded by the thread is played when it is determined that the other thread completes the data loading, so that the image data and the audio data can be played after the image data and the audio data are both loaded. In this way, even if the image data and the audio data are not loaded at the same time, the image data and the audio data can be played at the same time, so that the probability of occurrence of the problem of audio-visual asynchronization can be reduced.

[0008] Optionally, the playing of the data loaded by the thread if it is determined that the other thread completes the data loading includes: obtaining a mark object created before the two threads are started; after a preset operation is performed on the mark object once, if it is determined that the mark object has undergone the preset operation twice, the data loaded by the thread is played.

[0009] Optionally, the playing of the data loaded by the thread if it is determined that the other thread completes the data loading includes: obtaining a mark object created before the two threads are started; after a preset operation is performed on the mark object once, if it is determined that the mark object has undergone the preset operation twice, the data loaded by the thread is played.

[0010] In the embodiments of the present application, the image data and the audio data are marked by the operation times of the marking object to mark whether the image data and the audio data are loaded, so that the two threads can play the loaded data when it is determined that the other thread has completed the data loading, thereby the audio data and the image data can be played simultaneously when the audio data and the image data are both loaded.

[0011] Optionally, the marking object is a lock number, and after a preset operation is performed on the marking object, if it is determined that the marking object has been operated twice, the loaded data is played, including: acquiring a lock of the lock number to lock the lock number; wherein the lock is created before the two threads are started, and an initial value of the lock number indicates that the image data and the audio data are not loaded; after the preset operation is performed on the lock number, the lock is released to unlock the lock number; wherein the preset operation is used to increase or decrease the lock number by a preset value; after the lock is released, if it is determined that the lock number reaches a target value, the loaded data is played; wherein the target value indicates that the image data and the audio data are loaded.

[0012] In the embodiments of the present application, when the two threads operate the lock number, the lock number can be locked by a lock to prevent the two threads from operating the lock number simultaneously, thereby the error of the lock number can be avoided, and the problem that the image data and the audio data are played at different times due to the error of the lock number can be prevented.

[0013] Optionally, the playing of the loaded data includes: if the other thread is in a waiting state, a notification is sent to the other thread to inform the other thread to play the loaded data at a target time after a current time; wherein the current time and the target time are separated by a preset time length; after the notification is sent to the other thread, the loaded data is played at the target time.

[0014] In the embodiments of the present application, when each thread plays the loaded data, the loaded data is played at a target time after a current time, and the other thread is informed to play the loaded data at the target time, so that the two threads can play the loaded audio data at the target time, thereby the probability of the audio and the image being out of synchronization can be reduced.

[0015] Optionally, if it is determined that the other thread has completed the data loading, the loaded data is played, including: decoding the loaded data; after the decoding is completed, if it is determined that the other thread has completed the data loading and the decoding, the loaded data is played.

[0016] In the embodiments of the present application, after each thread completes loading and decoding of data, and after it is determined that another thread completes loading and decoding of data, the data is played, which can eliminate the time difference caused by different decoding times of audio data and image data, thereby further reducing the probability of occurrence of audio-visual asynchronization.

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

[0018] In the embodiments of the present application, based on the difference between the data amounts of the audio data and the image data, one thread is started to load data with a larger data amount, and another thread is started to load data with a smaller data amount after a certain time interval, which can shorten the time interval of starting of the two threads, thereby reducing the power consumption of the electronic device.

[0019] Optionally, before the starting of another of the two threads to load second data after the target time interval, the method further comprises: determining a first difference between the data amount of the first data and the data amount of the second data; determining the target time interval according to the first difference; wherein the first difference is positively correlated with the target time interval.

[0020] In the embodiments of the present application, the difference between the data amount of the first data and the data amount of the second data is positively correlated with the target time interval, which can shorten the time interval of starting of the two threads as much as possible, thereby reducing the power consumption of the electronic device.

[0021] Optionally, after each of the threads completes loading of data, if it is determined that another of the threads completes loading of data, the data loaded by the thread is played, which comprises: determining a second difference between the data amount of the image data and the data amount of the audio data; in a case where the second difference is greater than a preset difference, after each of the threads completes loading of data, if it is determined that another of the threads completes loading of data, the data loaded by the thread is played.

[0022] In the embodiment of the present application, when the difference between the data amount of the image data and the data amount of the audio data is greater than a preset difference, each thread plays the data loaded by itself after determining that another thread completes data loading; and when the difference between the data amount of the image data and the data amount of the audio data is less than or equal to the preset difference, each thread directly plays the data loaded by itself after completing data loading, so that the audio playing process can be simplified.

[0023] In a second aspect, a video playing device is provided, which comprises:

[0024] a loading module, configured to start two threads to load image data and audio data of a video to be played respectively;

[0025] a playing module, configured to, after each thread completes data loading, play the data loaded by itself if it is determined that another thread completes data loading, so as to play the video to be played.

[0026] In a third aspect, an electronic device is provided, which comprises a memory configured to store executable program code, and a processor configured to call and run the executable program code from the memory, so that the electronic device executes the method in any possible implementation manner of the first aspect.

[0027] In a fourth aspect, an electronic device program product is provided, which comprises executable program code, when the executable program code is run on an electronic device, so that the electronic device executes the method in any possible implementation manner of the first aspect.

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

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

[0030] Figure 2 is a flowchart of a video playing method provided by the embodiment of the present application;

[0031] Figure 3 is a structural schematic diagram of a video playing device provided by the embodiment of the present application;

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

[0033] The technical solutions in the present application will be described clearly and exhaustively in combination with the drawings. In the description of the embodiments of the present application, unless otherwise specified, " / " represents the meaning of or, for example, A / B can represent A or B: "and / or" in the text is only a description of the association relationship of the associated objects, which means that there can be three relationships, for example, A and / or B, which can represent: A exists alone, A and B exist together, and B exists alone, in addition, in the description of the embodiments of the present application, "multiple" means two or more than two.

[0034] Hereinafter, the terms "first", "second" are only for descriptive purposes, and cannot be understood as implying or suggesting relative importance or implicitly indicating the number of indicated technical features. Therefore, the features defined with "first", "second" can explicitly or implicitly include one or more of the features.

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

[0036] Since the video includes audio data and image data, when playing the video, two threads (Thread) are generally started at the same time, one thread loads image data from the storage location of the image data to the buffer and then plays, and the other thread loads audio data from the storage location of the audio data to the buffer and then. The data amount of the image data is generally greater than that of the audio data, so the time for loading the image data is generally longer than that for loading the audio data, so the audio data is often loaded first and starts playing before the image data is loaded, resulting in out-of-sync of audio and video.

[0037] To solve the above technical problems, the embodiment of the present application provides a video playing method, which can be applied in an electronic device, such as a mobile phone, an electronic device, a tablet computer, a host terminal (HUT) in a vehicle, and the like. However, the application is not limited to this. In the method, two threads are started to load image data and audio data in a video (hereinafter referred to as a to-be-played video) when the video is played. After each thread completes data loading, it is determined whether the other thread completes data loading. After it is determined that the other thread also completes data loading, the data loaded by each thread is played simultaneously with the other thread, so that even if the audio data and the image data are not loaded at the same time, the two threads can start playing the audio data and the image data at the same time, thereby reducing the probability of occurrence of audio and image out-of-sync.

[0038] Referring to Figure 1 , Figure 1 is a step flowchart of a video playing method provided by the embodiment of the present application. The execution subject of the method can be an electronic device, such as a mobile phone, an electronic device, a tablet computer, a host terminal (HUT) in a vehicle, and the like. Figure 1 As shown in the figure, the method comprises the following steps:

[0039] Step 101, two threads are started to load image data and audio data in a to-be-played video.

[0040] Exemplarily, when the electronic device receives a video playing instruction input by a user, the electronic device can determine a to-be-played video indicated by the video playing instruction, and then create two threads and start the two threads to load image data and audio data in the to-be-played video.

[0041] In an implementation, after the two threads are created, the electronic device can start the two threads simultaneously. One thread (hereinafter referred to as an audio thread) corresponds to the audio data, accesses a storage location of the audio data, and loads the audio data from the storage location to a buffer. The other thread (hereinafter referred to as an image thread) corresponds to the image data, accesses a storage location of the image data, and loads the image data from the storage location to a buffer.

[0042] In actual application, the data amount of the image data in the same video is generally greater than the data amount of the audio data. When the two threads are started simultaneously, the audio thread can complete data loading before the image thread. Of course, the data amount of the audio data in some videos can also be greater than the data amount of the image data. When the two threads are started simultaneously, the image thread can complete data loading before the audio thread.

[0043] Step 102, after each thread completes data loading, if it is determined that the other thread completes data loading, the data loaded by the thread is played to play the to-be-played video.

[0044] In an implementation, each thread can send a notification information to another thread after completing the data loading. Correspondingly, each thread can determine that another thread completes the data loading after receiving the notification information sent by another thread after completing the data loading. In combination with the above example, after the audio thread and the image thread are started simultaneously, the audio thread can determine whether the notification information sent by the image thread is received after completing the loading of the audio data. If the notification information sent by the image thread is not received, the audio thread can send the notification information to the image thread and enter a waiting state. After the audio thread enters the waiting state, if the notification information sent by the image thread after completing the data loading is received, the audio thread can start playing the loaded audio data. In addition, if the audio thread determines that the notification information sent by the image thread has been received after completing the loading of the audio data, the audio thread can determine that the image thread also completes the loading of the image data. At this time, the audio thread can start playing the audio data.

[0045] Correspondingly, the image thread can determine whether the notification information sent by the audio thread is received after completing the loading of the image data. If the notification information sent by the audio thread is not received, the image thread can send the notification information to the audio thread and enter a waiting state. After the image thread enters the waiting state, if the notification information sent by the audio thread after completing the loading of the audio data is received, the image thread can start playing the loaded image data. In addition, if the image thread determines that the notification information sent by the audio thread has been received after completing the loading of the image data, the image thread can determine that the audio thread also completes the loading of the audio data. At this time, the image thread can start playing the image data.

[0046] In this way, each thread can play the data loaded by itself after completing the loading of the data and determining that another thread also completes the loading of the data. The audio data can be played after the loading of the image data is completed, and the image data can be played after the loading of the audio data is completed. The problem of audio-visual asynchronization can be avoided.

[0047] In the embodiments of the present application, in the process of playing a video, two threads are started to load the image data and the audio data of the video to be played. Each thread can play the data loaded by itself after completing the loading of the data and determining that another thread also completes the loading of the data. The image data and the audio data can be played after the loading of the image data and the audio data is completed. In this way, even if the loading of the audio data and the image data is not completed at the same time, the audio data and the image data can be played at the same time. Therefore, the probability of the occurrence of audio-visual asynchronization can be reduced.

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

[0049] A mark object created before the two threads are started is obtained.

[0050] After a preset operation is performed on the mark object once, if it is determined that the mark object has undergone two preset operations, the data loaded by the self is played.

[0051] In an embodiment, the electronic device can create a mark object while creating two threads, and after starting the two threads, each thread can perform a preset operation on the mark object after completing data loading, and then determine whether the mark object has undergone two preset operations. If the mark object has undergone two preset operations, it is determined that the two threads have each performed an operation on the mark object, i.e., the two threads have each completed data loading. After determining that the mark object has undergone two preset operations, each thread can start playing the data loaded by the self.

[0052] Exemplarily, the mark object can be a shared variable. When the shared variable is created, the electronic device can set an initial value of the shared variable, which indicates that the two threads have not completed data loading. For example, the initial value of the shared variable can be set to 0, and the preset operation can be, for example, an add 1 operation. After starting the audio thread and the image thread, the audio thread can perform an add 1 operation on the shared variable after completing loading of audio data, 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, and the shared variable has undergone two preset operations. At this time, it can be determined that the image thread has completed loading of image data, and the audio thread can start playing the audio data loaded.

[0053] Conversely, when the audio thread determines that the shared variable is 1, it is determined that the image thread has not performed an add 1 operation on 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 loading of image data, and the audio thread enters a waiting state. After entering the waiting state, the audio thread continues to monitor the shared variable. When it is monitored that the shared variable becomes 2, it is determined that the image thread has completed loading of image data, and starts playing the audio data. At this time, the image thread can determine that the shared variable is 2, and the audio thread has completed loading of audio data. The image thread can start playing the image data loaded.

[0054] Correspondingly, after completing loading of image data, the image thread can perform an add 1 operation on 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 add 1 operation on the shared variable, and the shared variable has undergone two preset operations. At this time, it can be determined that the audio thread has completed loading of audio data, and the image thread can start playing the image data loaded.

[0055] Conversely, when the image thread determines that the shared variable is 1, it is determined that the audio thread does not perform the add 1 operation on the shared variable, and the shared variable only undergoes a preset operation once, at which time it can be determined that the audio thread does not complete the loading of the audio data, and the image thread enters a waiting state. After entering the waiting state, the image thread continues to monitor the shared variable, and when it is monitored that the shared variable becomes 2, it is determined that the audio thread completes 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, and the image thread completes the loading of the image data, and the audio thread can start playing the loaded audio data.

[0056] In the embodiments of the present application, the operation number of the marking object is used to mark whether the image data and the audio data are completed loading, which can facilitate the two threads to play the loaded data of themselves when determining that the other party completes the data loading, so that the audio data and the image data can be played simultaneously when the audio data and the image data are both completed loading.

[0057] Optionally, the marking object can be a lock number, and after a preset operation is performed on the marking object, if it is determined that the marking object undergoes two preset operations, the loaded data of the self is played, including:

[0058] A lock of the lock number is acquired to lock the lock number; wherein the lock is created before the two threads are started, and the initial value of the lock number indicates that the image data and the audio data are both not completed loading;

[0059] After the preset operation is performed on the lock number, the lock is released to unlock the lock number; wherein the preset operation is used to increase or decrease the lock number by a preset value;

[0060] After the lock is released, if it is determined that the lock number reaches a target value, the loaded data of the self is played; wherein the target value indicates that the image data and the audio data are both completed loading.

[0061] In an implementation manner, before the two threads are started, the electronic device can create the lock number and set an initial value of the lock number, and the initial value indicates that the two threads are both not completed data loading, and a lock (Lock) of the lock number can be created. After each thread completes the data loading, the lock of the lock number is acquired first, and then a preset operation is performed on the lock number.

[0062] Exemplarily, the initial value of the locking times can be set as 2, the preset operation can be reducing the locking times by 1 (1 is the preset value), and when the locking times is 0 (i.e. the target value), it indicates that both threads complete the data loading. After starting the audio thread and the image thread, the audio thread can acquire the lock of the locking times after completing the loading of the audio data. If the lock of the locking times is acquired, it indicates that the locking times is not locked by the image thread, and the audio thread can lock the locking times through the acquired lock to prevent the image thread from operating the locking times at this time. At this time, the audio thread can reduce the locking times by 1, and after completing the reducing by 1, the audio thread releases the lock to unlock the locking times. Then, the audio thread judges whether the locking times is 0. If it is determined that the locking times is 0, it indicates that the image thread completes the loading of the image data, and the audio data can start playing the audio data. If it is determined that the locking times is 1, it indicates that the image thread does not complete the loading of the image data, and the audio thread enters the waiting state.

[0063] After entering the waiting state, the audio thread continues to monitor the locking times. When it is monitored that the locking times becomes 0, it is determined that the image thread completes the loading of the image data, and starts playing the audio data. At this time, the image thread can determine that the locking times is 0, the audio thread completes the loading of the audio data, and the image thread can start playing the loaded image data.

[0064] Correspondingly, the image thread can acquire the lock of the locking times after completing the loading of the image data. If the lock of the locking times is acquired, it indicates that the locking times is not locked by the audio thread, and the image thread can lock the locking times through the acquired lock to prevent the audio thread from operating the locking times at this time. At this time, the image thread can reduce the locking times by 1, and after completing the reducing by 1, the image thread releases the lock to unlock the locking times. Then, the image thread judges whether the locking times is 0. If it is determined that the locking times is 0, it indicates that the audio thread completes the loading of the image data, and the image data can start playing the image data. If it is determined that the locking times is 1, it indicates that the audio thread does not complete the loading of the audio data, and the image thread enters the waiting state.

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

[0066] In the embodiments of the present application, when the two threads operate on the locking times, the locking times can be locked by the lock to prevent the two threads from operating on the locking times simultaneously, so that the locking times determination error can be avoided, and thus the problem that the image data and the audio data start to play at different time due to the locking times determination error can be prevented.

[0067] Optionally, the data loaded by the thread itself is played, including:

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

[0069] After the notification is sent to the other thread, the data loaded by the thread itself is played at the target time.

[0070] In an embodiment, after each thread completes data loading and determines that the other thread completes data loading, the other thread in the waiting state can be informed to start playing data at a target time separated from a current time by a preset time length.

[0071] For example, the preset time length is 200 milliseconds. When the audio thread completes data loading before the image thread, the audio thread determines that the image thread does not complete data loading when the data loading is completed, and enters the waiting state. After the image thread completes loading of the image data, in the case that the audio thread completes data loading, a target time separated from a current time by 200 milliseconds can be determined, and then a notification is sent to the audio thread in the waiting state to inform the audio thread to start playing audio data at the target time after waiting for 200 milliseconds after receiving the notification. After sending the notification, the image thread waits for 200 milliseconds first, and then starts playing the image data. Correspondingly, the audio thread switches from the waiting state to the running state after receiving the notification, and then waits for 200 milliseconds first, and then starts playing the audio data at the target time after waiting for 200 milliseconds.

[0072] Similarly, when the image thread finishes data loading prior to the audio thread, the image thread enters a waiting state upon finishing data loading if it is determined that the audio thread has not finished data loading. After the audio thread finishes loading of audio data, if it is determined that the image thread has finished data loading, the audio thread can determine a target time that is 200 milliseconds after the current time, and then send a notification to the image thread, notifying the image thread to start playing image data at the target time 200 milliseconds after the image thread receives the notification. After sending the notification, the audio thread waits for 200 milliseconds and then starts playing audio data at the target time 200 milliseconds after the waiting. Correspondingly, after receiving the notification, the image thread switches from the waiting state to the running state, and then waits for 200 milliseconds and starts playing image data at the target time 200 milliseconds after the waiting.

[0073] The specific value of the preset time length can be set according to actual requirements, and the embodiment is not limited in this regard.

[0074] In the embodiment of the application, when each thread plays the data loaded by itself, the data loaded by itself is played at a target time after the current time, and another thread in a waiting state is notified to play the loaded data at the target time, which can enable the two threads to play the audio data loaded by themselves at the target time, thereby reducing the probability of occurrence of audio-visual asynchronization.

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

[0076] decoding the loaded data;

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

[0078] In one embodiment, after each thread finishes loading data, it decodes the data it loaded first, and after decoding is finished, if it determines that another thread has finished loading and decoding data, it starts playing the data it loaded and decoded. For example, after the audio thread finishes loading audio data, it can decode the audio data first, and after decoding is finished, it acquires a lock for the number of locks, and if it acquires the lock for the number of locks, it determines that the number of locks is not locked by the image thread, and the audio thread can lock the number of locks by the lock it acquired, preventing the image thread from operating on the number of locks at this time. At this time, the audio thread can perform a decrement operation on the number of locks, and after the decrement operation is finished, the audio thread releases the lock to unlock the number of locks. Then, the audio thread determines whether the number of locks is 0, and if it determines that the number of locks is 0, it determines that the image thread has finished loading and decoding image data, and the audio data can start playing the audio data. If it determines that the number of locks is 1, it determines that the image thread has not finished loading image data (or has finished loading but not decoding image data), and the audio thread enters a waiting state.

[0079] After entering the waiting state, the audio thread continues to monitor the number of locks, and when it monitors that the number of locks becomes 0, it determines that the image thread has finished loading and decoding image data, and starts playing the audio data. At this time, the image thread can determine that the number of locks is 0, and the audio thread has finished loading and decoding audio data, and the image thread can start playing the image data that has finished loading and decoding.

[0080] For example, when the audio thread finishes loading and decoding audio data, it determines whether it has received notification information sent by the image thread, and if it has not received the 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 it finishes loading and decoding image data, it can start playing the decoded audio data. Also, when the audio thread finishes loading and decoding audio data, if it determines that it has received notification information sent by the image thread, it can determine that the image thread has also finished loading and decoding image data, and at this time the audio thread can start playing the audio data.

[0081] In actual applications, due to the data volume and format of audio data and image data, the time taken by audio data and image data in the decoding process can also be different. Even if audio data and image data are loaded at the same time, the time taken by the decoding process can be different, which can cause audio data and image data to start playing at different time points, and further cause the problem of audio and video being out of sync.

[0082] In the embodiments of the present application, after each thread completes loading and decoding of data, and plays the data after determining that another thread completes loading and decoding of data, the time difference caused by different decoding times of audio data and image data can be eliminated, so that the probability of occurrence of audio-visual asynchronization can be further reduced.

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

[0084] One of the two threads is started to load first data; wherein the first data is one of the image data and the audio data with a larger data volume.

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

[0086] In an embodiment, after the two threads are created, the electronic device can first start one thread to start loading one of the image data and the audio data with a larger data volume, and then start another thread to load the other data after a target time interval. For example, after receiving a video playing instruction, the electronic device can obtain 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 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, and 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 second data with a smaller data volume is the audio data. Then, the electronic device can first start one thread to load the image data with a larger data volume. After starting the one thread, another thread is started to load the audio data with a smaller data volume after a target time interval.

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

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

[0089] In the embodiments of the present application, based on the difference between the data volumes of the audio data and the image data, one thread is first started to load the data with a larger data volume, and another data with a smaller data volume is started after a certain time interval, so that the time interval during which the two threads are started simultaneously can be shortened, and the power consumption of the electronic device can be reduced.

[0090] Optionally, before starting the other one of the two threads to load the second data after the interval target duration, the method can further include:

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

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

[0093] Exemplarily, after determining that the data amount of the image data is greater than the data amount of the audio data, the electronic device can calculate a difference between the data amount of the audio data and the data amount of the image data to obtain the first difference. Then, the electronic device can calculate the target duration according to the first difference, and the greater the first difference, the longer the target duration. For example, a proportional coefficient between the target duration and the first difference can be set in advance, and the proportional coefficient is greater than 1. After determining the first difference each time, the product of the first difference and the proportional coefficient can be calculated, and the product is taken as the target duration.

[0094] The above is only an exemplary example, and the method of determining the target duration according to the difference between the data amount of the first data and the data amount of the second data can include but is not limited to the above example.

[0095] In the embodiment of the application, the difference between the data amount of the first data and the data amount of the second data is positively correlated with the target duration, which can shorten the duration of the two threads running simultaneously as much as possible, thereby reducing the power consumption of the electronic device.

[0096] Optionally, after each thread completes data loading, if it is determined that the other thread completes data loading, the data loaded by itself is played, including:

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

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

[0099] The preset difference can be a small value. When the second difference is less than or equal to the preset difference, it indicates that the data amount of the image data and the data amount of the audio data are relatively small, and the probability of the occurrence of audio-visual asynchronization is relatively small. When the second difference is greater than the preset difference, it indicates that the data amount of the image data and the data amount of the audio data are relatively large, and the probability of the occurrence of audio-visual asynchronization is relatively large.

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

[0101] In the embodiment, when the difference between the data amount of the image data and the data amount of the audio data is greater than the preset difference, each thread plays the loaded data after the data loading is completed when it is determined that the other thread has completed the data loading, and when the difference between the data amount of the image data and the data amount of the audio data is less than or equal to the preset difference, each thread directly plays the loaded data after the data loading is completed, which can simplify the audio playing process.

[0102] Referring to Figure 2 , Figure 2 is a flowchart of a video playing method provided in the embodiment.

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

[0104] Step 201: creating a lock and setting a locking number.

[0105] Step 202: creating and starting two threads.

[0106] In the embodiment, after receiving a video playing instruction, the electronic device sets a locking number, and the initial value of the locking number can be set as 2, and a lock can be created. Then, the electronic device can create and start two threads, one of which is used to load and play audio data, and the other of which is used to load and play image data, and each thread executes steps 203 to 208 after being started.

[0107] Step 203: determining whether the data is loaded.

[0108] Step 204: acquiring the lock and performing a minus 1 operation on the locking number.

[0109] Step 205: releasing the lock.

[0110] Step 206: determining whether the locking number is 0.

[0111] In the embodiment, after being started, each thread loads corresponding data and continuously monitors whether the data is loaded. After the data is loaded, the lock is acquired to lock the loading number, and then the minus 1 operation is performed on the locking number, and the lock is released to unlock the locking number, and then it is determined whether the locking number is 0.

[0112] Step 207, playing the loaded data.

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

[0114] Referring to Figure 3 , Figure 3 is a structural schematic diagram of a video playing device provided in the embodiment.

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

[0116] A loading module 301 is configured to start two threads to load image data and audio data of a video to be played.

[0117] A playing module 302 is configured to, after each thread completes data loading, if it is determined that another thread completes data loading, play the data loaded by the thread.

[0118] Optionally, the playing module 302 is configured to acquire a mark object created before the two threads are started. After a preset operation is performed on the mark object, if it is determined that the mark object has undergone two preset operations, the data loaded by the thread is played.

[0119] Optionally, the mark object is a lock number, and the playing module 302 is specifically configured to acquire a lock of the lock number to lock the lock number. The lock is created before the two threads are started, and an initial value of the lock number indicates that the image data and the audio data are not loaded. After the preset operation is performed on the lock number, the lock is released to unlock the lock number. The preset operation is used to increase or decrease the lock number by a preset value. After the lock is released, if it is determined that the lock number reaches a target value, the data loaded by the thread is played. The target value indicates that the image data and the audio data are loaded.

[0120] Optionally, the playing module 302 is specifically configured to, if another thread is in a waiting state, send a notification to another thread to notify another thread to play the loaded data at a target time after a current time. The current time and the target time are separated by a preset time length. After the notification is sent to another thread, the data loaded by the thread is played at the target time.

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

[0122] Optionally, the loading module 301 is specifically configured to start one of the two threads to load first data; the first data is one of the image data and the audio data with a large data volume; after starting one of the two threads, the loading module 301 starts another of the two threads to load second data after a target time interval; the second data is the other of the image data and the audio data except the first data.

[0123] Optionally, the loading module 301 is further configured to determine a first difference between the data volume of the first data and the data volume of the second data; determine the target time interval according to the first difference; the first difference is positively correlated with the target time interval.

[0124] Optionally, the playing module 302 is specifically configured to determine a second difference between the data volume of the image data and the data volume of the audio data; in a case where 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, the playing module 302 plays the data loaded by itself.

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

[0126] For example, as shown in FIG. 4, the electronic device 400 includes a memory 401 and a processor 402, wherein the memory 401 stores executable program code 4011, and the processor 402 is configured to invoke and execute the executable program code 4011 to execute a video playing method. Figure 4

[0127] In addition, an embodiment of the present application also protects a video playing device, which can include a memory and a processor, wherein the memory stores executable program code, and the processor is configured to invoke and execute the executable program code to execute a video playing method provided by an embodiment of the present application.

[0128] The embodiment can divide the device into functional modules according to the above method examples, for example, each functional module can be provided, or two or more functions can be integrated into one processing module, and the integrated module can be implemented in the form of hardware. It should be noted that the division of modules in the embodiment is illustrative, and is only a logical function division, and another division mode can be used in actual implementation.

[0129] ​In the case of adopting the respective functional modules corresponding to the respective functions, the apparatus can further include a determination module, a control module, and the like. It should be noted that all related content of the respective steps involved in the above method embodiments can be cited to the function description of the corresponding functional modules, and will not be repeated here.

[0130] It should be understood that the apparatus provided by the embodiment is used to execute the above-mentioned video playing method, and thus can achieve the same effects as the above-mentioned implementation method.

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

[0132] The processing module can be a processor or a controller, which can realize or execute various exemplary logical blocks, modules and circuits described in combination with the disclosure of the present application. The processor can also be a combination of computing functions, such as one or more microprocessor combinations, digital signal processing (DSP) and microprocessor combinations, and the like. The storage module can be a memory.

[0133] In addition, the apparatus provided by the embodiment of the present application can be a chip, an assembly or a module. The chip can include a connected processor and a memory. The memory is used to store instructions, and when the processor calls and executes the instructions, the chip can execute the video playing method provided by the above-mentioned embodiment.

[0134] The embodiment also provides a readable storage medium, which stores executable program codes. When the executable program codes run on an electronic device, the electronic device executes the related method steps to realize the video playing method provided by the above-mentioned embodiment.

[0135] The embodiment also provides an electronic device program product. When the electronic device program product runs on an electronic device, the electronic device executes the related steps to realize the video playing method provided by the above-mentioned embodiment.

[0136] The apparatus, readable storage medium, electronic device program product or chip provided by the embodiment are used to execute the corresponding method provided above, and thus the beneficial effects that can be achieved can refer to the beneficial effects of the corresponding method provided above, and will not be repeated here.

[0137] Through the description of the above embodiments, those skilled in the art can understand that, for the convenience and brevity of description, only the division of the above functional modules is exemplified, and in actual application, the above functions can be completed by different functional modules according to needs, that is, the internal structure of the device is 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 device and method can be implemented in other ways. For example, the device embodiments described above are only illustrative, for example, the division of the modules or units is only a logical function division, and in actual implementation, there can be another division manner, for example, a plurality of units or components can be combined or integrated into another device, or some features can be ignored or not executed. In addition, the coupling or direct coupling or communication connection between the displayed or discussed ones can be indirect coupling or communication connection through some interfaces, devices or units, and can be electrical, mechanical or other forms.

[0139] The above is only a specific implementation of the present application, but the protection scope of the present application is not limited thereto, any person skilled in the art can easily think of changes or replacements within the technical range disclosed in the present application, which should be covered in the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.

Claims

1. A video playback method, characterized in that, The method includes: Start two threads to load the image and audio data of the video to be played, respectively; After each thread completes data loading, it obtains a marker object created before the two threads started; after performing a preset operation on the marker object once, if it is determined that the marker object has undergone two preset operations, it plays the data it loaded. Wherein, the marked object is the number of locks, and the step of playing the self-loaded data after performing a preset operation on the marked object once, if it is determined that the marked object has undergone two preset operations, includes: acquiring a lock on the number of locks to lock the number of locks; wherein, the lock is created before the two threads start, and the initial value of the number of locks indicates that neither the image data nor the audio data has been fully loaded; after performing the preset operation on the number of locks, releasing the lock to unlock the number of locks; wherein, the preset operation is used to increase or decrease the number of locks by a preset value; after releasing the lock, if it is determined that the number of locks has reached a target value, playing the self-loaded data; wherein, the target value indicates that both the image data and the audio data have been fully loaded.

2. The method as described in claim 1, characterized in that, The data loaded by the player itself includes: If the other thread is in a waiting state, a notification is sent to the other thread to notify it 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 interval; After sending the notification to another of the aforementioned threads, the data that it has loaded is played at the target time.

3. The method as described in claim 1, characterized in that, The process of starting two threads to load the image and audio data of the video to be played includes: One of the two threads is started to load the first data; wherein the first data is the larger of the image data and the audio data; After starting one of the threads, after a target time interval, another of the two threads is started to load the second data; wherein, the second data is another data other than the first data among the image data and the audio data.

4. The method as described in claim 3, characterized in that, Before starting the other of the two threads to load the second data after the target interval duration, the method further includes: Determine a first difference between the data volume of the first data and the data volume of the second data; The target duration is determined based on the first difference; wherein the first difference is positively correlated with the target duration.

5. The method according to any one of claims 1-4, characterized in that, After each thread completes data loading, it retrieves the marker object created before the two threads started, including: Determine a second difference between the amount of image data and the amount of audio data; If the second difference is greater than the preset difference, each thread, after completing data loading, obtains the marker object created before the two threads started.

6. A video playback device, characterized in that, The device includes: The loading module is used to start two threads to load the image data and audio data of the video to be played, respectively. The playback module is used to obtain a marker object created before the two threads started after each thread completes data loading; after performing a preset operation on the marker object once, if it is determined that the marker object has undergone two preset operations, then the data loaded by itself is played. The marker object is the number of lock attempts. The playback module is specifically used to acquire the lock of the number of lock attempts to lock the number of lock attempts. The lock is created before the two threads start. The initial value of the number of lock attempts indicates that neither the image data nor the audio data has been fully loaded. After performing the preset operation on the number of lock attempts, the lock is released to unlock the number of lock attempts. The preset operation is used to increase or decrease the number of lock attempts by a preset value. After releasing the lock, if it is determined that the number of lock attempts has reached a target value, the loaded data is played. The target value indicates that both the image data and the audio data have been fully loaded.

7. An electronic device, characterized in that, The electronic device includes: Memory, used to store executable program code; A processor for calling and running the executable program code from the memory, causing the electronic device to perform the method as described in any one of claims 1 to 5.

Citation Information

Patent Citations

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

    CN114979766A

  • Display device and audio and video data playing method

    CN117812397A