Video processing method and device, electronic equipment and storage medium
By obtaining the target image group during the video interception process and directly reading the encoded frames, avoiding re-encoding, the problems of long-term video interception and high resource utilization are solved, and more efficient video interception is achieved.
Patent Information
- Application Number
- CN202410108093.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-01-25
- Publication Date
- 2025-07-25
AI Technical Summary
The prior art processes time-consuming and resource occupancy is high during the video interception process, which affects the performance of the video interception function.
By obtaining the video interception points of the target video, determining the target image group, and directly reading the encoded frames before or after the target image group from the target video, avoiding the re-encoding process and generating the interception video.
It reduces the amount of data encoding and decoding in the video interception process, reduces processing time and resource overhead, and improves the performance of the video interception function.
Smart Images

Figure CN120378687A_ABST
Abstract
Description
Technical Field
[0001] Embodiments of the present disclosure relate to the field of image processing technology, and in particular, to a video processing method, apparatus, electronic device, and storage medium. Background Art
[0002] Currently, intercepting and segmenting videos are common functions in video editing applications. The specific implementation method is to intercept the original video and then process the intercepted part to generate an independent video file, thereby completing the video interception process.
[0003] However, in the existing technology solutions, during the process of intercepting and processing videos, there are problems of long processing time and high resource occupancy, which affect the performance of the video interception function. Summary of the Invention
[0004] Embodiments of the present disclosure provide a video processing method, apparatus, electronic device, and storage medium to overcome the problems of long processing time and high resource occupancy during video interception.
[0005] In a first aspect, embodiments of the present disclosure provide a video processing method, including:
[0006] Responding to a video interception instruction, obtaining a video interception point for a target video; obtaining a corresponding target image group according to the video interception point, where the target image group includes at least one positioning frame of the target video; obtaining a first coded frame corresponding to the target image group, and directly reading a second coded frame corresponding to the video interception instruction from the target video, where the second coded frame is before or after the target image group; generating an intercepted video corresponding to the video interception instruction based on the first coded frame and the second coded frame.
[0007] In a second aspect, embodiments of the present disclosure provide a video processing apparatus, including:
[0008] An interaction module, configured to respond to a video interception instruction and obtain a video interception point for a target video;
[0009] A processing module, configured to obtain a corresponding target image group according to the video interception point, where the target image group includes at least one positioning frame of the target video;
[0010] An encoding module, configured to obtain a first coded frame corresponding to the target image group, and directly read a second coded frame corresponding to the video interception instruction from the target video, where the second coded frame is before or after the target image group;
[0011] A generation module, configured to generate an intercepted video corresponding to the video interception instruction based on the first coded frame and the second coded frame.
[0012] In a third aspect, embodiments of the present disclosure provide an electronic device, including: a processor and a memory;
[0013] The memory stores computer-executable instructions;
[0014] The processor executes the computer-executable instructions stored in the memory, so that the at least one processor executes the video processing method described in the first aspect and various possible designs of the first aspect as above.
[0015] In a fourth aspect, embodiments of the present disclosure provide a computer-readable storage medium, in which computer-executable instructions are stored. When the processor executes the computer-executable instructions, the video processing method described in the first aspect and various possible designs of the first aspect as above is implemented.
[0016] In a fifth aspect, embodiments of the present disclosure provide a computer program product, including a computer program. When the computer program is executed by a processor, the video processing method described in the first aspect and various possible designs of the first aspect as above is implemented.
[0017] The video processing method, device, electronic device, and storage medium provided in this embodiment obtain a video capture point for a target video in response to a video capture instruction; obtain a corresponding target image group according to the video capture point, where the target image group includes at least one positioning frame of the target video; obtain a first encoded frame corresponding to the target image group, and directly read a second encoded frame corresponding to the video capture instruction from the target video, where the second encoded frame is located before or after the target image group; generate a captured video corresponding to the video capture instruction based on the first encoded frame and the second encoded frame. By dividing the video capture process into two parts: obtaining the first encoded frame and the second encoded frame, and then combining the first encoded frame and the second encoded frame to generate the captured video. In this process, the first encoded frame corresponding to the video capture point is obtained by re-encoding, and the second encoded frame outside the video capture point is obtained by direct reading, thus avoiding the re-encoding process of the second encoded frame, achieving the effect of reducing the data encoding and decoding amount of the captured video, and further reducing the processing time and resource overhead of the video capture process, and improving the performance of the video capture function. Description of the Drawings
[0018] To more clearly illustrate the technical solutions in the embodiments of the present disclosure or the prior art, the following will briefly introduce the accompanying drawings required for the description of the embodiments or the prior art. Obviously, the accompanying drawings in the following description are some embodiments of the present disclosure. For those of ordinary skill in the art, without creative efforts, other accompanying drawings can also be obtained based on these drawings.
[0019] Figure 1 It is a schematic diagram of an application scenario of the video processing method provided by the embodiment of the present disclosure;
[0020] Figure 2 It is a flowchart of the video processing method provided by the embodiment of the present disclosure Figure 1 ;
[0021] Figure 3 For Figure 2 It is a flowchart of the specific implementation manner of step S102 in the illustrated embodiment;
[0022] Figure 4 For Figure 2 It is a flowchart of the specific implementation manner of step S104 in the illustrated embodiment;
[0023] Figure 5 It is a schematic diagram of the process of generating an intercepted video provided by the embodiment of the present disclosure;
[0024] Figure 6 It is a flowchart of the video processing method provided by the embodiment of the present disclosure Figure 2 ;
[0025] Figure 7 It is another schematic diagram of the process of generating an intercepted video provided by the embodiment of the present disclosure;
[0026] Figure 8 For Figure 6 It is a flowchart of a possible implementation manner of step S207 in the illustrated embodiment;
[0027] Figure 9 For Figure 6 It is a flowchart of another possible implementation manner of step S207 in the illustrated embodiment;
[0028] Figure 10 It is a block diagram of the structure of the video processing apparatus provided by the embodiment of the present disclosure;
[0029] Figure 11 It is a schematic diagram of the structure of an electronic device provided by the embodiment of the present disclosure;
[0030] Figure 12 It is a schematic diagram of the hardware structure of the electronic device provided by the embodiment of the present disclosure. Specific embodiments
[0031] To make the objectives, technical solutions, and advantages of the embodiments of the present disclosure clearer, the technical solutions in the embodiments of the present disclosure will be clearly and completely described below with reference to the accompanying drawings in the embodiments of the present disclosure. Apparently, the described embodiments are some, but not all, of the embodiments of the present disclosure. All other embodiments obtained by those of ordinary skill in the art based on the embodiments in the present disclosure without creative efforts shall fall within the protection scope of the present disclosure.
[0032] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data for analysis, stored data, displayed data, etc.) involved in the present disclosure are all information and data that have been authorized by the user or fully authorized by all parties. Moreover, the collection, use, and processing of relevant data need to comply with relevant laws, regulations, and standards in relevant countries and regions, and corresponding operation entrances are provided for users to select authorization or rejection.
[0033] The application scenarios of the embodiments of the present disclosure will be explained below:
[0034] Figure 1 FIG. is an application scenario diagram of the video processing method provided in the embodiments of the present disclosure. The video processing method provided in the embodiments of the present disclosure can be applied to an application program with a video capture function. More specifically, it can be applied to an application scenario where a video is captured to generate an independent video file. The execution subject of this embodiment can be a terminal device running the above application program with a video capture function, or a server deploying the corresponding service end of the above application program, or other electronic devices with similar functions. Refer to Figure 1 As shown in, taking the terminal device as an example, after the terminal device runs the above application program with a video capture function, it first loads the target video based on the H264 standard in the application program. Then, the user triggers the video capture function by operating the video editing interface and selects the video capture range, such as between the playback timestamps A and B of the target video shown in the figure. After that, the terminal device captures the target video according to the selected video capture range by the user and generates a video file that only contains the video segment corresponding to the playback timestamps A and B of the target video. Of course, in another possible application scenario, the video capture range can be determined by the terminal device or the server based on other judgment logics. For example, the terminal device determines a video capture range according to the video content of the target video to capture the target video, so as to achieve the adaptive segmentation of the target video based on the content.
[0035] In the prior art, during the process of a terminal device intercepting a target video according to a video interception range, the video data in the video file corresponding to the target video is in a compressed state. To ensure that the intercepted video segment can be played normally, it is necessary to decode all the video data of the intercepted part of the video and then re-encode it all. This results in the need to perform decoding and re-encoding processing steps on a large amount of video data (compressed encoded frames), thus causing problems such as long processing time and high resource occupancy.
[0036] Embodiments of the present disclosure provide a video processing method to solve the above problems.
[0037] Refer to Figure 2 , Figure 2 which is a flowchart illustration of the video processing method provided by the embodiments of the present disclosure. Figure 1 The method of this embodiment can be applied to a terminal device. The video processing method includes:
[0038] Step S101: In response to a video interception instruction, obtain a video interception point for the target video.
[0039] Exemplarily, referring to Figure 1 the schematic diagram of the application scenario shown, after the terminal device runs the application program and loads the target video to be segmented, by responding to the video interception instruction, the corresponding video interception point is obtained. Among them, the video interception instruction can be an operation instruction input by the user through the interaction interface of the application program, or an instruction sent by the server of the application program received by the terminal device to indicate the video interception position, or an instruction generated by the terminal device through the processing logic in the application program, such as an instruction generated based on the video content of the target video for intercepting the target video based on the video content, which can be specifically set according to needs and will not be elaborated here.
[0040] After that, the terminal device obtains the video interception point for the target video according to the information in the video interception instruction. Among them, the video interception point can be the frame identifier of a specific encoded frame of the target video. The encoded frame is a video frame compressed by a compression algorithm (such as the H264 compression algorithm), and it needs to be decoded in its entirety before it can be displayed. The specific implementation principle of video frame encoding and decoding is prior art and can be specifically referred to the relevant description of the H264 standard, which will not be elaborated here. In another possible implementation manner, the video interception point can also be the playback timestamp of the target video, and then the terminal device obtains the frame identifier of the corresponding encoded frame by converting the playback timestamp.
[0041] Step S102: Obtain the corresponding target picture group according to the video interception point. The target picture group includes at least one positioning frame of the target video.
[0042] Exemplarily, further, after obtaining the video capture point, the terminal device determines the picture group to which the coded frame corresponding to the video capture point (frame identifier) belongs, that is, the target picture group, according to the video capture point (frame identifier). Herein, a picture group (Group of picture, GOP) is a set of multiple coded frames. Within a picture group, there is at least one positioning frame, which may be an intra picture, also known as an I-frame or a key frame, or may be an instantaneous decoding refresh (IDR) frame for refreshing the decoding process. IDR frames and I-frames are usually adjacent and appear successively in the video file. By decoding the coded frames within a picture group, the display of the corresponding video segment can be achieved. Herein, the picture group in this embodiment is a closed GOP. Exemplarily, the video capture point may include a capture start point and / or a capture end point. When the video capture point is the capture start point or the capture end point (a single point), the other point representing the capture range is a static point representing the last frame or the first frame of the target video. The capture start point and / or the capture end point respectively correspond to their respective target picture groups. When the video capture point corresponds to the first frame or the last frame of the target video, the corresponding target picture group is fixed. When the capture start point and the capture end point do not correspond to the first frame or the last frame of the target video, specific processing needs to be performed on the video capture point to determine the corresponding target picture group.
[0043] Specifically, after obtaining the frame identifier (video capture point), in one possible implementation, the terminal device can directly determine the picture group to which the frame identifier belongs through the reference information of the target video. The coded frames of the target video are pre-grouped based on IDR frames, and the grouping information is recorded in the reference information. Through this reference information, the target picture group where the above frame identifier is located can be found. In another possible implementation, it is possible to perform a search based on the frame identifier to determine the corresponding target picture group. Exemplarily, as Figure 3 shown, the specific implementation manner of step S102 includes:
[0044] Step S1021: According to the video capture point, obtain the first positioning frame closest to the front of the video capture point and the second positioning frame closest to the back of the video capture point.
[0045] Step S1022: Obtain the corresponding target picture group according to the first positioning frame and the second positioning frame.
[0046] Exemplarily, the terminal device, according to the obtained video capture point, such as frame P1, then searches forward and backward from frame P1 in the target video to obtain the positioning frame closest to frame P1 before P1, such as frame I1, and the positioning frame closest to frame P1 after P1, such as frame I2. Then, the coded frames between frame I1 (inclusive) and frame I2 (exclusive) are determined as the target picture group. Wherein, frame I1 and frame I2 can be key frames or IDR frames, which are not limited here.
[0047] Step S103: Obtain the first coded frame corresponding to the target picture group, and directly read the second coded frame corresponding to the video capture instruction from the target video, where the second coded frame is before or after the target picture group.
[0048] Further, exemplarily, the video capture point includes a frame identifier, and the decoded image frame corresponding to the video capture point is the target decoded image frame. Exemplarily, the specific implementation manner of step S103 includes:
[0049] If the video capture point is at the position of the first frame of the target picture group, directly read the compressed packet data corresponding to the target picture group from the target video to obtain the first coded frame; if the video capture point is at a non-first-frame position of the target picture group, decode the target picture group to obtain decoded data; then, perform video encoding starting from the video capture point position of the decoded data until the end of the decoded data to obtain the first coded frame; or, perform video encoding starting from the start position of the decoded data until the video capture point position to obtain the first coded frame.
[0050] Further, for the case where the video capture point is at a non-first-frame position of the target picture group, specifically, taking the case where the video capture point is the capture start point as an example, first obtain the target decoded image frame corresponding to the video capture point; for each coded frame corresponding to the target picture group, perform video encoding on the decoded image frames after the target decoded image frame in sequence until the encoding of the last decoded image frame in the decoded data corresponding to the target picture group is completed to obtain the first coded frame; if the video capture point is the capture end point, after obtaining the target decoded image frame corresponding to the video capture point, starting from the first decoded image frame in the decoded data corresponding to the target picture group, perform video encoding on the decoded image frames before the target decoded image frame in each coded frame corresponding to the target picture group in sequence to obtain the first coded frame.
[0051] On the other hand, for the second encoded frame, in a possible implementation, the video capture point includes a capture start point and a capture end point. The capture start point corresponds to the first target picture group, and the capture end point corresponds to the second target picture group. According to the positions of the first target picture group and the second target picture group, the second encoded frame corresponding to the video capture instruction is directly read from the target video without going through the processes of decoding and encoding, thereby achieving fast capture of video data. Specifically, the specific implementation of step S103 includes: According to the end position of the first target picture group and the start position of the second target picture group, the compressed packet data is sequentially read frame by frame from the video file of the target video to obtain the second encoded frame.
[0052] More specifically, for example, when the video capture point is the capture start point, according to the end position of the first target picture group, starting from the end position of the first target picture group in the video file of the target video, the compressed packet data is read backward until reaching the end of the video file of the target video. All the read compressed packet files are used as the second encoded frame. For another example, when the video capture point is the capture end point, according to the start position of the second target picture group, starting from the start position of the video file of the target video, the compressed packet data is read backward until reaching the start position of the second target picture group. All the read compressed packet files are used as the second encoded frame. For still another example, when the video capture point includes the capture start point and the capture end point, starting from the end position of the first target picture group in the video file of the target video, the compressed packet data is read backward until reaching the start position of the second target picture group. All the read compressed packet files are used as the second encoded frame.
[0053] Step S104: Generate the captured video corresponding to the video capture instruction based on the first encoded frame and the second encoded frame.
[0054] Exemplarily, based on the introduction of the previous steps, the obtained first encoded frame and second encoded frame are combined based on their respective playback orders in the target video to generate the captured video corresponding to the video capture instruction.
[0055] Specifically, starting from the target picture group position, the subsequent encoded frame, that is, the second encoded frame, is obtained from the target video. This second encoded frame is directly read from the video file corresponding to the target video, so there is no need to perform the above-mentioned decoding and re-encoding processes. Then, the first encoded frame and the second encoded frame are written into the corresponding video file to generate the captured video corresponding to the video capture instruction.
[0056] Exemplarily, as Figure 4 shown, the specific implementation of step S104 includes:
[0057] Step S1041: Create a video capture file.
[0058] Step S1042: Write the first encoded frame and the second encoded frame into a preset intercepted video file in sequence to generate an intercepted video.
[0059] Exemplarily, the video file of the target video stores compressed packet data frame by frame, and each compressed packet corresponds to an encoded frame (frame identifier). After the terminal device loads the target video, starting from the identifier of the encoded frame corresponding to the cut-off position of the target image group, the corresponding compressed packets are sequentially read from the video file to obtain the second encoded frame. The process of reading the second encoded frame can be carried out simultaneously or successively with the process of generating the first encoded frame described above, and no specific limitation is made here. After that, the first encoded frame and the second encoded frame generated in the above steps are written into a preset intercepted video file synchronously or asynchronously in sequence to generate an intercepted video.
[0060] Among them, according to different implementation manners of the video interception point, when the video interception point only includes an interception start point, the second encoded frame is the encoded frame from the interception start point to the end of the target video; when the video interception point includes an interception start point and an interception end point, the second encoded frame is the encoded frame in the target video from the interception start point to the interception end point. Correspondingly, when the video interception point includes an interception start point and an interception end point, the first encoded frame includes a part of the encoded frames before the second encoded frame (hereinafter referred to as the first sub-encoded frame) and a part of the encoded frames after the second encoded frame (hereinafter referred to as the second sub-encoded frame). When writing into the intercepted video file, the first sub-encoded frame, the second encoded frame, and the second sub-encoded frame are written into the intercepted video file in sequence to generate an intercepted video.
[0061] Figure 5 FIG. is a schematic diagram of a process for generating an intercepted video provided by an embodiment of the present disclosure. The following will be combined with Figure 5 to introduce the above process in more detail. As Figure 5 shown, exemplarily, first, based on a video interception instruction, it is determined that the video interception point is the P_1 frame; after the terminal device processes and determines that the P_1 frame is located in the GOP_1 image group, the terminal device decodes all the encoded frames in the GOP_1 image group to obtain decoded data, and then starts from the P_1 frame position in the decoded data, encodes the decoded images in the GOP_1 image group after the P_1 frame to obtain encoded data D1. The encoded frames in the encoded data are the first encoded frames. Then, the encoded data D2 after the GOP_1 image group in the target video is read, and the encoded frames in the encoded data D2 are the second encoded frames; finally, the encoded data D1 and the encoded data D2 are written into the file F1 in sequence to obtain an intercepted video.
[0062] In this embodiment, in response to a video capture instruction, a video capture point for a target video is obtained; according to the video capture point, a corresponding target image group is obtained, and the target image group is decoded to obtain decoded data; wherein, the target image group includes at least one positioning frame of the target video; video encoding is started from the position of the video capture point of the decoded data to obtain a first encoded frame; a second encoded frame located after the target image group is obtained, and based on the first encoded frame and the second encoded frame, a captured video corresponding to the video capture instruction is generated. By dividing the video capture process into two parts: obtaining the first encoded frame and the second encoded frame, and then combining the first encoded frame and the second encoded frame to generate the captured video. In this process, the first encoded frame corresponding to the video capture point is obtained through re-encoding processing, while the second encoded frame outside the video capture point is obtained through direct reading, thereby avoiding the re-encoding process of the second encoded frame, achieving the effect of reducing the data encoding and decoding amount of the captured video, and further reducing the processing time and resource overhead of the video capture process, and improving the performance of the video capture function.
[0063] Reference Figure 6 , Figure 6 is a schematic flowchart of a video processing method provided by an embodiment of the present disclosure Figure 2 . This embodiment is based on Figure 2 the embodiment shown, and adds a step of setting the timestamp of the generated captured video. The video processing method includes:
[0064] Step S201: In response to a video capture instruction, obtain a video capture point for a target video, where the video capture point includes a capture start point and a capture end point.
[0065] Step S202: Obtain a first target image group corresponding to the capture start point and a second target image group corresponding to the capture end point.
[0066] Step S203: Decode the first target image group and the second target image group respectively to obtain first decoded data corresponding to the first target image group and second decoded data corresponding to the second target image group.
[0067] Step S204: Perform video encoding on the first decoded data and the second decoded data respectively to obtain a first video frame, and the first encoded frame includes a first sub-encoded frame and a second sub-encoded frame.
[0068] Exemplarily, in this embodiment, the video capture points include a capture start point and a capture end point. Among them, the capture start point is after the first encoded frame of the target video, and the capture end point is before the last encoded frame of the target video. Therefore, through the capture start point and the capture end point, a video segment at any position within the target video frame can be obtained, thereby achieving more flexible video capture. Further, in a possible implementation manner, the video capture points generated based on the video capture instruction may include multiple combinations of the capture start point and the capture end point, that is, each group of "capture start point and capture end point" corresponds to a segment of the target video, and finally a video file of the captured video is generated. The processing methods for each group of "capture start point and capture end point" are the same. In this embodiment, only the case where the video capture point includes one capture start point and one capture end point (a combination of one group of capture start point and capture end point) is described.
[0069] Specifically, after the terminal device obtains the capture start point and the capture end point, it first determines the target image groups corresponding to the capture start point and the capture end point respectively, that is, the first target image group corresponding to the capture start point and the second target image group corresponding to the capture end point. Then, the first target image group and the second target image group are decoded respectively to obtain the first decoded data corresponding to the first target image group and the second decoded data corresponding to the second target image group. After that, the first decoded data and the second decoded data are respectively subjected to video encoding to obtain the first sub-encoded frame and the second sub-encoded frame. The set of the first sub-encoded frame and the second sub-encoded frame is the first encoded frame. Among them, the process of determining the first target image group and the second target image group respectively based on the capture start point and the capture end point, and decoding based on the first target image group and the second target image group to obtain the corresponding first decoded data and second decoded data is the same as Figure 2 the process of obtaining the target image group and the decoded data corresponding to the video capture point in the embodiment shown, which will not be elaborated here.
[0070] After that, the process of performing video encoding on the first decoded data is the same as Figure 2 the implementation process of encoding the decoded data in the embodiment shown, that is, encoding starts from the capture start point and continues backward until the last decoded image frame in the first decoded data is encoded to obtain the first sub-encoded frame; while the process of performing video encoding on the second decoded data is to start encoding from the first decoded image frame of the second decoded data and continue backward until the decoded image frame corresponding to the capture end point is encoded to obtain the second sub-encoded frame.
[0071] Figure 7 Another schematic diagram of the process of generating the captured video provided by the embodiment of the present disclosure is shown in Figure 7As shown in the figure, first, based on the video capture instruction, the capture start point is determined as frame P1 and the capture end point is determined as frame P2. The terminal device determines through processing that frame P_1 is within group of pictures (GOP)_1 and frame P_2 is within group of pictures (GOP)_2. Then, the terminal device decodes all the encoded frames within group of pictures (GOP)_1 and group of pictures (GOP)_2 respectively to obtain corresponding decoded data E1 and decoded data E2. After that, for the decoded data E1, the terminal device starts from the position of frame P_1 in the decoded data E1 and encodes the decoded images within group of pictures (GOP)_1 that are after frame P_1 to obtain encoded data D1. For the decoded data E2, the terminal device starts from the starting position of the decoded data E2 and encodes the decoded images within group of pictures (GOP)_2 that are before frame P_2 to obtain encoded data D2. The encoded frames within the encoded data D1 are the first sub-encoded frames, and the encoded frames within the encoded data D2 are the second sub-encoded frames. The set of the encoded data D1 and the encoded data D2 is the first encoded frame. After that, the first encoded frame and the second encoded frame (encoded data D3) are written into file F2 in sequence, and the captured video can be obtained.
[0072] Step S205: Obtain a second encoded frame located between the capture start point and the capture end point.
[0073] Step S206: Arrange the first encoded frame and the second encoded frame based on the video positions corresponding to the first encoded frame and the second encoded frame to obtain an encoded frame sequence.
[0074] Step S207: Based on the encoded frame sequence, recalculate the timestamps corresponding to the first encoded frame and the second encoded frame to obtain a reset timestamp sequence corresponding to the encoded frame sequence.
[0075] Exemplarily, further, based on the capture start point and the capture end point, compressed packet data is obtained from the video file corresponding to the target video, and after obtaining the second video frame, since the first video frame is re-encoded, its timestamp is inconsistent with that of the second video frame. The timestamp includes presentation timestamp (pts) and / or decoding timestamp (dts). Therefore, it is necessary to reorder the timestamps to generate a reset timestamp sequence, so that the generated captured video can be played normally.
[0076] Specifically, first, the first encoded frame and the second encoded frame are arranged based on the video positions corresponding to them to obtain a complete sequence, that is, the encoded frame sequence. Among them, the video positions corresponding to the first encoded frame and the second encoded frame refer to the positions of the encoded frames corresponding to the first encoded frame in the target video. For example, refer to Figure 7As shown in the figure, the first coded frame includes a first sub-coded frame and a second sub-coded frame. Among them, the first sub-coded frame is before the second coded frame, and the second sub-coded frame is after the second coded frame. Then, an example of the generated coded frame sequence is: [the first sub-coded frame, the second coded frame, the second sub-coded frame]. After that, based on the combined coded frame sequence, the timestamps corresponding to each coded frame are recalculated to obtain a timestamp sequence corresponding to the coded frame sequence, that is, the timestamp sequence is reset. The following introduces the generation method of the reset timestamp sequence in two cases: the playback timestamp and the decoding timestamp:
[0077] As Figure 8 shown, in a possible implementation manner, the timestamp includes a playback timestamp. The specific implementation manner of step S207 includes:
[0078] Step S2071: Obtain the current coded frame of the coded frame sequence, and obtain the frame number of the current coded frame in the coded frame sequence according to the group number of the current coded frame in the corresponding current picture group and the number of pre-coded frames of the current picture group;
[0079] Step S2072: Obtain the playback timestamp corresponding to the current coded frame according to the frame number and the frame duration.
[0080] Step S2073: If the current coded frame is not the last coded frame of the coded frame sequence, set the next coded frame as the current coded frame and return to step S2071; if the current coded frame is the last coded frame of the coded frame sequence, obtain the reset timestamp sequence.
[0081] Exemplarily, for each encoded frame in the encoded frame sequence, the above steps are sequentially executed to generate the reset timestamp for each encoded frame. Specifically, starting from the first encoded frame in the encoded frame sequence, exemplarily, when the current encoded frame is the first encoded frame P1 in the encoded frame sequence, obtain the group sequence number of the encoded frame P1 in the current picture group (i.e., the picture group where the encoded frame P1 is located), for example, it is 1, that is, the encoded frame P1 is a key frame (the group sequence number of the IDR frame is 0). Then, according to the frame sequence number and the frame duration, obtain the presentation timestamp corresponding to the current encoded frame. For example, multiply the frame sequence number of the current encoded frame by the frame duration as the presentation timestamp of the encoded frame P1. Among them, the frame duration is the duration of each frame, which can be a preset value, and this frame duration is stored in the reference information of the target video, and is not limited here. Then, determine whether the encoded frame P1 (the current encoded frame) is the last encoded frame in the encoded frame sequence. In the current round, there are other encoded frames after the encoded frame P1. Therefore, return to step S2071, update the current encoded frame to the encoded frame P2 after the encoded frame P1, and repeat the above steps until the presentation timestamp of the last encoded frame in the encoded frame sequence is obtained. Finally, the set of presentation timestamps corresponding to each encoded frame, that is, the reset presentation timestamp sequence (i.e., the reset timestamp sequence).
[0082] As Figure 9 shown, in another possible implementation manner, the timestamp includes the decoding timestamp, and the specific implementation manner of step S207 includes:
[0083] Step S2074: Obtain the initial decoding timestamp according to the maximum buffer capacity and the frame duration;
[0084] Step S2075: Starting from the initial decoding timestamp, sequentially obtain the decoding timestamps corresponding to each encoded frame in the encoded frame sequence by accumulating the frame duration.
[0085] Step S2076: Obtain the reset timestamp sequence according to the decoding timestamp corresponding to each encoded frame.
[0086] Exemplarily, first, the terminal device obtains a preset maximum buffer size and frame duration, and calculates an initial decoding timestamp by multiplying the maximum buffer size by the frame duration. Herein, the maximum buffer size represents the number of decoded image frames to be buffered. Since video needs to be decoded before playback during the video playback process, in order to ensure smooth playback and reduce stuttering caused by the playback speed being greater than the decoding speed, the video (encoded frames) is usually decoded in advance to implement decoding caching. The number of pre-decoded encoded frames is the maximum buffer size. In one possible implementation, in the video coding sequence, the maximum number of images whose decoding order is before any image but whose display order is after it is determined as the maximum buffer size. This maximum buffer size can be preset in the sequence parameter set (sps) field of the reference information. After that, starting from the initial decoding timestamp, by accumulating the frame duration, the decoding timestamp corresponding to each encoded frame in the encoded frame sequence is obtained in turn. For example, the initial decoding timestamp corresponding to the encoded frame P1 is v1; then the decoding timestamp corresponding to the encoded frame P2 after the encoded frame P1 is v2 = v1 + t, where t is the frame duration; and then, the decoding timestamp corresponding to the encoded frame P3 after the encoded frame P2 is v3 = v2 + t. And so on, thus obtaining the decoding timestamp corresponding to each encoded frame in the encoded frame sequence. Among them, since the decoding order of each encoded frame may be different from the playback order, the playback order of the decoded image frames generated by the encoded frame P1, the encoded frame P2, and the encoded frame P3 in the above example may not be sequential. After that, a reset decoding timestamp sequence (i.e., a reset timestamp sequence) is generated based on the decoding timestamp corresponding to each encoded frame.
[0087] Among them, the generation processes of the above reset playback timestamp sequence and reset decoding timestamp sequence can be executed alternatively or all. In the case of all execution, they can be executed simultaneously or successively. The specific implementation manner can be set according to needs, and no limitation is imposed here.
[0088] Step S208: Generate an intercepted video corresponding to the video interception instruction based on the first encoded frame, the second encoded frame, and the reset timestamp.
[0089] After that, based on the first encoded frame, the second encoded frame, and the reset timestamp (reset decoding timestamp sequence and / or reset playback timestamp sequence) generated in the above steps, video data encapsulation is performed, and then the video file of the intercepted video corresponding to the video interception instruction can be obtained.
[0090] Optionally, before executing the above steps of this embodiment, it further includes a step of detecting the target video to ensure that the generated intercepted video can be played normally. Specifically, after step S201, it further includes:
[0091] Step S200A: Obtain the encoding parameters of the target video, where the encoding parameters are used to characterize the group of pictures (GOP) types of the pictures that make up the target video.
[0092] Step S200B: If the GOP type characterized by the encoding parameters is a closed GOP, then execute Step S202; otherwise, perform full decoding on the encoded frames between the interception start point and the interception end point to obtain the intercepted video.
[0093] Exemplarily, before processing the target video based on the above method, determine the GOP type of the GOP of the target video according to the encoding parameters of the target video. Among them, the GOP types include open GOP (Open GOP) and closed GOP (Close GOP). Among them, the decoding of the encoded frames in the closed GOP only depends on other encoded frames within the GOP and does not need to depend on the encoded frames in other GOPs. Therefore, after determining the target GOP, decoding data can be generated based on the target GOP, and then the final intercepted video can be obtained based on the decoding data, thereby ensuring the integrity of the generated intercepted video. When the GOP type is an open GOP, the integrity of the generated intercepted video cannot be guaranteed. In the steps of this embodiment, by judging the GOP type, the integrity of the generated intercepted video is ensured, thereby avoiding the problem that the intercepted video cannot be played normally.
[0094] Step S200C: Obtain the first encoder configuration parameters corresponding to the target video, and initialize the video encoder with the encoding parameters of the target video to obtain the second encoder configuration parameters corresponding to the video encoder, where the first encoder configuration parameters include the sequence parameter set and / or the picture parameter set corresponding to the target video.
[0095] Step S200D: If the first encoder configuration parameters are consistent with the second encoder configuration parameters, then execute Step S202; otherwise, perform full decoding on the encoded frames between the interception start point and the interception end point to obtain the intercepted video.
[0096] Exemplarily, in this embodiment, since the first video frame is re-encoded while the second video frame is not, they are generated based on different encoding processes. Therefore, there may be a problem of inconsistent encoder configuration parameters, that is, the sequence parameter set and / or picture parameter set (PPS) of the first encoded frame and the second encoded frame are inconsistent. This further leads to compatibility problems in the generated intercepted video. Therefore, in this embodiment, by obtaining the first encoder configuration parameters (such as pss_1, sps_1) corresponding to the target video, and then initializing the video encoder with the encoding parameters (preset values, which can be obtained from the reference information of the target video) of the target video to obtain the second encoder configuration parameters (such as pss_2, sps_2) corresponding to the video encoder, and by comparing the first encoder configuration parameters and the second encoder configuration parameters, the consistency of the encoder configuration parameters of the generated first encoded frame and the second encoded frame is ensured, and it is ensured that the video segments in the intercepted video are generated based on the same set of encoder configuration parameters, thereby improving the compatibility during the playback of the intercepted video.
[0097] In this embodiment, the implementation manner of step S201 is the same as that of step S101 in the embodiment Figure 2 shown in the present disclosure, and will not be elaborated herein one by one.
[0098] Corresponding to the video processing method in the above embodiment, Figure 10 is a structural block diagram of a video processing apparatus provided by an embodiment of the present disclosure. For the sake of convenience of description, only parts related to the embodiment of the present disclosure are shown.
[0099] Referring to Figure 10 , the video processing apparatus 3 includes:
[0100] An interaction module 31, configured to obtain a video interception point for the target video in response to a video interception instruction;
[0101] A processing module 32, configured to obtain a corresponding target image group according to the video interception point, where the target image group includes at least one positioning frame of the target video;
[0102] An encoding module 33, configured to obtain a first encoded frame corresponding to the target image group, and directly read a second encoded frame corresponding to the video interception instruction from the target video, where the second encoded frame is located before or after the target image group;
[0103] A generation module 34, configured to generate an intercepted video corresponding to the video interception instruction based on the first encoded frame and the second encoded frame.
[0104] According to one or more embodiments of the present disclosure, the video capture point includes a capture start point and a capture end point. The capture start point corresponds to the first target image group, and the capture end point corresponds to the second target image group. When the encoding module 33 directly reads the second encoded frame corresponding to the video capture instruction from the target video, it is specifically configured to: sequentially read the compressed packet data frame by frame from the video file of the target video according to the cut-off position of the first target image group and the start position of the second target image group to obtain the second encoded frame; the generation module 34 is specifically configured to: sequentially write the first encoded frame and the second encoded frame into a preset captured video file to generate a captured video.
[0105] According to one or more embodiments of the present disclosure, the processing module 32 is specifically configured to, according to the video capture point, obtain the first positioning frame closest to the front of the video capture point and the second positioning frame closest to the back of the video capture point; and obtain the corresponding target image group according to the first positioning frame and the second positioning frame.
[0106] According to one or more embodiments of the present disclosure, when the encoding module 33 obtains the first encoded frame corresponding to the target image group, it is specifically configured to: if the video capture point is located at the position of the first frame of the target image group, directly read the compressed packet data corresponding to the target image group from the target video to obtain the first encoded frame; if the video capture point is located at a non-first-frame position of the target image group, decode the target image group to obtain decoded data, and then perform video encoding starting from the video capture point position of the decoded data until the end of the decoded data to obtain the first encoded frame; or perform video encoding starting from the start position of the decoded data until the video capture point position to obtain the first encoded frame.
[0107] According to one or more embodiments of the present disclosure, the video capture point includes a capture start point and a capture end point; the encoding module 33 is further configured to: obtain the first target image group corresponding to the capture start point and the second target image group corresponding to the capture end point; respectively decode the first target image group and the second target image group to obtain the first decoded data corresponding to the first target image group and the second decoded data corresponding to the second target image group; the first encoded frame includes a first sub-encoded frame and a second sub-encoded frame. When the encoding module 33 obtains the first encoded frame corresponding to the target image group, it is specifically configured to: respectively perform video encoding on the first decoded data and the second decoded data to obtain the corresponding first sub-encoded frame and second sub-encoded frame.
[0108] According to one or more embodiments of the present disclosure, after directly reading the second encoded frame corresponding to the video capture instruction from the target video, the encoding module 33 is further configured to: arrange the first encoded frame and the second encoded frame based on the video positions corresponding to the first encoded frame and the second encoded frame to obtain an encoded frame sequence; based on the encoded frame sequence, recalculate the timestamps corresponding to the first encoded frame and the second encoded frame to obtain a reset timestamp sequence; the generation module 34 is specifically configured to: generate a captured video corresponding to the video capture instruction based on the first encoded frame, the second encoded frame, and the reset timestamp sequence.
[0109] According to one or more embodiments of the present disclosure, the timestamp includes a presentation timestamp. When the generation module 34 recalculates the timestamps corresponding to the first encoded frame and the second encoded frame according to the encoding parameters of the target video to obtain the reset timestamp, it is specifically configured to: for each encoded frame in the encoded frame sequence, sequentially perform the following steps: obtain the frame number of the encoded frame in the encoded frame sequence according to the group number of the encoded frame in the corresponding current picture group and the number of preceding encoded frames in the current picture group; obtain the presentation timestamp corresponding to the encoded frame according to the frame number and the frame duration.
[0110] According to one or more embodiments of the present disclosure, the timestamp includes a decoding timestamp. When the generation module 34 recalculates the timestamps corresponding to the first encoded frame and the second encoded frame according to the encoding parameters of the target video to obtain the reset timestamp, it is specifically configured to: obtain an initial decoding timestamp according to the maximum buffer size and the frame duration; starting from the initial decoding timestamp, sequentially obtain the decoding timestamps corresponding to each encoded frame in the encoded frame sequence by accumulating the frame duration.
[0111] According to one or more embodiments of the present disclosure, the encoding module 33 is further configured to: obtain the encoding parameters of the target video, where the encoding parameters are used to characterize the picture group type of the picture groups constituting the target video; when the interaction module 31 responds to the video capture instruction and obtains the video capture point for the target video, it is specifically configured to: if the picture group type characterized by the encoding parameters is a closed picture group, then respond to the video capture instruction and obtain the video capture point for the target video.
[0112] According to one or more embodiments of the present disclosure, the processing module 32 is further configured to: obtain the first encoder configuration parameters corresponding to the target video, where the first encoder configuration parameters include a sequence parameter set and / or a picture parameter set corresponding to the target video; initialize a video encoder with the encoding parameters of the target video to obtain the second encoder configuration parameters corresponding to the video encoder; when the processing module 32 obtains the corresponding target picture group according to the video capture point, it is specifically configured to: if the first encoder configuration parameters are consistent with the second encoder configuration parameters, then obtain the corresponding target picture group according to the video capture point.
[0113] Among them, the interaction module 31, the processing module 32, the encoding module 33, and the generation module 34 are connected in sequence. The video processing device 3 provided in this embodiment can execute the technical solutions of the above method embodiments, and the implementation principles and technical effects are similar, which will not be elaborated here.
[0114] Figure 11 It is a schematic structural diagram of an electronic device provided by an embodiment of the present disclosure, as Figure 11 shown. The electronic device 4 includes:
[0115] a processor 41 and a memory 42 communicatively connected to the processor 41;
[0116] The memory 42 stores computer-executable instructions;
[0117] The processor 41 executes the computer-executable instructions stored in the memory 42 to implement the video processing method in the embodiment as Figures 2 - 9 shown.
[0118] Optionally, the processor 41 and the memory 42 are connected through a bus 43.
[0119] For relevant descriptions, reference can be made to Figures 2 - 9 the relevant descriptions and effects corresponding to the steps in the corresponding embodiments, and details will not be elaborated here.
[0120] An embodiment of the present disclosure provides a computer-readable storage medium, in which computer-executable instructions are stored. When the computer-executable instructions are executed by a processor, they are used to implement the video processing method provided in any one of the embodiments corresponding to the present disclosure Figures 2 - 9 as described above.
[0121] An embodiment of the present disclosure provides a computer program product, including a computer program. When the computer program is executed by a processor, it implements the video processing method provided in any one of the embodiments corresponding to the present disclosure Figures 2 - 9 as described above.
[0122] To implement the above embodiments, an embodiment of the present disclosure also provides an electronic device.
[0123] Refer to Figure 12, which shows a schematic structural diagram of an electronic device 900 suitable for implementing the embodiments of the present disclosure. The electronic device 900 may be a terminal device or a server. Among them, the terminal device may include, but is not limited to, mobile terminals such as mobile phones, laptop computers, digital broadcast receivers, personal digital assistants (PDAs), tablet computers (PADs), portable media players (PMPs), in-vehicle terminals (such as in-vehicle navigation terminals), etc., and fixed terminals such as digital TVs, desktop computers, etc. Figure 12 The electronic device shown is merely an example and should not impose any limitations on the functions and usage scope of the embodiments of the present disclosure.
[0124] As Figure 12 shown, the electronic device 900 may include a processing device (such as a central processing unit, a graphics processing unit, etc.) 901, which may perform various appropriate actions and processes according to the programs stored in the read-only memory (ROM) 902 or the programs loaded from the storage device 908 into the random access memory (RAM) 903. In the RAM 903, various programs and data required for the operation of the electronic device 900 are also stored. The processing device 901, the ROM 902, and the RAM 903 are connected to each other through a bus 904. The input / output (I / O) interface 905 is also connected to the bus 904.
[0125] Generally, the following devices may be connected to the I / O interface 905: an input device 906 including, for example, a touch screen, a touchpad, a keyboard, a mouse, a camera, a microphone, an accelerometer, a gyroscope, etc.; an output device 907 including, for example, a liquid crystal display (LCD), a speaker, a vibrator, etc.; a storage device 908 including, for example, a magnetic tape, a hard disk, etc.; and a communication device 909. The communication device 909 may allow the electronic device 900 to communicate with other devices wirelessly or wiredly to exchange data. Although Figure 12 the electronic device 900 with various devices is shown, it should be understood that it is not required to implement or have all the shown devices. More or fewer devices may be implemented or had alternatively.
[0126] In particular, according to an embodiment of the present disclosure, the processes described above with reference to the flowcharts can be implemented as computer software programs. For example, an embodiment of the present disclosure includes a computer program product that includes a computer program carried on a computer-readable medium, and the computer program includes program code for performing the methods shown in the flowcharts. In such an embodiment, the computer program can be downloaded and installed from a network via a communication device 909, or installed from a storage device 908, or installed from a ROM 902. When the computer program is executed by a processing device 901, the above-described functions defined in the methods of the embodiments of the present disclosure are performed.
[0127] It should be noted that the above-mentioned computer-readable medium in the present disclosure can be a computer-readable signal medium or a computer-readable storage medium or any combination of the two. A computer-readable storage medium can be, for example, but not limited to, an electrical, magnetic, optical, electromagnetic, infrared, or semiconductor system, apparatus, or device, or any combination of the above. More specific examples of the computer-readable storage medium can include, but are not limited to: an electrical connection having one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disk read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the above. In the present disclosure, a computer-readable storage medium can be any tangible medium that contains or stores a program that can be used by or in conjunction with an instruction execution system, apparatus, or device. In the present disclosure, a computer-readable signal medium can include a data signal propagated in a baseband or as part of a carrier wave, which carries computer-readable program code. Such a propagated data signal can take various forms, including but not limited to electromagnetic signals, optical signals, or any suitable combination of the above. A computer-readable signal medium can also be any computer-readable medium other than a computer-readable storage medium, and the computer-readable signal medium can send, propagate, or transmit a program for use by or in conjunction with an instruction execution system, apparatus, or device. The program code contained on the computer-readable medium can be transmitted by any appropriate medium, including but not limited to: wires, optical cables, RF (radio frequency), etc., or any suitable combination of the above.
[0128] The above-mentioned computer-readable medium can be included in the above-mentioned electronic device; or it can exist separately without being assembled into the electronic device.
[0129] The above-mentioned computer-readable medium carries one or more programs, and when the above-mentioned one or more programs are executed by the electronic device, the electronic device is caused to execute the methods shown in the above embodiments.
[0130] Computer program code for performing the operations of this disclosure may be written in one or more programming languages or combinations thereof. The programming languages include object-oriented programming languages such as Java, Smalltalk, C++, and also conventional procedural programming languages such as the "C" language or similar programming languages. The program code may execute entirely on the user's computer, partly on the user's computer, as a stand-alone software package, partly on the user's computer and partly on a remote computer, or entirely on the remote computer or server. In the case of a remote computer, the remote computer may be connected to the user's computer through any type of network, including a local area network (LAN) or a wide area network (WAN), or it may be connected to an external computer (e.g., through the Internet using an Internet service provider).
[0131] The flowcharts and block diagrams in the accompanying drawings illustrate the possible architectures, functions, and operations of systems, methods, and computer program products according to various embodiments of this disclosure. In this regard, each block in the flowchart or block diagram may represent a module, a program segment, or a portion of code that contains one or more executable instructions for implementing the specified logical function. It should also be noted that, in some alternative implementations, the functions noted in the blocks may occur in a different order than noted in the accompanying drawings. For example, two consecutive blocks shown may actually be executed substantially in parallel, or they may sometimes be executed in the reverse order, depending on the functions involved. It should also be noted that each block in the block diagram and / or flowchart, and combinations of blocks in the block diagram and / or flowchart, may be implemented by a dedicated hardware-based system that performs the specified functions or operations, or may be implemented by a combination of dedicated hardware and computer instructions.
[0132] The units described in the embodiments of this disclosure may be implemented in software or in hardware. Among them, the name of the unit does not constitute a limitation on the unit itself in some cases. For example, the first acquisition unit may also be described as "the unit for acquiring at least two Internet protocol addresses".
[0133] The functions described above herein may be performed at least in part by one or more hardware logic components. For example, by way of non-limitation, exemplary types of hardware logic components that may be used include: field programmable gate arrays (FPGA), application specific integrated circuits (ASIC), application specific standard products (ASSP), system on a chip (SOC), complex programmable logic devices (CPLD), and so on.
[0134] In the context of the present disclosure, a machine-readable medium may be a tangible medium that can contain or store a program for use by or in connection with an instruction execution system, apparatus, or device. The machine-readable medium may be a machine-readable signal medium or a machine-readable storage medium. The machine-readable medium may include, but is not limited to, electronic, magnetic, optical, electromagnetic, infrared, or semiconductor systems, apparatus, or devices, or any suitable combination of the foregoing. More specific examples of the machine-readable storage medium would include an electrical connection based on one or more wires, a portable computer disk, a hard disk, a random access memory (RAM), a read-only memory (ROM), an erasable programmable read-only memory (EPROM or flash memory), an optical fiber, a portable compact disc read-only memory (CD-ROM), an optical storage device, a magnetic storage device, or any suitable combination of the foregoing.
[0135] In a first aspect, according to one or more embodiments of the present disclosure, there is provided a video processing method, including:
[0136] In response to a video capture instruction, obtaining a video capture point for a target video; according to the video capture point, obtaining a corresponding target image group, where the target image group includes at least one positioning frame of the target video; obtaining a first coded frame corresponding to the target image group, and directly reading a second coded frame corresponding to the video capture instruction from the target video, where the second coded frame is located before or after the target image group; and generating a captured video corresponding to the video capture instruction based on the first coded frame and the second coded frame.
[0137] According to one or more embodiments of the present disclosure, the video capture point includes a capture start point and a capture end point, the capture start point corresponds to a first target image group, and the capture end point corresponds to a second target image group; the directly reading a second coded frame corresponding to the video capture instruction from the target video includes: sequentially reading compressed packet data frame by frame from a video file of the target video according to a cut-off position of the first target image group and a start position of the second target image group to obtain the second coded frame; and generating a captured video corresponding to the video capture instruction based on the first coded frame and the second coded frame includes: sequentially writing the first coded frame and the second coded frame into a preset captured video file to generate a captured video.
[0138] According to one or more embodiments of the present disclosure, the obtaining a corresponding target image group according to the video capture point includes: obtaining a first positioning frame closest to the video capture point before the video capture point and a second positioning frame closest to the video capture point after the video capture point according to the video capture point; and obtaining a corresponding target image group according to the first positioning frame and the second positioning frame.
[0139] According to one or more embodiments of the present disclosure, obtaining the first encoded frame corresponding to the target image group includes: if the video capture point is located at the position of the first frame of the target image group, directly reading the compressed package data corresponding to the target image group from the target video to obtain the first encoded frame; if the video capture point is located at a non-first frame position of the target image group, decoding the target image group to obtain decoded data, and then performing video encoding starting from the video capture point position of the decoded data until the end of the decoded data to obtain the first encoded frame; or performing video encoding starting from the start position of the decoded data until the video capture point position to obtain the first encoded frame.
[0140] According to one or more embodiments of the present disclosure, the video capture point includes a capture start point and a capture end point; the method further includes: obtaining a first target image group corresponding to the capture start point and a second target image group corresponding to the capture end point; respectively decoding the first target image group and the second target image group to obtain first decoded data corresponding to the first target image group and second decoded data corresponding to the second target image group; the first encoded frame includes a first sub-encoded frame and a second sub-encoded frame, and obtaining the first encoded frame corresponding to the target image group includes: respectively performing video encoding on the first decoded data and the second decoded data to obtain corresponding first sub-encoded frames and second sub-encoded frames.
[0141] According to one or more embodiments of the present disclosure, after directly reading the second encoded frame corresponding to the video capture instruction from the target video, it further includes: arranging the first encoded frame and the second encoded frame based on the video positions corresponding to the first encoded frame and the second encoded frame to obtain an encoded frame sequence; re-calculating the timestamps corresponding to the first encoded frame and the second encoded frame based on the encoded frame sequence to obtain a reset timestamp sequence; generating the captured video corresponding to the video capture instruction based on the first encoded frame and the second encoded frame includes: generating the captured video corresponding to the video capture instruction based on the first encoded frame, the second encoded frame, and the reset timestamp sequence.
[0142] According to one or more embodiments of the present disclosure, the timestamp includes a playback timestamp, and re-calculating the timestamps corresponding to the first encoded frame and the second encoded frame according to the encoding parameters of the target video to obtain a reset timestamp includes: sequentially performing the following steps for each encoded frame in the encoded frame sequence: obtaining the frame number of the encoded frame in the encoded frame sequence according to the group number of the encoded frame in the corresponding current image group and the number of pre-encoded frames in the current image group; obtaining the playback timestamp corresponding to the encoded frame according to the frame number and the frame duration.
[0143] According to one or more embodiments of the present disclosure, the timestamp includes a decoding timestamp. According to the encoding parameters of the target video, the timestamps corresponding to the first encoded frame and the second encoded frame are recalculated to obtain reset timestamps, including: obtaining an initial decoding timestamp according to the maximum buffer capacity and the frame duration; starting from the initial decoding timestamp, by accumulating the frame duration, obtaining the decoding timestamp corresponding to each encoded frame in the encoded frame sequence in turn.
[0144] According to one or more embodiments of the present disclosure, the method further includes: obtaining the encoding parameters of the target video, where the encoding parameters are used to characterize the group of pictures type of the group of pictures constituting the target video; the obtaining the corresponding target group of pictures according to the video cut-off point includes: if the group of pictures type characterized by the encoding parameters is a closed group of pictures, obtaining the corresponding target group of pictures according to the video cut-off point.
[0145] According to one or more embodiments of the present disclosure, the method further includes: obtaining the first encoder configuration parameters corresponding to the target video, where the first encoder configuration parameters include the sequence parameter set and / or the picture parameter set corresponding to the target video; initializing a video encoder with the encoding parameters of the target video to obtain the second encoder configuration parameters corresponding to the video encoder; the obtaining the corresponding target group of pictures according to the video cut-off point includes: if the first encoder configuration parameters are consistent with the second encoder configuration parameters, obtaining the corresponding target group of pictures according to the video cut-off point.
[0146] In a second aspect, according to one or more embodiments of the present disclosure, there is provided a video processing apparatus, including:
[0147] An interaction module, configured to obtain a video cut-off point for a target video in response to a video cut-off instruction;
[0148] A processing module, configured to obtain a corresponding target group of pictures according to the video cut-off point, where at least one positioning frame of the target video is included in the target group of pictures;
[0149] An encoding module, configured to obtain a first encoded frame corresponding to the target group of pictures, and directly read a second encoded frame corresponding to the video cut-off instruction from the target video, where the second encoded frame is before or after the target group of pictures;
[0150] A generation module, configured to generate a cut video corresponding to the video cut-off instruction based on the first encoded frame and the second encoded frame.
[0151] According to one or more embodiments of the present disclosure, the video capture point includes a capture start point and a capture end point. The capture start point corresponds to a first target image group, and the capture end point corresponds to a second target image group. When the encoding module directly reads the second encoded frame corresponding to the video capture instruction from the target video, it specifically is configured to: sequentially read compressed packet data frame by frame from the video file of the target video according to the cut-off position of the first target image group and the start position of the second target image group to obtain the second encoded frame; The generation module is specifically configured to: sequentially write the first encoded frame and the second encoded frame into a preset captured video file to generate a captured video.
[0152] According to one or more embodiments of the present disclosure, the processing module is specifically configured to, according to the video capture point, obtain the first positioning frame closest to the front of the video capture point and the second positioning frame closest to the back of the video capture point; according to the first positioning frame and the second positioning frame, obtain the corresponding target image group.
[0153] According to one or more embodiments of the present disclosure, when the encoding module obtains the first encoded frame corresponding to the target image group, it specifically is configured to: if the video capture point is located at the first frame position of the target image group, directly read the compressed packet data corresponding to the target image group from the target video to obtain the first encoded frame; if the video capture point is located at a non-first frame position of the target image group, decode the target image group to obtain decoded data, and then perform video encoding starting from the video capture point position of the decoded data until the end of the decoded data to obtain the first encoded frame; or, perform video encoding starting from the start position of the decoded data until the video capture point position to obtain the first encoded frame.
[0154] According to one or more embodiments of the present disclosure, the video capture point includes a capture start point and a capture end point; the encoding module is further configured to: obtain a first target image group corresponding to the capture start point and a second target image group corresponding to the capture end point; respectively decode the first target image group and the second target image group to obtain first decoded data corresponding to the first target image group and second decoded data corresponding to the second target image group; the first encoded frame includes a first sub-encoded frame and a second sub-encoded frame. When the encoding module obtains the first encoded frame corresponding to the target image group, it specifically is configured to: respectively perform video encoding on the first decoded data and the second decoded data to obtain the corresponding first sub-encoded frame and second sub-encoded frame.
[0155] According to one or more embodiments of the present disclosure, after directly reading the second encoded frame corresponding to the video capture instruction from the target video, the encoding module is further configured to: arrange the first encoded frame and the second encoded frame based on the video positions corresponding to the first encoded frame and the second encoded frame to obtain an encoded frame sequence; re-calculate the timestamps corresponding to the first encoded frame and the second encoded frame based on the encoded frame sequence to obtain a reset timestamp sequence; the generating module is specifically configured to: generate a captured video corresponding to the video capture instruction based on the first encoded frame, the second encoded frame, and the reset timestamp sequence.
[0156] According to one or more embodiments of the present disclosure, the timestamp includes a presentation timestamp. When the generating module re-calculates the timestamps corresponding to the first encoded frame and the second encoded frame according to the encoding parameters of the target video to obtain the reset timestamp, it is specifically configured to: for each encoded frame in the encoded frame sequence, sequentially perform the following steps: obtain the frame number of the encoded frame in the encoded frame sequence according to the group number of the encoded frame in the corresponding current picture group and the number of preceding encoded frames in the current picture group; obtain the presentation timestamp corresponding to the encoded frame according to the frame number and the frame duration.
[0157] According to one or more embodiments of the present disclosure, the timestamp includes a decoding timestamp. When the generating module re-calculates the timestamps corresponding to the first encoded frame and the second encoded frame according to the encoding parameters of the target video to obtain the reset timestamp, it is specifically configured to: obtain an initial decoding timestamp according to the maximum buffer size and the frame duration; starting from the initial decoding timestamp, sequentially obtain the decoding timestamps corresponding to each encoded frame in the encoded frame sequence by accumulating the frame duration.
[0158] According to one or more embodiments of the present disclosure, the encoding module is further configured to: obtain the encoding parameters of the target video, where the encoding parameters are used to characterize the picture group type of the picture groups constituting the target video; when the interaction module responds to a video capture instruction and obtains a video capture point for the target video, it is specifically configured to: if the picture group type characterized by the encoding parameters is a closed picture group, then respond to the video capture instruction and obtain a video capture point for the target video.
[0159] According to one or more embodiments of the present disclosure, the processing module is further configured to: obtain the first encoder configuration parameters corresponding to the target video, where the first encoder configuration parameters include a sequence parameter set and / or a picture parameter set corresponding to the target video; initialize a video encoder with the encoding parameters of the target video to obtain the second encoder configuration parameters corresponding to the video encoder; when the processing module obtains a corresponding target picture group according to the video capture point, it is specifically configured to: if the first encoder configuration parameters are consistent with the second encoder configuration parameters, then obtain the corresponding target picture group according to the video capture point.
[0160] In a third aspect, according to one or more embodiments of the present disclosure, there is provided an electronic device, including: at least one processor and a memory;
[0161] The memory stores computer-executable instructions;
[0162] The at least one processor executes the computer-executable instructions stored in the memory, so that the at least one processor executes the video processing method as described in the first aspect above and various possible designs of the first aspect.
[0163] In a fourth aspect, according to one or more embodiments of the present disclosure, there is provided a computer-readable storage medium storing computer-executable instructions, and when a processor executes the computer-executable instructions, the video processing method as described in the first aspect above and various possible designs of the first aspect is implemented.
[0164] In a fifth aspect, according to one or more embodiments of the present disclosure, there is provided a computer program product including a computer program, and when the computer program is executed by a processor, the video processing method as described in the first aspect above and various possible designs of the first aspect is implemented.
[0165] The above description is only a preferred embodiment of the present disclosure and an explanation of the applied technical principles. Those skilled in the art should understand that the scope of the disclosure involved in the present disclosure is not limited to the technical solutions formed by the specific combination of the above technical features, but should also cover other technical solutions formed by any combination of the above technical features or their equivalent features without departing from the above disclosure concept. For example, a technical solution formed by mutually replacing the above features with the (but not limited to) technical features having similar functions disclosed in the present disclosure.
[0166] In addition, although the operations are depicted in a specific order, this should not be construed as requiring these operations to be performed in the specific order shown or in a sequential order. In certain environments, multitasking and parallel processing may be advantageous. Similarly, although several specific implementation details are included in the above discussion, these should not be construed as limiting the scope of the present disclosure. Certain features described in the context of a single embodiment may also be implemented in combination in a single embodiment. Conversely, the various features described in the context of a single embodiment may also be implemented separately or in any suitable sub-combination in multiple embodiments.
[0167] Although the subject matter has been described in language specific to structural features and / or method logical acts, it should be understood that the subject matter defined in the appended claims is not necessarily limited to the specific features or acts described above. On the contrary, the specific features and acts described above are merely example forms for implementing the claims.
Claims
1. A video processing method, characterized in that, Including: In response to a video capture instruction, obtaining a video capture point for a target video; According to the video capture point, obtaining a corresponding target image group, where the target image group includes at least one positioning frame of the target video; Obtaining a first encoded frame corresponding to the target image group, and directly reading a second encoded frame corresponding to the video capture instruction from the target video, where the second encoded frame is before or after the target image group; Based on the first encoded frame and the second encoded frame, generating a captured video corresponding to the video capture instruction.
2. The method according to claim 1, wherein The video capture point includes a capture start point and a capture end point, the capture start point corresponds to a first target image group, and the capture end point corresponds to a second target image group; The directly reading the second encoded frame corresponding to the video capture instruction from the target video includes: According to the end position of the first target image group and the start position of the second target image group, sequentially reading compressed packet data frame by frame from the video file of the target video to obtain the second encoded frame; Based on the first encoded frame and the second encoded frame, generating a captured video corresponding to the video capture instruction includes: Writing the first encoded frame and the second encoded frame into a preset captured video file in sequence to generate a captured video.
3. The method according to claim 1, characterized in that, The obtaining a corresponding target image group according to the video capture point includes: According to the video capture point, obtaining a first positioning frame closest to the video capture point before the video capture point and a second positioning frame closest to the video capture point after the video capture point; According to the first positioning frame and the second positioning frame, obtaining a corresponding target image group.
4. The method according to claim 1, wherein The obtaining a first encoded frame corresponding to the target image group includes: If the video capture point is at the position of the first frame of the target image group, directly reading the compressed packet data corresponding to the target image group from the target video to obtain the first encoded frame; If the video capture point is at a non-first frame position of the target image group, decoding the target image group to obtain decoded data, and then, performing video encoding starting from the video capture point position of the decoded data until the end of the decoded data to obtain a first encoded frame; or, performing video encoding starting from the start position of the decoded data until the video capture point position to obtain a first encoded frame.
5. The method according to claim 1, wherein The video capture point includes a capture start point and a capture end point; the method further includes: Obtaining a first target image group corresponding to the capture start point and a second target image group corresponding to the capture end point; Decoding the first target image group and the second target image group respectively to obtain first decoded data corresponding to the first target image group and second decoded data corresponding to the second target image group; The first encoded frame includes a first sub-encoded frame and a second sub-encoded frame, and the obtaining a first encoded frame corresponding to the target image group includes: Performing video encoding on the first decoded data and the second decoded data respectively to obtain corresponding first sub-encoded frames and second sub-encoded frames.
6. The method according to claim 1, wherein After directly reading the second encoded frame corresponding to the video capture instruction from the target video, it further includes: Arrange the first encoded frame and the second encoded frame based on the video positions corresponding to the first encoded frame and the second encoded frame to obtain an encoded frame sequence; Based on the encoded frame sequence, recalculate the timestamps corresponding to the first encoded frame and the second encoded frame to obtain a reset timestamp sequence; The generating the intercepted video corresponding to the video interception instruction based on the first encoded frame and the second encoded frame includes: Generate the intercepted video corresponding to the video interception instruction based on the first encoded frame, the second encoded frame, and the reset timestamp sequence.
7. The method according to claim 6, characterized in that, The timestamp includes a playback timestamp. According to the encoding parameters of the target video, recalculating the timestamps corresponding to the first encoded frame and the second encoded frame to obtain a reset timestamp includes: For each encoded frame in the encoded frame sequence, sequentially perform the following steps: Obtain the frame number of the encoded frame in the encoded frame sequence according to the group number of the encoded frame in the corresponding current picture group and the number of preceding encoded frames in the current picture group; Obtain the playback timestamp corresponding to the encoded frame according to the frame number and the frame duration.
8. The method according to claim 6, characterized in that, The timestamp includes a decoding timestamp. According to the encoding parameters of the target video, recalculating the timestamps corresponding to the first encoded frame and the second encoded frame to obtain a reset timestamp includes: Obtain an initial decoding timestamp according to the maximum buffer size and the frame duration; Starting from the initial decoding timestamp, sequentially obtain the decoding timestamps corresponding to each encoded frame in the encoded frame sequence by accumulating the frame duration.
9. The method according to claim 1, wherein The method further includes: Obtain the encoding parameters of the target video, where the encoding parameters are used to characterize the picture group type of the picture groups constituting the target video; The obtaining the corresponding target picture group according to the video interception point includes: If the picture group type characterized by the encoding parameters is a closed picture group, obtain the corresponding target picture group according to the video interception point.
10. The method according to claim 1, wherein The method further includes: Obtain the first encoder configuration parameters corresponding to the target video, where the first encoder configuration parameters include the sequence parameter set and / or the picture parameter set corresponding to the target video; Initialize a video encoder with the encoding parameters of the target video to obtain the second encoder configuration parameters corresponding to the video encoder; The obtaining the corresponding target picture group according to the video interception point includes: If the first encoder configuration parameters are consistent with the second encoder configuration parameters, obtain the corresponding target picture group according to the video interception point.
11. A video processing device, characterized in that, Includes: An interaction module, configured to obtain a video interception point for a target video in response to a video interception instruction; A processing module, configured to obtain a corresponding target picture group according to the video interception point, where the target picture group includes at least one positioning frame of the target video; An encoding module, configured to obtain a first encoded frame corresponding to the target picture group and directly read a second encoded frame corresponding to the video interception instruction from the target video, where the second encoded frame is before or after the target picture group; A generation module, configured to generate an intercepted video corresponding to the video interception instruction based on the first encoded frame and the second encoded frame.
12. An electronic device, characterized in that, Comprising: A processor and a memory; The memory stores computer-executable instructions; The processor executes the computer-executable instructions stored in the memory, so that the processor executes the video processing method according to any one of claims 1 to 10.
13. A computer-readable storage medium, characterized in that, Computer-executable instructions are stored in the computer-readable storage medium, and when the processor executes the computer-executable instructions, the video processing method according to any one of claims 1 to 10 is implemented.
14. A computer program product, comprising a computer program, characterized in that, When the computer program is executed by the processor, the video processing method according to any one of claims 1 to 10 is implemented.
