Video processing method and apparatus, and device and medium
A video processing method includes: obtaining a plurality of image groups on the basis of a video frame sequence of an initial video; performing motion blur processing on the basis of each frame of image in a target image group, and fusing images which are obtained by performing motion blur processing on each frame of image, so as to obtain a motion-blurred image corresponding to the target image group; on the basis of a specified frame of image in the target image group, determining a main body object area and a background area, which correspond to the target image group; fusing the motion-blurred image with the specified frame of image according to the main body object area and the background area, so as to obtain a target fused image; and generating a target video on the basis of target fused images respectively corresponding to the plurality of image groups.
1 . A video processing method, comprising:
obtaining a plurality of image groups based on a video frame sequence of an initial video;
performing, for each target image group among the plurality of image groups, following operations:
performing motion blur processing based on frame images in the target image group, so as to obtain a motion-blurred image corresponding to the target image group;
determining, by using an object instance segmentation algorithm, a main object area and a background area of a certain frame image in the target image group; and
merging the motion-blurred image and the certain frame image according to the main object area and the background area so as to obtain a target merged image corresponding to the target image group, wherein an image part of the target merged image in the main object area corresponds to an image part of the certain frame image in the main object area, and an image part of the target merged image in the background area corresponds to an image part of the motion-blurred image in the background area; and
generating a target video based on the target merged images respectively corresponding to the plurality of image groups, wherein a sequence in which the target merged images respectively corresponding to the plurality of image groups are played in the target video is the same as a sequence in which the plurality of image groups are played in the initial video,
wherein performing the motion blur processing based on the frame images in the target image group, so as to obtain the motion-blurred image corresponding to the target image group comprises:
interpolating a certain number of intermediate frame images between adjacent frame images in the target image group by using an optical flow interpolation algorithm, and
performing average merging on all image frames in the target image group after the frame interpolation, so as to obtain the motion-blurred image corresponding to the target image group.
2 . The video processing method according to claim 1 , wherein interpolating the certain number of intermediate frame images between the adjacent frame images in the target image group by using the optical flow interpolation algorithm comprises:
obtaining a bidirectional motion vector of a pixel block between the adjacent frame images in the target image group; and
interpolating the certain number of intermediate frame images between the adjacent frame images according to the bidirectional motion vector of the pixel block and a block motion compensation algorithm.
3 . The video processing method according to claim 2 , wherein obtaining the bidirectional motion vector of the pixel block between the adjacent frame images in the target image group comprises:
obtaining the bidirectional motion vector of the pixel block between the adjacent frame images in the target image group based on an improved dense inverse search (DIS) optical flow algorithm,
wherein at least one of the following is met: a resolution of a bottom layer image of an image pyramid used in the improved DIS optical flow algorithm is less than a resolution of a bottom layer image of an image pyramid used in an original DIS optical flow algorithm, or, a number of iterations used in the improved DIS optical flow algorithm is less than a number of iterations used in the original DIS optical flow algorithm.
4 . The video processing method according to claim 1 , wherein determining the main object area and the background area of the certain frame image in the target image group comprises:
taking an image located in the middle of the target image group as the certain frame image;
processing the certain frame image by using the object instance segmentation algorithm; and
obtaining the main object area and the background area of the certain frame image based on a processing result.
5 . The video processing method according to claim 1 , wherein merging the motion-blurred image and the certain frame image according to the main object area and the background area comprises:
obtaining a main object mask image according to the main object area and the background area;
obtaining a weight coefficient corresponding to the main object mask image;
adjusting pixel values of the main object mask image based on the weight coefficient so as to obtain the adjusted main object mask image; and
merging the motion-blurred image and the certain frame image based on the adjusted main object mask image.
6 . The video processing method according to claim 5 , wherein obtaining the weight coefficient corresponding to the main object mask image comprises:
obtaining a global motion amplitude corresponding to the frame images in the target image group based on an optical flow method; and
determining the weight coefficient corresponding to the main object mask image according to the global motion amplitude.
7 . The video processing method of claim 6 , wherein the global motion magnitude is negatively correlated with the weight coefficient.
8 . The video processing method according to claim 5 , wherein merging the motion-blurred image and the certain frame image based on the adjusted main object mask image comprises:
merging the motion-blurred image and the certain frame image by using the following formula:
Merge_N
′
=
β
*
mask_main
*
Pn
+
(
1
-
β
*
mask_main
)
*
Merge_N
,
wherein β is the weight coefficient, mask_main is the main object mask image, β*mask_main is the adjusted main object mask image, Pn is the certain frame image, Merge_N is the motion-blurred image, and Merge_N′ is the target merged image.
9 . The video processing method according to claim 1 , wherein obtaining the plurality of image groups based on the video frame sequence of the initial video comprises:
segmenting the video frame sequence of the initial video according to a certain interval so as to obtain the plurality of image groups, wherein two adjacent image groups have a preset number of overlapping frame images therebetween.
10 . An electronic device, comprising:
a processor; and
a memory configured to store instructions executable by the processor,
wherein the processor is configured to read the executable instructions from the memory and execute the instructions to implement following video processing operations:
obtaining a plurality of image groups based on a video frame sequence of an initial video;
performing, for each target image group among the plurality of image groups, following operations:
performing motion blur processing based on frame images in the target image group, so as to obtain a motion-blurred image corresponding to the target image group;
determining, by using an object instance segmentation algorithm, a main object area and a background area of a certain frame image in the target image group; and
merging the motion-blurred image and the certain frame image according to the main object area and the background area so as to obtain a target merged image corresponding to the target image group, wherein an image part of the target merged image in the main object area corresponds to an image part of the certain frame image in the main object area, and an image part of the target merged image in the background area corresponds to an image part of the motion-blurred image in the background area; and
generating a target video based on the target merged images respectively corresponding to the plurality of image groups, wherein a sequence in which the target merged images respectively corresponding to the plurality of image groups are played in the target video is the same as a sequence in which the plurality of image groups are played in the initial video,
wherein performing the motion blur processing based on the frame images in the target image group, so as to obtain the motion-blurred image corresponding to the target image group comprises:
interpolating a certain number of intermediate frame images between adjacent frame images in the target image group by using an optical flow interpolation algorithm, and
performing average merging on all image frames in the target image group after the frame interpolation, so as to obtain the motion-blurred image corresponding to the target image group.
11 . The electronic device according to claim 10 , wherein interpolating the certain number of intermediate frame images between the adjacent frame images in the target image group by using the optical flow interpolation algorithm comprises:
obtaining a bidirectional motion vector of a pixel block between the adjacent frame images in the target image group; and
interpolating the certain number of intermediate frame images between the adjacent frame images according to the bidirectional motion vector of the pixel block and a block motion compensation algorithm.
12 . The electronic device according to claim 11 , wherein obtaining the bidirectional motion vector of the pixel block between the adjacent frame images in the target image group comprises:
obtaining the bidirectional motion vector of the pixel block between the adjacent frame images in the target image group based on an improved dense inverse search (DIS) optical flow algorithm,
wherein at least one of the following is met: a resolution of a bottom layer image of an image pyramid used in the improved DIS optical flow algorithm is less than a resolution of a bottom layer image of an image pyramid used in an original DIS optical flow algorithm, or, a number of iterations used in the improved DIS optical flow algorithm is less than a number of iterations used in the original DIS optical flow algorithm.
13 . The electronic device according to claim 10 , wherein determining the main object area and the background area of the certain frame image in the target image group comprises:
taking an image located in the middle of the target image group as the certain frame image;
processing the certain frame image by using the object instance segmentation algorithm; and
obtaining the main object area and the background area of the certain frame image based on a processing result.
14 . A non-transitory computer-readable storage medium having stored thereon a computer program which, when executed by a processor, causes the processor to perform following video processing operations:
obtaining a plurality of image groups based on a video frame sequence of an initial video;
performing, for each target image group among the plurality of image groups, following operations:
performing motion blur processing based on frame images in a target image group, so as to obtain a motion-blurred image corresponding to the target image group;
determining, by using an object instance segmentation algorithm, a main object area and a background area of a certain frame image in the target image group; and
merging the motion-blurred image and the certain frame image according to the main object area and the background area so as to obtain a target merged image corresponding to the target image group, wherein an image part of the target merged image in the main object area corresponds to an image part of the certain frame image in the main object area, and an image part of the target merged image in the background area corresponds to an image part of the motion-blurred image in the background area; and
generating a target video based on the target merged images respectively corresponding to the plurality of image groups, wherein a sequence in which the target merged images respectively corresponding to the plurality of image groups are played in the target video is the same as a sequence in which the plurality of image groups are played in the initial video,
wherein performing the motion blur processing based on the frame images in the target image group, so as to obtain the motion-blurred image corresponding to the target image group comprises:
interpolating a certain number of intermediate frame images between adjacent frame images in the target image group by using an optical flow interpolation algorithm, and
performing average merging on all image frames in the target image group after the frame interpolation, so as to obtain the motion-blurred image corresponding to the target image group.
15 . The storage medium according to claim 14 , wherein interpolating the certain number of intermediate frame images between the adjacent frame images in the target image group by using the optical flow interpolation algorithm comprises:
obtaining a bidirectional motion vector of a pixel block between the adjacent frame images in the target image group; and
interpolating the certain number of intermediate frame images between the adjacent frame images according to the bidirectional motion vector of the pixel block and a block motion compensation algorithm.
16 . The storage medium according to claim 15 , wherein obtaining the bidirectional motion vector of the pixel block between the adjacent frame images in the target image group comprises:
obtaining the bidirectional motion vector of the pixel block between the adjacent frame images in the target image group based on an improved dense inverse search (DIS) optical flow algorithm,
wherein at least one of the following is met: a resolution of a bottom layer image of an image pyramid used in the improved DIS optical flow algorithm is less than a resolution of a bottom layer image of an image pyramid used in an original DIS optical flow algorithm, or, a number of iterations used in the improved DIS optical flow algorithm is less than a number of iterations used in the original DIS optical flow algorithm.
17 . The storage medium according to claim 14 , wherein determining the main object area and the background area of the certain frame image in the target image group comprises:
taking an image located in the middle of the target image group as the certain frame image;
processing the certain frame image by using the object instance segmentation algorithm; and
obtaining the main object area and the background area of the certain frame image based on a processing result.