A video playback method, device, equipment and readable storage medium
By dynamically adjusting playback speed to avoid stuttering and maintain synchronization, the method addresses playback anomalies on low-performance devices, enhancing user experience.
Patent Information
- Application Number
- CN202211356064.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-11-01
- Publication Date
- 2025-07-15
- Estimated Expiration
- 2042-11-01
AI Technical Summary
When playing videos at high speeds on low-performance devices, video playback lags and black screens are prone to occur, and the existing technology is difficult to effectively solve.
By identifying whether the current video playback speed is the expected speed set by the user, if it is not the expected speed, gradually increase the playback speed and detect whether there is a lag. If it is a lag, gradually decrease the playback speed. Adjust the playback speed based on the actual decoded frame rate and the preset decoded frame rate, and set a frame drop strategy to ensure sound and picture synchronization.
On the premise of ensuring audio and video synchronization, gradually adjust the video playback speed to reduce the probability of video playback lag and black screen, and improve the smoothness of video playback.
Smart Images

Figure CN115695922B_ABST
Abstract
Description
Technical Field
[0001] This application relates to the field of video processing technologies, and particularly to a video playing method, apparatus, device, and readable storage medium. Background Art
[0002] Currently, when a user plays a video, they can set the playing speed according to their own needs. For example, set the video to play at 2 times the speed. Generally, after the user sets the speed, the device will play the video at the speed set by the user. If a video is played at a high multiple of the speed set by the user on a low-performance device, phenomena such as video stuttering and black screens are likely to occur.
[0003] Therefore, how to reduce the occurrence probability of abnormal phenomena such as video stuttering is a problem that needs to be solved by those skilled in the art. Summary of the Invention
[0004] The main purpose of this application is to provide a video playing method, apparatus, device, and readable storage medium, aiming to reduce the occurrence probability of abnormal phenomena such as video stuttering.
[0005] To achieve the above purpose, this application provides a video playing method, including:
[0006] Identify whether the playing speed of the currently played video is the desired playing speed; the desired playing speed is a value set by the user;
[0007] If the playing speed of the video is not the desired playing speed, increase the playing speed of the video by a first change value, and identify whether the video stutters;
[0008] If the video stutters, reduce the playing speed of the video.
[0009] Optionally, reducing the playing speed of the video includes:
[0010] Reduce the playing speed of the video by a second change value.
[0011] Optionally, reducing the playing speed of the video includes:
[0012] Calculate the actual decoding frame rate;
[0013] Reduce the playing speed of the video based on the actual decoding frame rate and the preset decoding frame rate of the video.
[0014] Optionally, before calculating the actual decoding frame rate, it further includes:
[0015] Count the total number of decoded frames from the moment when the playing speed is increased to the current moment;
[0016] If the total number of decoded frames is greater than the decoded frame number threshold and the difference between the timestamp of the current video frame and the current audio timestamp is greater than the preset target value, then execute the step of calculating the actual decoding frame rate; the decoded frame number threshold is the product of the preset decoding frame rate and the preset value.
[0017] Optionally, reducing the playback speed of the video based on the actual decoding frame rate and the preset decoding frame rate of the video includes:
[0018] Calculate the ratio of the actual decoding frame rate to the preset decoding frame rate;
[0019] Determine the difference between the ratio and the set value as the reduced playback speed.
[0020] Optionally, it further includes:
[0021] Before decoding each video frame in the video, initialize the number of consecutive frames that can be discarded;
[0022] Calculate the difference between the timestamp of the current video frame and the current audio timestamp;
[0023] If the difference is greater than the preset first threshold and not greater than the preset second threshold, then compare the number of consecutive frames that have been discarded with the current number of consecutive frames that can be discarded, and determine whether to discard the current video frame according to the comparison result; wherein, the preset first threshold is less than the preset second threshold.
[0024] Optionally, determining whether to discard the current video frame according to the comparison result includes:
[0025] When the number of consecutive frames that have been discarded is less than the current number of consecutive frames that can be discarded, discard the current video frame and increment the number of consecutive frames that have been discarded by one;
[0026] When the number of consecutive frames that have been discarded is not less than the current number of consecutive frames that can be discarded, decode the current video frame and set the number of consecutive frames that have been discarded to zero.
[0027] Optionally, it further includes:
[0028] If the difference is not greater than the preset first threshold, then decode the current video frame and set the number of consecutive frames that have been discarded to zero.
[0029] Optionally, it further includes:
[0030] If the difference is greater than the preset second threshold, increment the current number of consecutive frames that can be discarded, and when the difference is not greater than the preset third threshold, perform the step of comparing the number of consecutive frames that have been discarded with the current number of consecutive frames that can be discarded, and determining whether to discard the current video frame according to the comparison result; wherein, the preset second threshold is less than the preset third threshold.
[0031] Optionally, it further includes:
[0032] If the difference is greater than the preset third threshold, increment the current number of consecutive frames that can be discarded again, and perform the step of comparing the number of consecutive frames that have been discarded with the current number of consecutive frames that can be discarded, and determining whether to discard the current video frame according to the comparison result.
[0033] Optionally, it further includes:
[0034] If the playback speed of the video is the desired playback speed, perform the step of identifying whether the video is stuck;
[0035] If the video is not stuck, perform the step of identifying whether the playback speed of the video is the desired playback speed.
[0036] To achieve the above object, the present application further provides a video playback device, including:
[0037] An identification module, configured to identify whether the playback speed of the video is the desired playback speed; the desired playback speed is a user-set value;
[0038] An acceleration module, configured to, if the playback speed of the video is not the desired playback speed, increase the playback speed of the video by a first change value, and identify whether the video is stuck;
[0039] A deceleration module, configured to, if the video is stuck, reduce the playback speed of the video.
[0040] To achieve the above object, the present application further provides an electronic device, including:
[0041] A memory, configured to store a computer program;
[0042] A processor, configured to execute the computer program to implement the aforementioned video playback method.
[0043] To achieve the above object, the present application further provides a readable storage medium, configured to store a computer program, wherein the computer program, when executed by a processor, implements the aforementioned video playback method.
[0044] To achieve the above object, the present application further provides a computer program product, including computer instructions, which when running on a computer, enable the computer to execute the aforementioned disclosed video playing method.
[0045] As can be seen from the above solution, the present application provides a video playing method, including: identifying whether the playing speed of the currently played video is the desired playing speed; the desired playing speed is a user-set value; if the playing speed of the video is not the desired playing speed, increasing the playing speed of the video by a first change value and identifying whether the video freezes; if the video freezes, reducing the playing speed of the video.
[0046] It can be seen that when the present application identifies that the playing speed of the currently played video is not the desired playing speed set by the user, it increases the playing speed of the video by a first change value and identifies whether the video freezes; if the video freezes, it reduces the playing speed of the video. Thus, the present application can gradually increase the video playing speed, and when the video freezes, it reduces the playing speed of the video, so as to gradually and automatically adjust the video playing speed with reference to the desired playing speed set by the user on the premise of ensuring the synchronous playing of video sound and picture, and reduce the occurrence probability of phenomena such as video playing freeze and black screen. Among them, gradually reducing or increasing the playing speed can make the playing speed smoothly transition and reduce the user's perception of the change in the playing speed.
[0047] Correspondingly, a video playing device, equipment, readable storage medium and computer program product provided by the present application also have the above technical effects. Description of the Drawings
[0048] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the following will briefly introduce the drawings required to be used in the description of the embodiments or the prior art. Obviously, the drawings in the following description are only the embodiments of the present application. For those of ordinary skill in the art, other drawings can be obtained according to the provided drawings without creative efforts.
[0049] Figure 1 It is a flowchart of a video playing method disclosed by the present application;
[0050] Figure 2 It is a schematic diagram of a frame dropping judgment process disclosed by the present application;
[0051] Figure 3 It is a schematic diagram of a speed increasing process disclosed by the present application;
[0052] Figure 4 It is a schematic diagram of a speed decreasing process disclosed by the present application;
[0053] Figure 5 Schematic diagram of a video playback device disclosed in the present application;
[0054] Figure 6 Schematic diagram of an electronic device disclosed in the present application;
[0055] Figure 7 Schematic diagram of another electronic device disclosed in the present application.
[0056] The realization of the purpose of the present application, functional characteristics and advantages will be further described with reference to the embodiments and the accompanying drawings. Detailed implementation manners
[0057] In order to make the purpose, technical solutions and advantages of the present application clearer, the following further describes the present application in detail with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are only used to explain the present application and are not used to limit the present application. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative efforts belong to the scope of protection of the present application.
[0058] The terms "first", "second", "third", "fourth", etc. (if any) in the specification and claims of the present application and the above-mentioned drawings are used to distinguish similar objects and do not have to be used to describe a specific order or sequence. It should be understood that such data can be interchanged under appropriate circumstances so that the embodiments described herein can be implemented in an order other than that shown or described herein. In addition, the terms "including" and "having" and any variations thereof are intended to cover non-exclusive inclusion. For example, a process, method, system, product or device that includes a series of steps or units does not have to be limited to those steps or units clearly listed, but may include other steps or units not clearly listed or inherent to these processes, methods, products or devices.
[0059] It should be noted that the descriptions involving "first", "second", etc. in the present application are only for descriptive purposes and cannot be understood as indicating or implying their relative importance or implicitly indicating the quantity of the indicated technical features. Thus, features defined with "first" and "second" may explicitly or implicitly include at least one such feature. In addition, the technical solutions between various embodiments can be combined with each other, but it must be based on the fact that those of ordinary skill in the art can implement them. When the combination of technical solutions results in contradictions or cannot be implemented, it should be considered that such a combination of technical solutions does not exist and is not within the scope of protection required by the present application.
[0060] See Figure 1 , Figure 1 which is a flowchart of the first video playback method disclosed in the present application. In this embodiment, the method includes:
[0061] S101. Identify whether the playback speed of the currently playing video is the desired playback speed; the desired playback speed is a value set by the user.
[0062] S102. If the playback speed of the video is not the desired playback speed, increase the playback speed of the video by a first change value and identify whether the video freezes.
[0063] During the video playback process, the user can set the desired playback speed at any time, so that the video playback device plays the video at the playback speed set by the user. In this embodiment, to prevent the user from setting a large playback speed on a device with low performance, resulting in playback freezes, when it is determined that the playback speed of the currently playing video is not the desired playback speed set by the user, the playback speed of the video is increased by a first change value. If the playback speed of the video is the desired playback speed, then perform the step of identifying whether the video freezes; if the video does not freeze, then perform the step of identifying whether the playback speed of the video is the desired playback speed. The video playback device includes but is not limited to intelligent robots, smart phones, tablet computers, laptop computers, or desktop computers, etc.
[0064] It should be noted that the first change value can be the increment value used to increase the playback speed this time, or the playback speed value obtained after increasing the playback speed this time. If the first change value is the increment value used to increase the playback speed this time, then in one example, the first change value is 0.2. Then, increase the playback speed 1 of the currently playing video by 0.2 to get 1.2, and then play the current video at 1.2 times the speed. When playing the current video at 1.2 times the speed, it can be determined whether the video freezes; if it freezes, then reduce the playback speed of the video. Thus, on the premise of ensuring the synchronous playback of video audio and video, the video playback speed can be gradually and automatically adjusted with reference to the desired playback speed set by the user, reducing the occurrence probability of video playback freezes, black screens, and other phenomena.
[0065] In this embodiment, the first change value can be a fixed value or determined based on an algorithm or rule. When the first change value is a fixed value, each time the playback speed is increased, the speed is incremented by the first change value. At this time, the first change value can be the increment value used to increase the playback speed this time. When the first change value is determined based on an algorithm or rule, each time the playback speed is increased, an algorithm or rule outputs a first change value, and then the first change value output by the algorithm or rule is added to the original playback speed to obtain the increased playback speed. Of course, the algorithm or rule can also directly output the increased playback speed. At this time, the first change value can be both the increment value used to increase the playback speed this time and the playback speed value obtained after increasing the playback speed this time. It should be noted that the playback speed after each increase should not be greater than the expected playback speed set by the user. If the playback speed after a certain calculation is greater than the expected playback speed set by the user, then the playback speed after this calculation is not used, and the expected playback speed set by the user is directly taken as the playback speed after this increase.
[0066] In one example, if the median value selection rule is used to increase the playback speed, the median of the playback speed of the currently played video and the expected playback speed of the user can be taken as the increased playback speed. If the median value selection rule is used to decrease the playback speed, the median of the playback speed of the currently played video and the expected playback speed of the user can be taken as the decreased playback speed. If the random value selection rule is used to increase the playback speed, a value can be randomly selected between the playback speed of the currently played video and the expected playback speed of the user as the increased playback speed. If the random value selection rule is used to decrease the playback speed, a value can also be randomly selected between the playback speed of the currently played video and the expected playback speed of the user as the decreased playback speed. It can be seen that there are various implementation methods for gradually increasing and gradually decreasing the playback speed. In specific implementation, it can be flexibly selected according to actual needs. Gradually decreasing or gradually increasing the playback speed can make the playback speed transition smoothly and reduce the user's perception of the change in the playback speed.
[0067] S103. If the video lags, reduce the playback speed of the video.
[0068] In one embodiment, reducing the playback speed of a video includes: reducing the playback speed of the video by a second change value. For example, if the second change value is 0.2, then the playback speed of the currently played video, which is 1, is reduced by 0.2 to get 0.8, and then the current video is played at 0.8 times the speed. When playing the current video at 0.8 times the speed, it is possible to determine whether the video is stuck; if it is stuck, the playback speed of the video is reduced again, thereby ensuring the synchronous playback of the video's audio and video and reducing the occurrence probability of phenomena such as video playback jitter and black screen. It should be noted that the second change value can be a fixed value or determined based on an algorithm or rule. For specific reference, please refer to the relevant introduction about the first change value above, and it will not be elaborated here.
[0069] Under normal circumstances, a video has its own preset decoding frame rate. However, due to factors such as the network environment and the performance of the video playback device affecting video decoding, the actual decoding frame rate of the video may be lower than the preset decoding frame rate. The actual decoding frame rate of the video can be determined based on the ratio of the total number of decoded frames within a period of time to this period of time. For example, if the total number of decoded frames within 10 seconds is 1000, then the actual decoding frame rate F1 = 1000 / 10 = 100.
[0070] In one embodiment, reducing the playback speed of a video includes: calculating the actual decoding frame rate; reducing the playback speed of the video based on the actual decoding frame rate and the preset decoding frame rate of the video. Among them, reducing the playback speed of the video based on the actual decoding frame rate and the preset decoding frame rate of the video includes: calculating the ratio of the actual decoding frame rate to the preset decoding frame rate; determining the difference between the ratio and a set value as the reduced playback speed. If the preset decoding frame rate F2 of the video is 120, then in one example, the reduced playback speed = (F1 / F2) - A, where A is the set value and F1 is the actual decoding frame rate calculated above.
[0071] Among them, before calculating the actual decoding frame rate, it further includes: counting the total number of decoded frames from the moment when the playback speed is increased to the current moment; if the total number of decoded frames is greater than the decoded frame number threshold, and the difference between the timestamp of the current frame video image and the current audio timestamp is greater than the preset target value, then perform the calculation of the actual decoding frame rate; steps of reducing the playback speed of the video based on the actual decoding frame rate and the preset decoding frame rate of the video; the decoded frame number threshold is the product of the preset decoding frame rate and the preset value B. Counting the total number of decoded frames from the moment when the playback speed is increased to the current moment and judging the size of the total number of decoded frames and the decoded frame number threshold can determine: the total number of decoded frames during the period from the moment when the playback speed is increased to the current moment. If the total number of decoded frames is greater than the decoded frame number threshold, it means that the period from the moment when the playback speed is increased to the current moment has met a condition for enabling the speed reduction function, that is: the video has been played for a long enough time at the increased playback speed; if the difference between the timestamp of the current frame video image and the current audio timestamp is greater than the preset target value at this time, it means that the audio and video are out of sync at the current moment, then it is considered that another condition for enabling the speed reduction function is met, so the playback speed of the video is reduced. It can be seen that when the video has been tried to be played at a certain speed for a long enough time but the audio and video are still out of sync, it is considered that the current device is difficult to play the video smoothly at the current speed, so the speed reduction process is performed. Among them, the purpose of "counting the total number of decoded frames from the moment when the playback speed is increased to the current moment and judging the size of the total number of decoded frames and the decoded frame number threshold" in this embodiment is: to judge whether the time for playing the video at the increased playback speed is long enough, and this method is convenient for code implementation. Of course, it is also possible to directly start timing from the moment when the playback speed is increased, and when the timing time is long enough, judge how long the video image timestamp lags behind the audio timestamp, so as to determine whether to perform the speed reduction process.
[0072] It can be seen that in this embodiment, when it is recognized that the playback speed of the currently played video is not the desired playback speed set by the user, the playback speed of the video is increased by the first change value, and it is recognized whether the video freezes; if the video freezes, the playback speed of the video is reduced. Thus, this embodiment can gradually increase the video playback speed, and when the video freezes, the playback speed of the video is reduced, so that it is possible to gradually and automatically adjust the video playback speed with reference to the desired playback speed set by the user on the premise of ensuring the synchronous playback of the video audio and video, and reduce the occurrence probability of phenomena such as video playback freezing and black screen.
[0073] Based on the above embodiments, it should be noted that no matter at which speed value the video is played, the frame dropping judgment process will be entered during the playback process, because before decoding each frame of the image, a judgment on whether to drop the current frame will be made.
[0074] In one embodiment, before decoding each video frame in a video, initialize the number of consecutive droppable frames, which is used to limit the maximum number of consecutive frames that are allowed to be dropped; calculate the difference between the timestamp of the current video frame and the current audio timestamp; if the difference is greater than a preset first threshold and not greater than a preset second threshold, then compare the number of consecutive droppable frames that have been dropped with the current number of consecutive droppable frames, and determine whether to drop the current video frame according to the comparison result; wherein, the preset first threshold is less than the preset second threshold. If the difference is not greater than the preset first threshold, decode the current video frame and set the number of consecutive droppable frames that have been dropped to zero. If the difference is greater than the preset second threshold, increment the current number of consecutive droppable frames, and when the difference is not greater than a preset third threshold, perform the step of comparing the number of consecutive droppable frames that have been dropped with the current number of consecutive droppable frames, and determine whether to drop the current video frame according to the comparison result; wherein, the preset second threshold is less than the preset third threshold. If the difference is greater than the preset third threshold, increment the current number of consecutive droppable frames again, and perform the step of comparing the number of consecutive droppable frames that have been dropped with the current number of consecutive droppable frames, and determine whether to drop the current video frame according to the comparison result. Among them, when incrementing the number of consecutive droppable frames, it can be incremented by a fixed value or incremented according to a preset algorithm or rule.
[0075] Among them, determining whether to drop the current video frame according to the comparison result includes: when the number of consecutive droppable frames that have been dropped is less than the current number of consecutive droppable frames, drop the current video frame and increment the number of consecutive droppable frames that have been dropped by one; when the number of consecutive droppable frames that have been dropped is not less than the current number of consecutive droppable frames, decode the current video frame and set the number of consecutive droppable frames that have been dropped to zero.
[0076] Please refer to Figure 2 , for each frame, initialize the maximum number of consecutive dropped frames M (i.e., the number of consecutive droppable frames mentioned above), calculate how long the timestamp of the current frame lags behind the audio timestamp. If the lag time is not greater than X1 (i.e., the preset first threshold mentioned above), it means that the lag time is within the allowable range, and it is considered that the audio and video are synchronized at the current moment, so the current frame is not dropped. At this time, since the current frame is retained, the counting of the number of consecutive droppable frames that have been dropped is interrupted, so the actual number of consecutive dropped frames N (i.e., the number of consecutive droppable frames that have been dropped mentioned above) is set to 0.
[0077] If the lag time is greater than X1, then compare the lag time with X2 (i.e., the preset second threshold described above). If the lag time is not greater than X2, it indicates that the condition for increasing M is not met, so M remains unchanged. Then compare N and M. When N is greater than M, it means that the actual number of continuously dropped frame numbers N has reached the maximum value. If another frame is dropped, it will affect the continuity of the video. Therefore, this frame is not dropped. At this time, the count of the number of continuously dropped frames is interrupted, so N is set to 0. When N is not greater than M, it means that the actual number of continuously dropped frame numbers N has not reached the maximum value. This frame is discarded without affecting the continuity of the video. Therefore, this frame is discarded, and the count of the number of continuously dropped frames is incremented by one, i.e., N = N + 1. Among them, the number of continuously dropped frames can be understood with reference to the following example: If the 1st, 2nd, and 3rd frames in the video are all discarded, and the 4th frame is retained, then after the frame dropping judgment for the 3rd frame, the number of continuously dropped frames N is equal to 3. After the frame dropping judgment for the 4th frame, N is set to 0.
[0078] If the lag time is greater than X2, then it is considered that the condition for increasing M is met. At this time, increment M by one, i.e., M = M + 1. Then compare the lag time with X3 (i.e., the preset third threshold described above). If the lag time is not greater than X3, at this time M takes the value of M + 1 updated in the previous step. Then compare N and M to determine whether this frame needs to be discarded and the value of N. If the lag time is greater than X3, then M is incremented by one on the basis of M + 1, i.e., M = M + 1 + 1. Then compare N and M to determine whether this frame needs to be discarded and the value of N.
[0079] Among them, according to Figure 2 When making a frame dropping judgment for each frame, the value of M is initialized. Therefore, for each frame, M can be increased by at most 2. Figure 2 where X1 < X2 < X3.
[0080] It can be seen that in this embodiment, three thresholds are set to strictly control the frame dropping strategy layer by layer. Thus, it can be carefully determined whether to drop a frame, thereby avoiding the video being discontinuous due to excessive frame dropping or the audio and video being out of sync due to too few frame drops. That is to say, in this embodiment, a frame dropping judgment can be made on the premise of ensuring audio - video synchronization and video continuity, thereby avoiding abnormal phenomena such as playback jamming, audio - video out - of - sync, and black screen.
[0081] Based on the above embodiments, a frame dropping judgment component, a speed increasing component, a detection component, and a speed decreasing component can be set in a video player that can be installed in a video playback device. Among them, the frame dropping judgment component can be used to judge whether each video frame is to be dropped. The speed increasing component can gradually increase the video playback speed to the speed expected by the user or gradually increase the video playback speed to a speed slightly less than the speed expected by the user when the user increases the video playback speed. The detection component is used to judge whether to enable the speed decreasing function. The speed decreasing component is used to gradually perform speed decreasing processing after the speed decreasing function is enabled. Gradually decreasing or increasing the playback speed can make the playback speed smoothly transition, reduce the user's perception of the change in the playback speed, and also make the video play smoothly.
[0082] The frame dropping judgment component can avoid video playback stuttering while ensuring the continuity of the picture, and can specifically execute Figure 2 the process shown. As Figure 2 shown, the maximum number of consecutive dropped frames M is set, and in Figure 2 the process shown, M can be changed according to the duration by which the video frame timestamp lags behind the audio frame timestamp. If the video frame timestamp lags behind the audio frame timestamp for too long, then M will increase in the process. If the video frame timestamp does not lag behind the audio frame timestamp for a long time, then M can remain unchanged.
[0083] During the process of gradually increasing the speed, the speed increasing component can also ensure audio-visual synchronization. As Figure 3 shown, if the video player is playing a video at speed C and there is no stuttering when playing the video at speed C, and at this time the user sets the speed to 2, then the video player can judge the magnitude of the current video playback speed C and the speed 2. If C is less than 2, then the video player calls the speed increasing component to increase the playback speed to C + D, where D is the first change value described in the above embodiments, and then plays the video at the increased C + D. If C is equal to, then play the video at speed 2.
[0084] It should be noted that if C is less than 2, then C + D cannot be greater than the speed 2 expected by the user. Therefore, before playing the video at C + D, it is also necessary to compare the magnitudes of C + D and 2. If C + D is not greater than 2, then play the video at C + D. If C + D is greater than 2, then play the video at the speed 2 expected by the user. No matter which speed value is used to play the video, when decoding each frame of the video, the frame dropping judgment component is called to determine whether a frame needs to be dropped.
[0085] If C + D is less than 2 and there is no lag when playing the video at C + D speed, then call the speed-up component again to increase the playback speed to C + D + D, and so on in a loop until the video playback speed is increased to the user-expected speed of 2 or the video playback speed is slightly less than 2. If C + D is less than 2 but there is lag when playing the video at C + D speed, then call the detection component to determine whether to reduce the speed. During the entire adjustment process, the user can be prompted that the playback speed is being dynamically adjusted.
[0086] As Figure 3 shown, whether there is lag when playing the video at a certain speed is judged by the following conditions: If the number of consecutive and undropped video frames determined according to the Figure 2 shown process is not less than E × F2, where E is a preset value and F2 is the preset decoding frame rate of the video, then it is considered that there is no lag when playing the video at the current speed, that is: it is considered that audio-visual synchronization can be achieved at the current speed; otherwise, it is considered that there is lag when playing the video at the current speed, that is: it is considered that audio-visual synchronization cannot be achieved at the current speed. Among them, the number of consecutive and undropped video frames can be understood with reference to the following example: If the first frame, the second frame, and the third frame in the video are all retained, but the fourth frame is discarded, then after the frame-drop judgment for the third frame, the number of consecutive and undropped video frames is equal to 3; after the frame-drop judgment for the fourth frame, the number of consecutive and undropped video frames will be set to 0.
[0087] The detection component can detect whether the current speed reduction condition is met. That is: when there is lag when playing the video at a certain speed P, call the detection component to determine whether to reduce the speed. As Figure 4 shown, the judgment condition for whether to reduce the speed is: when the total number of frames decoded at speed P is greater than the decoded frame number threshold and the audio and video are out of sync at the current moment, then it is considered that the speed reduction function activation condition is met, so call the speed reduction component to perform speed reduction processing.
[0088] As Figure 4As shown in the figure, after the deceleration component determines that the deceleration function is enabled, it determines the time difference T from the moment when the deceleration function is enabled to the current moment. If T is not less than the preset time threshold, then it calculates the actual decoding frame rate F1 during the period from the moment when the deceleration function is enabled to the current moment, and then calculates the reduced playback speed this time according to the formula (F1 / F2)-A. F2 is the preset decoding frame rate of the video, and A is a set value. If F2 is 100 frames per second, then when calculating the actual decoding frame rate F1, it can start timing from the moment when the deceleration function starts. After timing for 5 minutes, it calculates the total number of decoded frames within these 5 minutes divided by 300 seconds, and the quotient obtained is F1. After reducing the playback speed this time, the video is played at the reduced playback speed this time. Similarly, during the playback process, it determines whether there is any lag. If there is lag, it repeats the above process to decelerate again; if there is no lag, it determines whether there are dropped frames during the playback process. It can be seen that no matter at which playback speed value the video is played, when decoding each frame of the video, it calls the dropped frame determination component to determine whether dropped frames are needed. During the whole adjustment process, the user can be prompted that the playback speed is being dynamically adjusted currently.
[0089] It can be seen that this embodiment can add to the video player: a gradually increasing speed function and a gradually decreasing speed function, and can also ensure synchronous audio and video playback. Thus, on the premise of ensuring synchronous audio and video playback of the video, it gradually and automatically adjusts the video playback speed with reference to the expected playback speed set by the user, reducing the occurrence probability of phenomena such as video playback lag and black screen.
[0090] Next, a video playback device provided by an embodiment of the present application will be introduced. The video playback device described below can be referred to each other with the video playback method described above.
[0091] See Figure 5 , Figure 5 which is a schematic diagram of a video playback device disclosed in the present application. In this embodiment, the device includes:
[0092] An identification module 501, configured to identify whether the playback speed of the video is the expected playback speed; the expected playback speed is a value set by the user;
[0093] An acceleration module 502, configured to, if the playback speed of the video is not the expected playback speed, increase the playback speed of the video by a first change value and identify whether the video lags;
[0094] A deceleration module 503, configured to, if the video lags, reduce the playback speed of the video.
[0095] In one implementation manner, the deceleration module is specifically configured to:
[0096] Reduce the playback speed of the video by a second change value.
[0097] In one embodiment, the speed reduction module includes:
[0098] A calculation unit for calculating the actual decoding frame rate;
[0099] A speed reduction unit for reducing the playback speed of the video based on the actual decoding frame rate and the preset decoding frame rate of the video.
[0100] In one embodiment, the speed reduction module further includes:
[0101] A statistics unit for counting the total number of decoded frames from the moment when the playback speed is increased to the current moment; if the total number of decoded frames is greater than the decoded frame number threshold and the difference between the timestamp of the current video frame and the current audio timestamp is greater than the preset target value, it enters the calculation unit; the decoded frame number threshold is the product of the preset decoding frame rate and the preset value.
[0102] In one embodiment, the speed reduction unit is specifically configured to:
[0103] Calculate the ratio of the actual decoding frame rate to the preset decoding frame rate;
[0104] Determine the difference between the ratio and the set value as the reduced playback speed.
[0105] In one embodiment, the device further includes: a dropped frame judgment module;
[0106] Wherein, the dropped frame judgment module is used for:
[0107] Before decoding each video frame in the video, initialize the number of consecutive frames that can be dropped;
[0108] Calculate the difference between the timestamp of the current video frame and the current audio timestamp;
[0109] If the difference is greater than the preset first threshold and not greater than the preset second threshold, compare the number of consecutive frames that have been dropped with the current number of consecutive frames that can be dropped, and determine whether to discard the current video frame according to the comparison result; wherein, the preset first threshold is less than the preset second threshold.
[0110] In one embodiment, the dropped frame judgment module is specifically configured to:
[0111] When the number of consecutive frames that have been dropped is less than the current number of consecutive frames that can be dropped, discard the current video frame and increment the number of consecutive frames that have been dropped by one;
[0112] When the number of consecutive frames that have been dropped is not less than the current number of consecutive frames that can be dropped, decode the current video frame and set the number of consecutive frames that have been dropped to zero.
[0113] In one embodiment, the dropped frame judgment module is further used for:
[0114] If the difference is not greater than a preset first threshold, decode the current frame of the video picture and set the number of consecutive dropped pictures to zero.
[0115] In one embodiment, the dropped frame determination module is further configured to:
[0116] If the difference is greater than a preset second threshold, increment the current number of consecutive droppable pictures, and when the difference is not greater than a preset third threshold, perform the step of comparing the number of consecutive dropped pictures and the current number of consecutive droppable pictures, and determine whether to discard the current frame of the video picture according to the comparison result; wherein, the preset second threshold is less than the preset third threshold.
[0117] In one embodiment, the dropped frame determination module is further configured to:
[0118] If the difference is greater than the preset third threshold, increment the current number of consecutive droppable pictures again, and perform the step of comparing the number of consecutive dropped pictures and the current number of consecutive droppable pictures, and determine whether to discard the current frame of the video picture according to the comparison result.
[0119] In one embodiment, it further includes:
[0120] An execution module, configured to, if the playback speed of the video is the desired playback speed, perform the step of identifying whether the video is stuck; if the video is not stuck, perform the step of identifying whether the playback speed of the video is the desired playback speed.
[0121] Wherein, for the more specific working processes of each module and unit in this embodiment, reference may be made to the corresponding content disclosed in the foregoing embodiments, and details will not be elaborated herein.
[0122] It can be seen that this embodiment provides a video playback device, which can gradually and automatically adjust the video playback speed with reference to the desired playback speed set by the user on the premise of ensuring the synchronous playback of video sound and picture, and reduce the occurrence probability of video playback stuck, black screen and other phenomena.
[0123] Next, an electronic device provided by an embodiment of the present application will be introduced. The electronic device described below can be mutually referred to with the video playback method and device described above.
[0124] See Figure 6 , Figure 6 is a schematic diagram of an electronic device disclosed in the present application. In this embodiment, the device includes:
[0125] A memory 601, configured to store a computer program;
[0126] A processor 602, configured to execute the computer program to implement the following steps: identifying whether the playback speed of the currently played video is the desired playback speed; the desired playback speed being a value set by the user; if the playback speed of the video is not the desired playback speed, increasing the playback speed of the video by a first change value and identifying whether the video freezes; if the video freezes, decreasing the playback speed of the video.
[0127] In this embodiment, when the processor executes the computer subroutine stored in the memory, the following steps may be specifically implemented: decreasing the playback speed of the video by a second change value.
[0128] In this embodiment, when the processor executes the computer subroutine stored in the memory, the following steps may be specifically implemented: calculating the actual decoding frame rate; decreasing the playback speed of the video based on the actual decoding frame rate and the preset decoding frame rate of the video.
[0129] In this embodiment, when the processor executes the computer subroutine stored in the memory, the following steps may be specifically implemented: counting the total number of decoded frames from the moment when the playback speed is increased to the current moment; if the total number of decoded frames is greater than the decoded frame number threshold and the difference between the timestamp of the current video frame and the current audio timestamp is greater than the preset target value, then execute the step of calculating the actual decoding frame rate; the decoded frame number threshold is the product of the preset decoding frame rate and a preset value.
[0130] In this embodiment, when the processor executes the computer subroutine stored in the memory, the following steps may be specifically implemented: calculating the ratio of the actual decoding frame rate to the preset decoding frame rate; determining the decreased playback speed as the difference between the ratio and a set value.
[0131] In this embodiment, when the processor executes the computer subroutine stored in the memory, the following steps may be specifically implemented: before decoding each video frame in the video, initializing the number of consecutive droppable frames; calculating the difference between the timestamp of the current video frame and the current audio timestamp; if the difference is greater than a preset first threshold and not greater than a preset second threshold, then comparing the number of already dropped consecutive frames with the current number of droppable frames and determining whether to discard the current video frame according to the comparison result; wherein the preset first threshold is less than the preset second threshold.
[0132] In this embodiment, when the processor executes the computer subroutine stored in the memory, the following steps may be specifically implemented: when the number of already dropped consecutive frames is less than the current number of droppable frames, discarding the current video frame and incrementing the number of already dropped consecutive frames by one; when the number of already dropped consecutive frames is not less than the current number of droppable frames, decoding the current video frame and setting the number of already dropped consecutive frames to zero.
[0133] In this embodiment, when the processor executes the computer subroutine stored in the memory, the following steps may be specifically implemented: If the difference is not greater than a preset first threshold, decode the current frame of video picture and set the number of consecutive lost pictures to zero.
[0134] In this embodiment, when the processor executes the computer subroutine stored in the memory, the following steps may be specifically implemented: If the difference is greater than a preset second threshold, increment the current number of consecutive droppable pictures, and when the difference is not greater than a preset third threshold, execute the step of comparing the number of consecutive lost pictures with the current number of consecutive droppable pictures and determining whether to discard the current frame of video picture according to the comparison result; wherein, the preset second threshold is less than the preset third threshold.
[0135] In this embodiment, when the processor executes the computer subroutine stored in the memory, the following steps may be specifically implemented: If the difference is greater than a preset third threshold, increment the current number of consecutive droppable pictures again, and execute the step of comparing the number of consecutive lost pictures with the current number of consecutive droppable pictures and determining whether to discard the current frame of video picture according to the comparison result.
[0136] In this embodiment, when the processor executes the computer subroutine stored in the memory, the following steps may be specifically implemented: If the playback speed of the video is the desired playback speed, execute the step of identifying whether the video is stuck; if the video is not stuck, execute the step of identifying whether the playback speed of the video is the desired playback speed.
[0137] See Figure 7 , Figure 7 which is another schematic diagram of an electronic device disclosed in the present application. The electronic device may include a memory 11, a processor 12, and a bus 13.
[0138] Among them, the memory 11 includes at least one type of readable storage medium, and the readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (such as SD or DX memory, etc.), magnetic memory, magnetic disk, optical disc, etc. The memory 11 can be an internal storage unit of the electronic device in some embodiments, such as the hard disk of the electronic device. The memory 11 can also be an external storage device of the electronic device in other embodiments, such as a plug-in hard disk equipped on the electronic device, a Smart Media Card (SMC), a Secure Digital (SD) card, a FlashCard, etc. Further, the memory 11 can also include both the internal storage unit and the external storage device of the electronic device. The memory 11 can be used not only to store the application software and various types of data installed in the electronic device, such as the code of the video playback program, etc., but also to temporarily store the data that has been output or will be output.
[0139] The processor 12 can be a central processing unit (CPU), a controller, a microcontroller, a microprocessor, or other data processing chips in some embodiments, and is used to run the program code stored in the memory 11 or process data, such as executing the video playback program, etc.
[0140] The bus 13 can be a peripheral component interconnect (PCI) bus or an extended industry standard architecture (EISA) bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. For the sake of convenience of representation, Figure 7 only a thick line is used to represent it in the figure, but it does not mean that there is only one bus or one type of bus.
[0141] Further, the electronic device can also include a network interface, and the network interface can optionally include a wired interface and / or a wireless interface (such as a WI-FI interface, a Bluetooth interface, etc.), and is usually used to establish a communication connection between the device and other electronic devices.
[0142] Optionally, the device may further include a user interface, which may include a display, an input unit such as a keyboard, and an optional user interface may further include a standard wired interface and a wireless interface. Optionally, in some embodiments, the display may be an LED display, a liquid crystal display, a touch liquid crystal display, and an OLED (Organic Light-Emitting Diode) toucher, etc. Among them, the display may also be appropriately referred to as a display screen or a display unit, which is used to display the information processed in the device and to display a visual user interface.
[0143] Figure 7 Only an electronic device with components 11-13 is shown. Those skilled in the art can understand that Figure 7 the shown structure does not constitute a limitation on the device, and it may include fewer or more components than shown, or combine certain components, or have different component arrangements.
[0144] Next, a readable storage medium provided by an embodiment of the present application will be introduced. The readable storage medium described below can be referred to in mutual reference with the video playback method, device, equipment, and readable storage medium described above.
[0145] A readable storage medium is used to store a computer program. When the computer program is executed by a processor, it implements the video playback method disclosed in the foregoing embodiments. For the specific steps of the method, reference can be made to the corresponding content disclosed in the foregoing embodiments, and details will not be repeated here.
[0146] Next, a computer program product provided by an embodiment of the present application will be introduced. The computer program product described below can be referred to in mutual reference with the video playback method, device, equipment, and readable storage medium described above.
[0147] A computer program product includes computer instructions. When it runs on a computer, it enables the computer to execute the video playback method disclosed in the foregoing embodiments. For the specific steps of the method, reference can be made to the corresponding content disclosed in the foregoing embodiments, and details will not be repeated here.
[0148] The various embodiments in this specification are described in a progressive manner. Each embodiment focuses on the differences from other embodiments. The same or similar parts among the various embodiments can be referred to each other.
[0149] The steps of the methods or algorithms described in connection with the embodiments disclosed herein may be implemented directly in hardware, in software modules executed by a processor, or in a combination thereof. The software modules may be placed in a random access memory (RAM), internal memory, read-only memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, a removable disk, a CD-ROM, or any other form of readable storage medium known in the art.
[0150] Specific examples are used in this article to illustrate the principles and implementation manners of the present application. The descriptions of the above embodiments are only used to help understand the method and its core idea of the present application; at the same time, for those of ordinary skill in the art, according to the idea of the present application, there will be changes in the specific implementation manners and application scopes. In summary, the content of this specification should not be construed as a limitation to the present application.
Claims
1. A video playing method, characterized in that, Including: Identifying whether the playing speed of the currently played video is the desired playing speed; the desired playing speed is a user-set value; If the playing speed of the video is not the desired playing speed, increasing the playing speed of the video by a first change value and identifying whether the video freezes; If the video freezes, reducing the playing speed of the video; Among them, it also includes: If the playing speed of the video is the desired playing speed, performing the step of identifying whether the video freezes; If the video does not freeze, performing the step of identifying whether the playing speed of the video is the desired playing speed.
2. The video playback method according to claim 1, wherein Reducing the playing speed of the video includes: Reducing the playing speed of the video by a second change value.
3. The video playback method according to claim 1, wherein Reducing the playing speed of the video includes: Calculating the actual decoding frame rate; Reducing the playing speed of the video based on the actual decoding frame rate and the preset decoding frame rate of the video.
4. The video playback method according to claim 3, wherein Before calculating the actual decoding frame rate, it also includes: Counting the total number of decoded frames from the moment when the playing speed is increased to the current moment; If the total number of decoded frames is greater than the decoding frame number threshold and the difference between the time stamp of the current frame video picture and the current audio time stamp is greater than the preset target value, performing the step of calculating the actual decoding frame rate; the decoding frame number threshold is the product of the preset decoding frame rate and the preset value.
5. The video playing method according to claim 3, wherein Reducing the playing speed of the video based on the actual decoding frame rate and the preset decoding frame rate of the video includes: Calculating the ratio of the actual decoding frame rate to the preset decoding frame rate; Determining the difference between the ratio and the set value as the reduced playing speed.
6. The video playback method according to any one of claims 1 to 5, characterized in that, It also includes: Initializing the number of consecutive disposable pictures before decoding each frame of the video picture; Calculating the difference between the time stamp of the current frame video picture and the current audio time stamp; If the difference is greater than the preset first threshold and not greater than the preset second threshold, comparing the number of already discarded consecutive pictures with the current number of disposable consecutive pictures and determining whether to discard the current frame video picture according to the comparison result; where the preset first threshold is less than the preset second threshold.
7. The video playing method according to claim 6, wherein Determining whether to discard the current frame video picture according to the comparison result includes: When the number of already discarded consecutive pictures is less than the current number of disposable consecutive pictures, discarding the current frame video picture and incrementing the number of already discarded consecutive pictures by one; When the number of already discarded consecutive pictures is not less than the current number of disposable consecutive pictures, decoding the current frame video picture and setting the number of already discarded consecutive pictures to zero.
8. The video playing method according to claim 6, wherein It also includes: If the difference is not greater than the preset first threshold, decoding the current frame video picture and setting the number of already discarded consecutive pictures to zero.
9. The video playing method according to claim 6, wherein It also includes: If the difference is greater than the preset second threshold, incrementing the current number of disposable consecutive pictures and, when the difference is not greater than the preset third threshold, performing the step of comparing the number of already discarded consecutive pictures with the current number of disposable consecutive pictures and determining whether to discard the current frame video picture according to the comparison result; where the preset second threshold is less than the preset third threshold.
10. The video playback method according to claim 9, wherein It also includes: If the difference is greater than the preset third threshold value, increment the current number of consecutive frames that can be discarded again, and perform the steps of comparing the number of consecutive frames that have been discarded with the current number of consecutive frames that can be discarded, and determining whether to discard the current video frame according to the comparison result.
11. A video playback device, characterized in that, Comprising: An identification module, configured to identify whether the playback speed of the currently played video is the desired playback speed; the desired playback speed is a user-set value; An acceleration module, configured to, if the playback speed of the video is not the desired playback speed, increase the playback speed of the video by a first change value, and identify whether the video freezes; A deceleration module, configured to, if the video freezes, decrease the playback speed of the video; Wherein, the device further comprises: An execution module, configured to, if the playback speed of the video is the desired playback speed, perform the step of identifying whether the video freezes; if the video does not freeze, perform the step of identifying whether the playback speed of the video is the desired playback speed.
12. An electronic device, characterized in that, Comprising: A memory, configured to store a computer program; A processor, configured to execute the computer program to implement the video playback method according to any one of claims 1 to 10.
13. A readable storage medium, characterized in that, For saving a computer program, wherein the computer program, when executed by a processor, implements the video playback method according to any one of claims 1 to 10.
Citation Information
Patent Citations
Video playing method and device, server and storage medium
CN112887761A
Video adjustment method, monitoring device, computer program product and storage medium
CN113115100A