Video definition switching method, device, electronic device and storage medium
By obtaining and utilizing the key frames and index data of the video to switch video definitions, the problems of frame skipping playback and excessive traffic consumption during video switching in the existing technology are solved, and smoother and energy-saving video playback is achieved.
Patent Information
- Application Number
- CN202010071483.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2020-01-21
- Publication Date
- 2024-08-23
- Estimated Expiration
- 2040-01-21
AI Technical Summary
Existing video definition switching solutions are prone to frame skipping when switching, resulting in excessive traffic consumption.
By obtaining the key frames and index data of the currently playing video, the corresponding key frames in the video to be switched are determined, and video switching is performed based on these key frames and index data to avoid unnecessary reloading and traffic waste.
It effectively solves the problem of frame skipping playback, reduces traffic consumption, and improves the smoothness of video playback.
Smart Images

Figure CN113225585B
Abstract
Description
Technical Field
[0001] The present application relates to the field of computer technology, and in particular to a method, device, electronic device and storage medium for switching video definition. Background Art
[0002] With the development of network technology, users can use terminals to watch videos online. The videos provided by a video source on the Internet generally have multiple bit rates, and videos with different bit rates have different clarity. When watching a video, the user can manually select the bit rate of the video to be watched according to the viewing needs.
[0003] At present, the video definition switching solution is mainly based on the real-time streaming protocol (HTTP Live Streaming, HLS), that is, the video file is first segmented, and then reloaded based on the segments when the definition is switched. However, the current switching solution has the problem of frame skipping, which consumes a lot of traffic. Summary of the invention
[0004] The embodiments of the present invention provide a method, device, electronic device and storage medium for switching video definition, which can solve the problem of frame skipping playback and thus reduce traffic consumption.
[0005] An embodiment of the present invention provides a method for switching video definition, comprising:
[0006] Get the currently playing video;
[0007] When a video definition switching request triggered by a user is received, a video to be switched that is consistent with the content of the currently playing video is obtained, wherein the bit rate of the currently playing video is different from the bit rate of the video to be switched;
[0008] Loading index data corresponding to the video to be switched;
[0009] Extract the current key frame of the currently playing video to obtain the current key frame;
[0010] Determine the key frame corresponding to the current key frame in the video to be switched according to the current key frame and the index data, and obtain the switching key frame;
[0011] Based on the current key frame, the switching key frame and the index data, the currently playing video is switched to the video to be switched.
[0012] Accordingly, an embodiment of the present invention further provides a device for switching video definition, including:
[0013] The first acquisition module is used to acquire the currently playing video and obtain the currently playing video;
[0014] A second acquisition module is used to, when receiving a video definition switching request triggered by a user, acquire a video to be switched that is consistent with the content of the currently playing video, wherein the bit rate of the currently playing video is different from the bit rate of the video to be switched;
[0015] A loading module, used for loading the index data corresponding to the video to be switched;
[0016] An extraction module is used to extract the current key frame of the currently playing video to obtain the current key frame;
[0017] A determination module, used to determine a key frame corresponding to the current key frame in the video to be switched according to the current key frame and index data, and obtain a switching key frame;
[0018] The switching module is used to switch the currently played video to the video to be switched based on the current key frame, the switching key frame and the index data.
[0019] Optionally, in some embodiments of the present invention, the determining module includes:
[0020] An acquisition submodule, used for acquiring the video data where the current key frame is located from the currently playing video to obtain the first video data;
[0021] The determination submodule is used to select a key frame that meets a preset condition in the video to be switched according to the first video data, the current key frame and the index data to obtain a switching key frame.
[0022] Optionally, in some embodiments of the present invention, the determining submodule includes:
[0023] An acquisition unit, used to acquire a position of a current key frame in the first video data, and obtain position information corresponding to the current key frame;
[0024] The selection unit is used to select a key frame that meets a preset condition in the video to be switched according to the index data to obtain a switching key frame.
[0025] Optionally, in some embodiments of the present invention, the selection unit includes:
[0026] A loading subunit, configured to load the video data corresponding to the to-be-switched video based on the index data to obtain second video data;
[0027] The selection subunit is used to select a key frame matching the position information in the second video data to obtain a switching key frame.
[0028] Optionally, in some embodiments of the present invention, the acquisition subunit is specifically used for:
[0029] Extract the timestamp corresponding to the current key frame to get the first timestamp, and
[0030] Extracting the timestamp corresponding to each key frame in the second video data to obtain a plurality of second timestamps;
[0031] The key frame whose second timestamp is consistent with the first timestamp is determined as the key frame corresponding to the current key frame to obtain a switching key frame.
[0032] Optionally, in some embodiments of the present invention, the switching module is specifically used to:
[0033] Determine the video data that has been played of the currently played video according to the current key frame;
[0034] Calculate the video data to be loaded for the video to be switched by using the current key frame, the played video data and the index data;
[0035] The preset video data buffer is updated by the video data to be loaded to obtain an updated buffer;
[0036] Taking the switching key frame as a starting point, based on the video data to be loaded and the updated buffer, the currently playing video is switched to the video to be switched.
[0037] Optionally, in some embodiments of the present invention, a deletion module is further included, wherein the deletion module is specifically used to delete the video data corresponding to the currently playing video in the buffer after the update.
[0038] Optionally, in some embodiments of the present invention, a construction module is further included, and the construction module is specifically used to:
[0039] Build video data buffer;
[0040] The video data corresponding to the currently playing video is loaded into the video data buffer.
[0041] The embodiment of the present invention obtains the currently playing video, and after obtaining the currently playing video, when receiving a video definition switching request triggered by a user, obtains a video to be switched that is consistent with the content of the currently playing video, and the bit rate of the currently playing video is different from the bit rate of the video to be switched, and then loads the index data corresponding to the video to be switched, and then extracts the current key frame of the currently playing video to obtain the current key frame, and then determines the key frame corresponding to the current key frame in the video to be switched according to the current key frame and the index data to obtain the switching key frame, and finally, based on the current key frame, the switching key frame and the index data, switches the currently playing video to the video to be switched. Therefore, this solution can solve the problem of frame skipping playback, thereby reducing traffic consumption. BRIEF DESCRIPTION OF THE DRAWINGS
[0042] In order to more clearly illustrate the technical solutions in the embodiments of the present invention, the drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings without creative work.
[0043] Figure 1a is a schematic diagram of a scenario of a method for switching video definition provided by an embodiment of the present invention;
[0044] Figure 1b A schematic diagram of a flow chart of a method for switching video definition provided by an embodiment of the present invention;
[0045] Figure 2a is another flow chart of a method for switching video definition provided by an embodiment of the present invention;
[0046] Figure 2b It is a schematic diagram of a display page corresponding to a currently played video in a method for switching video definition provided by an embodiment of the present invention;
[0047] Figure 2c is a schematic diagram of a video frame in a method for switching video definition provided by an embodiment of the present invention;
[0048] Figure 2d It is a schematic diagram of switching and playing a video to be switched in the method for switching video definition provided by an embodiment of the present invention;
[0049] Figure 3a It is a structural schematic diagram of a first implementation manner of a device for switching video definition provided by an embodiment of the present invention;
[0050] Figure 3b is another structural schematic diagram of a second implementation manner of the video definition switching device provided in an embodiment of the present invention;
[0051] Figure 3c It is a structural schematic diagram of a third implementation manner of the video definition switching device provided by an embodiment of the present invention;
[0052] Figure 4 It is a schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0053] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative work are within the scope of protection of the present invention.
[0054] The embodiments of the present invention provide a method, a device, an electronic device and a storage medium for switching video definition.
[0055] The video definition switching device may be specifically integrated in a terminal, and the terminal may include a mobile phone, a tablet computer or a personal computer (PC).
[0056] See also Figure 1a The embodiment of the present invention provides a video definition switching system (hereinafter referred to as the switching system), which may include a terminal, a server and a user. Taking the video definition switching device integrated in a personal computer as an example, the personal computer may be installed with a client, which may be any client that can provide a video playback service, such as a web client based on a browser. The video playback service can support users to watch videos through a browser. During the video viewing process, users can also switch the video definition for the same video. For example, when the user needs to switch the video definition of the currently played video, a video to be switched that is consistent with the content of the currently played video is obtained, and the bit rate of the video to be switched is different from the bit rate of the currently played video. Then, the index data corresponding to the video to be switched is loaded, and then the current key frame of the currently played video is extracted to obtain the current key frame. Then, the key frame corresponding to the current key frame in the video to be switched is determined according to the current key frame and the index data to obtain the switching key frame. Finally, based on the current key frame, the switching key frame and the index data, the currently played video is switched to the video to be switched.
[0057] Since this solution determines the key frame corresponding to the current key frame in the video to be switched (i.e., the switching key frame) based on the current key frame and index data, and then switches the currently playing video to the video to be switched based on the current key frame, the switching key frame and the index data, that is, in this solution, the video clarity is switched based on the key frame. Therefore, the problem of frame skipping playback in the existing solution can be solved, thereby reducing traffic consumption.
[0058] It should be noted that the order of description of the following embodiments is not intended to limit the priority order of the embodiments.
[0059] A method for switching video definition includes: obtaining a currently playing video, obtaining the currently playing video, when receiving a video definition switching request triggered by a user, obtaining a to-be-switched video that is consistent with the content of the currently playing video, loading index data corresponding to the to-be-switched video, extracting a current key frame of the currently playing video, obtaining a current key frame, determining a key frame in the to-be-switched video that corresponds to the current key frame according to the current key frame and the index data, obtaining a switching key frame, and switching the currently playing video to the to-be-switched video based on the current key frame, the switching key frame and the index data.
[0060] See also Figure 1b , Figure 1b A schematic diagram of a flow chart of a method for switching video definition provided by an embodiment of the present invention. The specific flow of the method for switching video definition may be as follows:
[0061] 101. Get the currently playing video.
[0062] There are many ways to obtain the currently playing video, for example, it can be obtained from the Internet and / or a specified database, which can be determined according to the needs of the actual application. The currently playing video can include TV series, movies, and user-recorded videos, etc.
[0063] It should be noted that before the video is switched, a video data buffer can be constructed, and the video data buffer can be used to store and manage the video source data segments, that is, optionally, before the step of "obtaining the currently played video, obtaining the currently played video", it can also specifically include:
[0064] (11) Building a video data buffer;
[0065] (12) Load the video data corresponding to the currently playing video into the video data buffer.
[0066] For example, before the video is switched, the currently played video is video A, and the video data corresponding to video A can be loaded into the video data buffer.
[0067] 102. When a request for switching the video definition triggered by the user is received, a video to be switched that is consistent with the content of the currently playing video is obtained.
[0068] Among them, the bit rate of the currently playing video is different from the bit rate of the video to be switched. The bit rate is the number of data bits transmitted per unit time during data transmission, and the unit is kbps (kilobits per second), which is the sampling rate. The higher the sampling rate per unit time, the higher the accuracy, and the processed file is closer to the original file. The higher the bit rate, the clearer it is, otherwise the picture will be rough.
[0069] For example, when a user-triggered video clarity switching request is received, the switching request indicates that video A is switched to video B, that is, video A is the currently playing video, and video B is the video to be switched, wherein the content of video A is consistent with the content of video B, and the bit rate of video A is different from the bit rate of video B.
[0070] 103. Load the index data corresponding to the video to be switched.
[0071] In the embodiment of the present invention, during the video playback process, the terminal and the server follow the video transmission protocol, which may include: Real Time Messaging Protocol (RTMP) and HLS (HTTP Live Streaming) protocol, etc. Unless otherwise specified, the subsequent embodiments of the present invention all take the HLS protocol as an example. The HLS protocol is a streaming media solution, which includes a video index and video fragments. The video index contains a lot of basic information about the video stream. When a user plays a video through a terminal, the video index is not played directly, but the video index is parsed to obtain the index of each video fragment, and the URL of the corresponding video fragment is found according to the index for playback. Each video fragment is a video content of the video to be played, which includes the timestamp of the key frame and the video content corresponding to the timestamp and other data. For example, the formats of the currently playing video and the video to be switched are both in the fourth generation moving picture expert group (Moving Picture Experts Group 4, MP4) format. For an MP4 file, the most important thing is the index data. The index data (also called the header file) records the decoding information, timestamp, position and other data of all subsequent audio frames and video frames. Of course, the same is true for switching the clarity of the currently playing video based on other streaming media protocols, which will not be repeated here.
[0072] 104. Extract the current key frame of the currently playing video to obtain the current key frame.
[0073] Among them, video frames can include key frames (I frames), forward prediction frames (P frames) and bidirectional prediction frames (B frames). I frames are internally encoded frames, are the first frame of each image, and are a complete picture; P frames are forward prediction frames, which record changes relative to I frames or the adjacent previous P frames; B frames are bidirectional interpolation frames, and the difference from P frames is that it can refer to I frames or the adjacent previous frame, or the adjacent next frame, that is, P frames record changes relative to adjacent previous and next frames, that is, to play a short picture, you must find the I frame, and then you can successfully decode the corresponding B frame and P frame. It should be noted that the order of step 103 and step 104 is not limited.
[0074] 105. Determine a key frame corresponding to the current key frame in the video to be switched according to the current key frame and the index data, and obtain a switching key frame.
[0075] Since the content of the currently playing video is consistent with the video to be switched, that is, the number of images recorded in the two videos is the same, the number of key frames corresponding to the two videos is also consistent, that is, each key frame in the video to be switched has a corresponding key frame in the currently playing video. In an embodiment of the present invention, the key frame corresponding to the current key frame in the video to be switched can be determined based on the current key frame and index data. The difference lies in the different states of the two video frames. For example, when a user-triggered video clarity switching request for video A is received, the switching request indicates switching to video B. At this time, key frame I1 of video A is being played, then the video frame I1 is determined to be the current key frame, and the key frame corresponding to video frame I1 in video B is determined to be key frame I2 based on video frame I1 and index data, then key frame I2 is determined to be the switching key frame.
[0076] For example, the video data of the current key frame can be obtained from the currently playing video, and the key frame corresponding to the current key frame in the video to be switched can be determined based on the video data, the current key frame and the index data. That is, optionally, in some embodiments, the step of "determining the key frame corresponding to the current key frame in the video to be switched according to the current key frame and the index data to obtain the switching key frame" can specifically include:
[0077] (21) Obtaining video data of the current key frame from the currently playing video to obtain first video data;
[0078] (22) A key frame that meets a preset condition is selected from the video to be switched according to the first video data, the current key frame, and the index data to obtain a switching key frame.
[0079] For example, a key frame with image content consistent with the current key frame can be selected in the video to be switched based on the first video data, the current key frame and the index data to obtain a switching key frame. Specifically, a neural network model can be used to identify the image content of the current key frame and the image content corresponding to each key frame in the video to be switched.
[0080] For another example, the position of the current key frame in the first video data may be obtained, and then the key frame corresponding to the current key frame in the video to be switched may be determined according to the position and the index data, and then the key frame corresponding to the current key frame in the video to be switched may be determined according to the position and the index data to obtain the switching key frame, that is, the optional step of "selecting a key frame that meets the preset conditions in the video to be switched according to the first video data, the current key frame and the index data to obtain the switching key frame" may specifically include:
[0081] (31) Obtaining the position of the current key frame in the first video data, and obtaining the position information corresponding to the current key frame;
[0082] (32) A key frame whose position information meets a preset condition is selected in the video to be switched according to the index data to obtain a switching key frame.
[0083] For example, specifically, the position of the current key frame in the first video data is obtained, and the position indicates that the current key frame is at the position of the 8th frame in the first video data. Then, based on the index data, the video data corresponding to the video to be switched is loaded, and the 8th key frame is selected in the video data corresponding to the video to be switched to obtain the switching key frame. That is, optionally, in some embodiments, the step of "determining the key frame corresponding to the current key frame in the video to be switched according to the position information and the index data to obtain the switching key frame" may specifically include:
[0084] (41) loading video data corresponding to the video to be switched based on the index data to obtain second video data;
[0085] (42) Select a key frame matching the position information in the second video data to obtain a switching key frame.
[0086] For example, specifically, the index data is parsed, and based on the parsing result, the video data corresponding to the video to be switched is loaded to obtain the second video data, and then the key frame corresponding to the current key frame is obtained from the second video data to obtain the switching key frame. There are two ways to obtain the key frame corresponding to the current key frame from the second video data:
[0087] The first method: based on the position information of the current key frame, the key frame corresponding to the current key frame can be obtained from the second video data to obtain the switching key frame. For example, if the current key frame is the data of the 8th frame, then the 8th frame in the second video data can be determined as the key frame corresponding to the current key frame to obtain the switching key frame.
[0088] The second method: a key frame corresponding to the current key frame may be selected in the second video data according to the timestamp corresponding to the current key frame and the timestamps corresponding to the key frames in the second video data. That is, optionally, in some embodiments, the step of "obtaining a key frame corresponding to the current key frame in the second video data to obtain a switching key frame" may specifically include:
[0089] (51) extracting a timestamp corresponding to the current key frame to obtain a first timestamp, and extracting a timestamp corresponding to each key frame in the second video data to obtain a plurality of second timestamps;
[0090] (52) A plurality of key frames whose second timestamps are consistent with the first timestamp are determined as key frames corresponding to the current key frame, to obtain a switching key frame.
[0091] For example, the currently playing video and the video to be switched are both 100 seconds long, and the timestamp of the current key frame indicates that the current key frame is the 10th second key frame. Then, the 10th second key frame in the second video data can be determined as the key frame corresponding to the current key frame, and the switching key frame can be obtained. After obtaining the switching key frame, step 106 can be executed.
[0092] 106. Based on the current key frame, the switching key frame and the index data, the currently playing video is switched to the video to be switched.
[0093] For example, specifically, the video data that needs to be loaded for the video to be switched can be calculated based on the current key frame, the switching key frame, and the index data, and then, based on the switching key frame and the video data that needs to be loaded, the currently played video is switched to the video to be switched. That is, optionally, in some embodiments, the step of "switching the currently played video to the video to be switched based on the current key frame, the switching key frame, and the index data" can specifically include:
[0094] (61) determining the video data that has been played in the currently played video according to the current key frame;
[0095] (62) Calculating the video data to be loaded for the video to be switched based on the current key frame, the played video data, and the index data;
[0096] (63) updating a preset video data buffer using the video data to be loaded to obtain an updated buffer;
[0097] (64) Taking the switching key frame as the starting point, based on the switching key frame and the updated buffer, the currently playing video is switched to the video to be switched.
[0098] For example, specifically, if the current key frame is the third key frame, it can be determined based on the current key frame that the video data that has been played by the currently playing video includes: the video data of the first frame, the video data of the second frame, and the video data of the third frame. Then, the video data of the video to be switched can be obtained based on the index data, and the video data that needs to be loaded for the video to be switched can be calculated through the current key frame and the video data that has been played. Next, the size of the video data buffer that needs to be loaded can be reversely calculated through the video data that has been played by the currently playing video and the video data that needs to be loaded. That is, the preset video data buffer can be updated through the video data that has been played by the currently playing video and the video data that needs to be loaded. Finally, based on the switching key frame and the video data that needs to be loaded, the currently playing video is switched to the video to be switched.
[0099] In order to avoid unnecessary waste of traffic, after the currently playing video is switched to the video to be switched, the video data of the previous video in the updated buffer can also be updated. For example, after switching video A to video B, the video data of video A in the updated buffer can be deleted. That is, in some implementations, the step of "taking the switching key frame as the starting point, switching the currently playing video to the video to be switched based on the video data to be loaded and the updated buffer" can also include: deleting the video data corresponding to the currently playing video in the updated buffer.
[0100] The embodiment of the present invention first obtains the currently playing video, and obtains the currently playing video. When a video definition switching request triggered by a user is received, the video to be switched that is consistent with the content of the currently playing video is obtained, and then the index data corresponding to the video to be switched is loaded, and then the current key frame of the currently playing video is extracted to obtain the current key frame, and then the key frame corresponding to the current key frame in the video to be switched is determined according to the current key frame and the index data to obtain the switching key frame, and finally, based on the current key frame, the switching key frame and the index data, the currently playing video is switched to the video to be switched. Compared with the existing video definition switching scheme, the video definition switching method of the present invention can determine the key frame corresponding to the current key frame in the video to be switched according to the current key frame and the index data to obtain the switching key frame, and then, based on the current key frame, the switching key frame and the index data, the currently playing video is switched to the video to be switched. That is to say, in this scheme, the video definition switching is based on the key frame, so the problem of frame skipping playback in the existing scheme can be solved, thereby reducing traffic consumption.
[0101] The method described in the embodiment will be further described in detail below with examples.
[0102] In this embodiment, the video definition switching device is specifically integrated into a terminal as an example for description.
[0103] See also Figure 2a , a method for switching video definition, the specific process can be as follows:
[0104] 201. The terminal obtains the currently playing video.
[0105] There are many ways for the terminal to obtain the currently playing video, for example, it can be obtained from the Internet and / or a specified database, which can be determined according to the needs of the actual application. The currently playing video can include TV series, movies, and user-recorded videos, etc.
[0106] It should be noted that before the video switches, the terminal can construct a video data buffer, which can be used to store and manage video source data segments, that is, optionally, in some embodiments, the terminal can specifically construct a video data buffer, and then the terminal loads the video data corresponding to the currently playing video in the video data buffer.
[0107] 202. When receiving a video definition switching request triggered by a user, the terminal obtains a to-be-switched video that is consistent with the content of the currently playing video.
[0108] The bit rate of the currently playing video is different from the bit rate of the video to be switched. For example, Figure 2b The terminal may be installed with a client, which may be any client that can provide video playback services. A display page corresponding to the currently playing video may be displayed on the display screen of the terminal, and the display page may include a switching control A, a switching control B, and a switching control C. When the terminal receives a video definition switching request triggered by a user, if the terminal detects a selection operation of the user on the switching control C, the terminal obtains a video to be switched that is consistent with the content of the currently playing video and has a definition corresponding to the switching control C.
[0109] 203. The terminal loads index data corresponding to the video to be switched.
[0110] For an MP4 file, the most important thing is the index data, which records the decoding information, timestamp, position and other data of all subsequent audio frames and video frames. Of course, the same is true for switching the clarity of the currently playing video based on other streaming protocols, which will not be repeated here.
[0111] 204. The terminal extracts the current key frame of the currently playing video to obtain the current key frame.
[0112] Among them, video frames can include key frames (I frames), forward prediction frames (P frames) and bidirectional prediction frames (B frames). I frames are internally coded frames, which are the first frame of each image and a complete picture; P frames are forward prediction frames, which record the changes relative to the I frame or the adjacent previous P frame; B frames are bidirectional interpolation frames, which are different from P frames in that they can refer to either the I frame or the adjacent previous frame or the adjacent next frame, that is, P frames record the changes relative to the adjacent previous and next frames, such as Figure 2cAs shown, video playback can be understood as being completed by rendering continuous picture frames in sequence, but in order to transmit the video, it must be encoded and compressed. Each small video segment is composed of an I frame and multiple B frames and P frames, among which B frames and P frames rely on I frames for compression encoding. The I frame is always the first frame in each video clip. In other words, if you want to play this small picture segment, you must first find the I frame, and then you can successfully decode the corresponding B frame and P frame. It should be noted that there is no limitation on the order of step 203 and step 204.
[0113] 205. The terminal determines a key frame corresponding to the current key frame in the video to be switched according to the current key frame and the index data, and obtains a switching key frame.
[0114] Since the content of the currently playing video is consistent with the video to be switched, that is, the number of images recorded in the two videos is the same, the number of key frames corresponding to the two videos is also consistent, that is, each key frame in the video to be switched has a corresponding key frame in the currently playing video. For example, the terminal obtains the video data of the currently playing video to obtain the first video data, and then the terminal determines the key frame corresponding to the current key frame in the video to be switched according to the first video data, the current key frame and the index data to obtain the switching key frame. Further, for example, specifically, the terminal obtains the position of the current key frame in the first video data, which indicates that the current key frame is at the 8th frame in the first video data. Then, the terminal loads the video data corresponding to the video to be switched based on the index data, and the terminal obtains the key frame corresponding to the current key frame in the video data corresponding to the video to be switched according to the position information to obtain the switching key frame.
[0115] 206. The terminal switches the currently playing video to the video to be switched based on the current key frame, the switching key frame and the index data.
[0116] Specifically, the terminal can calculate the video data to be loaded for the video to be switched according to the current key frame, the switching key frame and the index data, and then the terminal switches the currently played video to the video to be switched based on the switching key frame and the video data to be loaded.
[0117] For example, see Figure 2dIf the current key frame is the third key frame, the terminal can determine that the video data of the currently played video includes: the video data of the first frame, the video data of the second frame and the video data of the third frame according to the current key frame. Then, the terminal can obtain the video data of the video to be switched based on the index data. The terminal calculates the video data that needs to be loaded for the video to be switched through the current key frame and the played video data. Finally, the terminal switches the currently played video to the video to be switched based on the switching key frame and the video data that needs to be loaded. For example, as shown in the figure, the video can be switched at the third frame I frame. For another example, in order to improve the smoothness of video playback, the video can be switched at the next frame of the switching key frame, that is, it can be switched at the fourth frame I frame. The specific setting is made according to the actual situation.
[0118] Optionally, in some embodiments, after switching to play the video to be switched, the terminal may delete the video data corresponding to the currently playing video in the video data buffer.
[0119] As can be seen from the above, the terminal of the present invention first obtains the currently playing video and obtains the currently playing video. When receiving a video definition switching request triggered by a user, the terminal obtains the video to be switched that is consistent with the content of the currently playing video. Then, the terminal loads the index data corresponding to the video to be switched. Then, the terminal extracts the current key frame of the currently playing video and obtains the current key frame. Then, the terminal determines the key frame corresponding to the current key frame in the video to be switched according to the current key frame and the index data to obtain the switching key frame. Finally, the terminal switches the currently playing video to the video to be switched based on the current key frame, the switching key frame and the index data. Compared with the existing video definition switching scheme, the terminal of the present invention can determine the key frame corresponding to the current key frame in the video to be switched according to the current key frame and the index data to obtain the switching key frame. Then, the terminal switches the currently playing video to the video to be switched based on the current key frame, the switching key frame and the index data. That is to say, in this scheme, the terminal switches the video definition based on the key frame. Therefore, the problem of frame skipping playback in the existing scheme can be solved, thereby reducing traffic consumption.
[0120] In order to facilitate better implementation of the video definition switching method of the embodiment of the present invention, the embodiment of the present invention also provides a switching device based on the above video definition (switching device for short). The meanings of the terms are the same as those in the above video definition switching method, and the specific implementation details can refer to the description in the method embodiment.
[0121] See also Figure 3a , Figure 3aA schematic diagram of the structure of a first implementation of a device for switching video definition provided in an embodiment of the present invention, wherein the switching device may include a first acquisition module 301, a second acquisition module 302, a loading module 303, an extraction module 304, a determination module 305 and a switching module 306, which may be specifically as follows:
[0122] The first acquisition module 301 is used to acquire the currently playing video.
[0123] Among them, there are many ways for the first acquisition module 301 to obtain the currently playing video, for example, it can be obtained from the Internet and / or a specified database, which can be determined according to the needs of actual applications. The currently playing video may include TV series, movies, and user-recorded videos, etc.
[0124] The second acquisition module 302 is used to acquire a video to be switched that is consistent with the content of the currently playing video when receiving a request for switching the video definition triggered by the user.
[0125] Among them, the bit rate of the currently playing video is different from the bit rate of the video to be switched. The bit rate is the number of data bits transmitted per unit time during data transmission, and the unit is kbps (kilobits per second), which is the sampling rate. The higher the sampling rate per unit time, the higher the accuracy, and the processed file is closer to the original file. The higher the bit rate, the clearer it is, otherwise the picture will be rough.
[0126] The loading module 303 is used to load the index data corresponding to the video to be switched.
[0127] In the embodiment of the present invention, during the video playback process, the terminal and the server follow the video transmission protocol, which may include: Real Time Messaging Protocol (RTMP) and HLS (HTTP Live Streaming) protocol, etc. Unless otherwise specified, the subsequent embodiments of the present invention all take the HLS protocol as an example. The HLS protocol is a streaming media solution, which includes a video index and video fragments. The video index records the index of each video fragment. When a user plays a video through a terminal, the video index is not played directly, but the video index is parsed to obtain the index of each video fragment, and the URL of the corresponding video fragment is found according to the index for playback. Each video fragment is a video content of a video to be played, which includes a timestamp and data such as the video content corresponding to the timestamp. For example, the formats of the currently playing video and the video to be switched are both in the fourth generation moving picture expert group (Moving Picture Experts Group 4, MP4) format. For an MP4 file, the most important thing is the index data. The index data records the decoding information, timestamp, position and other data of all subsequent audio frames and video frames. Of course, the same is true for switching the clarity of the currently playing video based on other streaming media protocols, which will not be repeated here.
[0128] The extraction module 304 is used to extract the current key frame of the currently playing video to obtain the current key frame.
[0129] The determination module 305 is used to determine the key frame corresponding to the current key frame in the video to be switched according to the current key frame and the index data, and obtain the switching key frame.
[0130] Since the content of the currently playing video is consistent with the video to be switched, that is, the number of images recorded in the two videos is the same, the number of key frames corresponding to the two videos is also consistent, that is, each key frame in the video to be switched has a corresponding key frame in the currently playing video. In an embodiment of the present invention, the determination module 305 can determine the key frame in the video to be switched that corresponds to the current key frame based on the current key frame and index data.
[0131] Optionally, in some embodiments, the determination module 305 may specifically include:
[0132] An acquisition submodule, used to acquire video data of a current key frame from a currently playing video, to obtain first video data;
[0133] The determination submodule is used to select a key frame that meets a preset condition in the video to be switched according to the first video data, the current key frame and the index data to obtain a switching key frame.
[0134] Optionally, in some embodiments, the determining submodule may specifically include:
[0135] An acquisition unit, used to acquire a position of a current key frame in the first video data, and obtain position information corresponding to the current key frame;
[0136] The selection unit is used to select a key frame that meets a preset condition in the video to be switched according to the index data to obtain a switching key frame.
[0137] Optionally, in some embodiments, the selection unit may specifically include:
[0138] A loading subunit, used for loading the video data corresponding to the video to be switched based on the index data to obtain the second video data;
[0139] The selection subunit is used to select a key frame matching the position information of the current key frame in the second video data to obtain a switching key frame.
[0140] Optionally, in some embodiments, the acquisition sub-unit can be specifically used to: extract the timestamp corresponding to the current key frame to obtain a first timestamp, and extract the timestamp corresponding to each key frame in the second video data to obtain multiple second timestamps, determine the key frame whose second timestamp is consistent with the first timestamp as the key frame corresponding to the current key frame, and obtain a switching key frame.
[0141] The switching module 306 is used to switch the currently played video to the video to be switched based on the current key frame, the switching key frame and the index data.
[0142] For example, specifically, the video data required to be loaded for the video to be switched can be calculated based on the current key frame, switching key frame and index data, and then, based on the switching key frame and the video data required to be loaded, the currently playing video can be switched to the video to be switched.
[0143] Optionally, in some embodiments, the switching module 306 can be specifically used to: determine the video data that has been played of the currently playing video based on the current key frame, calculate the video data that needs to be loaded for the video to be switched through the current key frame, the played video data and the index data, update the preset video data buffer with the video data to be loaded, obtain an updated buffer, take the switching key frame as the starting point, and switch the currently playing video to play the video to be switched based on the video data to be loaded and the updated buffer.
[0144] Optionally, in some embodiments, see Figure 3b , and also includes a deletion module 307, which is specifically used to delete the video data corresponding to the currently playing video in the buffer after the update.
[0145] Optionally, in some embodiments, see Figure 3c , also includes a construction module 308, which can be specifically used to: construct a video data buffer, and load the video data corresponding to the currently played video into the video data buffer.
[0146] It can be seen that the first acquisition module 301 in the video clarity switching device of the embodiment of the present invention acquires the currently playing video. After obtaining the currently playing video, the second acquisition module 302, when receiving a video clarity switching request triggered by a user, acquires the video to be switched that is consistent with the content of the currently playing video. Then, the loading module 303 loads the index data corresponding to the video to be switched. Then, the extraction module 304 extracts the current key frame of the currently playing video to obtain the current key frame. Then, the determination module 305 determines the key frame corresponding to the current key frame in the video to be switched according to the current key frame and the index data to obtain the switching key frame. Finally, the switching module 306 switches the currently playing video to the video to be switched based on the current key frame, the switching key frame and the index data. Compared with the existing video clarity switching scheme, the determination module 305 of the present invention can determine the key frame corresponding to the current key frame in the video to be switched according to the current key frame and index data to obtain the switching key frame. Then, the switching module 306 switches the currently playing video to the video to be switched based on the current key frame, the switching key frame and the index data. That is to say, in this scheme, the video clarity switching is based on the key frame. Therefore, the problem of frame skipping playback in the existing scheme can be solved, thereby reducing traffic consumption.
[0147] In addition, an embodiment of the present invention further provides an electronic device, such as Figure 4 As shown, it shows a schematic diagram of the structure of an electronic device involved in an embodiment of the present invention, specifically:
[0148] The electronic device may include components such as a processor 401 with one or more processing cores, a memory 402 with one or more computer-readable storage media, a power supply 403, and an input unit 404. Those skilled in the art will appreciate that Figure 4 The electronic device structure shown in the figure does not constitute a limitation on the electronic device, and may include more or fewer components than shown in the figure, or combine certain components, or arrange the components differently.
[0149] The processor 401 is the control center of the electronic device, and uses various interfaces and lines to connect various parts of the entire electronic device. By running or executing software programs and / or modules stored in the memory 402, and calling data stored in the memory 402, the processor 401 performs various functions of the electronic device and processes data, thereby monitoring the electronic device as a whole. Optionally, the processor 401 may include one or more processing cores; preferably, the processor 401 may integrate an application processor and a modem processor, wherein the application processor mainly processes the operating system, user interface, and application programs, and the modem processor mainly processes wireless communications. It is understandable that the above-mentioned modem processor may not be integrated into the processor 401.
[0150] The memory 402 can be used to store software programs and modules. The processor 401 executes various functional applications and data processing by running the software programs and modules stored in the memory 402. The memory 402 may mainly include a program storage area and a data storage area, wherein the program storage area may store an operating system, an application required for at least one function (such as a sound playback function, an image playback function, etc.), etc.; the data storage area may store data created according to the use of the electronic device, etc. In addition, the memory 402 may include a high-speed random access memory, and may also include a non-volatile memory, such as at least one disk storage device, a flash memory device, or other volatile solid-state storage devices. Accordingly, the memory 402 may also include a memory controller to provide the processor 401 with access to the memory 402.
[0151] The electronic device also includes a power supply 403 for supplying power to each component. Preferably, the power supply 403 can be logically connected to the processor 401 through a power management system, so as to manage charging, discharging, power consumption and other functions through the power management system. The power supply 403 can also include one or more DC or AC power supplies, recharging systems, power failure detection circuits, power converters or inverters, power status indicators and other arbitrary components.
[0152] The electronic device may further include an input unit 404, which may be used to receive input digital or character information and generate keyboard, mouse, joystick, optical or trackball signal input related to user settings and function control.
[0153] Although not shown, the electronic device may further include a display unit, etc., which will not be described in detail herein. Specifically in this embodiment, the processor 401 in the electronic device will load the executable files corresponding to the processes of one or more application programs into the memory 402 according to the following instructions, and the processor 401 will run the application programs stored in the memory 402, thereby realizing various functions, as follows:
[0154] Get the currently playing video, get the currently playing video, when receiving a user-triggered video clarity switching request, get the video to be switched that is consistent with the content of the currently playing video, load the index data corresponding to the video to be switched, extract the current key frame of the currently playing video, get the current key frame, determine the key frame in the video to be switched that corresponds to the current key frame according to the current key frame and the index data, get the switching key frame, and switch the currently playing video to the video to be switched based on the current key frame, the switching key frame and the index data.
[0155] The specific implementation of the above operations can be found in the previous embodiments, which will not be described in detail here.
[0156] The embodiment of the present invention first obtains the currently playing video, and obtains the currently playing video. When a video definition switching request triggered by a user is received, the video to be switched that is consistent with the content of the currently playing video is obtained, and then the index data corresponding to the video to be switched is loaded, and then the current key frame of the currently playing video is extracted to obtain the current key frame, and then the key frame corresponding to the current key frame in the video to be switched is determined according to the current key frame and the index data to obtain the switching key frame, and finally, based on the current key frame, the switching key frame and the index data, the currently playing video is switched to the video to be switched. Compared with the existing video definition switching scheme, the video definition switching method of the present invention can determine the key frame corresponding to the current key frame in the video to be switched according to the current key frame and the index data to obtain the switching key frame, and then, based on the current key frame, the switching key frame and the index data, the currently playing video is switched to the video to be switched. That is to say, in this scheme, the video definition switching is based on the key frame, so the problem of frame skipping playback in the existing scheme can be solved, thereby reducing traffic consumption.
[0157] A person of ordinary skill in the art will appreciate that all or part of the steps in the various methods of the above embodiments may be completed by instructions, or by controlling related hardware through instructions. The instructions may be stored in a computer-readable storage medium and loaded and executed by a processor.
[0158] To this end, an embodiment of the present invention provides a storage medium in which a plurality of instructions are stored, and the instructions can be loaded by a processor to execute the steps in any one of the video definition switching methods provided in the embodiment of the present invention. For example, the instructions can execute the following steps:
[0159] Get the currently playing video, get the currently playing video, when receiving a user-triggered video clarity switching request, get the video to be switched that is consistent with the content of the currently playing video, load the index data corresponding to the video to be switched, extract the current key frame of the currently playing video, get the current key frame, determine the key frame in the video to be switched that corresponds to the current key frame according to the current key frame and the index data, get the switching key frame, and switch the currently playing video to the video to be switched based on the current key frame, the switching key frame and the index data.
[0160] The specific implementation of the above operations can be found in the previous embodiments, which will not be described in detail here.
[0161] The storage medium may include: a read-only memory (ROM), a random access memory (RAM), a magnetic disk or an optical disk, etc.
[0162] Since the instructions stored in the storage medium can execute the steps in any video definition switching method provided in the embodiments of the present invention, the beneficial effects that can be achieved by any video definition switching method provided in the embodiments of the present invention can be achieved. Please refer to the previous embodiments for details and will not be repeated here.
[0163] The above is a detailed introduction to a video definition switching method, device, electronic device and storage medium provided in an embodiment of the present invention. Specific examples are used in this article to illustrate the principles and implementation methods of the present invention. The description of the above embodiments is only used to help understand the method of the present invention and its core idea. At the same time, for technical personnel in this field, according to the idea of the present invention, there will be changes in the specific implementation method and application scope. In summary, the content of this specification should not be understood as a limitation on the present invention.
Claims
1. A method for switching video definition, It is characterized in that include: Get the currently playing video; When a request for switching the video definition triggered by the user is received, a video to be switched with the same number of images as the currently playing video is obtained, and the definition of the currently playing video is the same as that of the video to be switched. Clarity Different, the number of key frames corresponding to the currently playing video and the video to be switched is the same; Loading index data corresponding to the video to be switched, the index data including decoding information, timestamps, and positions of audio frames and video frames in the video to be switched; Extract the current key frame of the currently playing video to obtain the current key frame; Acquire the video data where the current key frame is located from the currently playing video to obtain first video data; Acquire the position of the current key frame in the first video data to obtain position information corresponding to the current key frame; Load the video data corresponding to the video to be switched based on the index data to obtain second video data; Selecting a key frame matching the position information in the second video data to obtain a switching key frame includes: extracting a timestamp corresponding to the current key frame to obtain a first timestamp, extracting a timestamp corresponding to each key frame in the second video data to obtain a plurality of second timestamps; determining a key frame consistent with the first timestamp among the plurality of second timestamps as a key frame corresponding to the current key frame to obtain a switching key frame; wherein the switching key frame includes determining a key frame consistent with the timestamp or image content corresponding to the current key frame in the video data corresponding to the video to be switched based on the video data where the current key frame is located, the current key frame and the index data; Based on the current key frame, the switching key frame and the index data, the video data that needs to be loaded for the video to be switched is determined, and the video data buffer is updated according to the video data that needs to be loaded, and based on the video data in the updated buffer, the currently playing video is switched to the video to be switched, including: determining the video data that has been played for the currently playing video according to the current key frame; calculating the video data that needs to be loaded for the video to be switched by using the current key frame, the played video data and the index data; updating the preset video data buffer by the video data that needs to be loaded to obtain an updated buffer; taking the switching key frame as the starting point, based on the video data that needs to be loaded and the updated buffer, the currently playing video is switched to the video to be switched.
2. The method according to claim 1, It is characterized in that After switching the currently played video to the video to be switched based on the video data to be loaded and the updated buffer zone with the switching key frame as the starting point, the method further includes: Delete the video data corresponding to the currently playing video in the updated buffer.
3. The method according to claim 1, It is characterized in that Before getting the currently playing video, the following is also included: Build video data buffer; The video data corresponding to the currently playing video is loaded into the video data buffer.
4. A device for switching video definition, It is characterized in that include: The first acquisition module is used to acquire the currently playing video and obtain the currently playing video; A second acquisition module is used to, when receiving a video definition switching request triggered by a user, acquire a video to be switched having the same number of images as the currently playing video, wherein the definition of the currently playing video is different from that of the video to be switched, and the number of key frames corresponding to the currently playing video and the video to be switched is the same; A loading module, used to load index data corresponding to the video to be switched, wherein the index data includes decoding information, timestamps, and positions of audio frames and video frames in the video to be switched; An extraction module is used to extract the current key frame of the currently playing video to obtain the current key frame; A determination module is used to determine the key frame corresponding to the current key frame in the video to be switched according to the current key frame and the index data, and obtain the switching key frame; wherein the switching key frame includes determining the key frame in the video data corresponding to the video to be switched, which has the same timestamp or image content as the current key frame, based on the video data where the current key frame is located, the current key frame and the index data; A switching module is used to determine the video data that needs to be loaded for the video to be switched based on the current key frame, the switching key frame and the index data, and to update the video data buffer according to the video data that needs to be loaded, and to switch the currently played video to the video to be switched based on the video data in the updated buffer, including: determining the video data that has been played for the currently played video according to the current key frame; calculating the video data that needs to be loaded for the video to be switched by using the current key frame, the played video data and the index data; updating the preset video data buffer by using the video data that needs to be loaded to obtain an updated buffer; taking the switching key frame as the starting point, switching the currently played video to the video to be switched based on the video data that needs to be loaded and the updated buffer; Wherein, the determination module includes: An acquisition submodule, used to acquire the video data where the current key frame is located from the currently playing video to obtain the first video data; A determination submodule, configured to select a key frame satisfying a preset condition in the video to be switched according to the first video data, the current key frame and the index data, and obtain a switching key frame; The determination submodule comprises: An acquisition unit, used to acquire a position of a current key frame in the first video data, and obtain position information corresponding to the current key frame; A selection unit, configured to select a key frame satisfying a preset condition in the video to be switched according to the index data, to obtain a switching key frame; The selection unit comprises: A loading subunit, configured to load the video data corresponding to the to-be-switched video based on the index data to obtain second video data; A selection subunit is used to select a key frame matching the position information in the second video data to obtain a switching key frame, including: extracting a timestamp corresponding to a current key frame to obtain a first timestamp, extracting a timestamp corresponding to each key frame in the second video data to obtain a plurality of second timestamps; and determining a key frame consistent with the first timestamp among the plurality of second timestamps as a key frame corresponding to the current key frame to obtain a switching key frame.
5. An electronic device comprising a memory, a processor and a computer program stored in the memory and executable on the processor, in, When the processor executes the program, the steps of the method for switching the video definition as described in any one of claims 1 to 3 are implemented.
6. A storage medium, It is characterized in that A computer program is stored thereon, wherein when the computer program is executed by a processor, the steps of the method for switching the video definition as described in any one of claims 1 to 3 are implemented.
