Video cropping method and apparatus, storage medium and electronic device
View Patent ↗This disclosure relates to a video cropping method and apparatus, storage medium, and electronic device. The present disclosure method: acquiring an original video to be cropped; performing frame extraction processing on the original video to obtain a plurality of target video frames; determining, for each of the target video frames, a target candidate cropping box corresponding to the target video frame according to a main content in the target video frame; performing interpolation processing according to the target candidate cropping box corresponding to each of the target video frames to determine a target cropping box corresponding to each frame picture in the original video; and cropping the original video according to the target cropping box corresponding to the each frame picture.
1 . A video cropping method, comprising:
acquiring an original video to be cropped;
performing frame extraction processing on the original video to obtain a plurality of target video frames;
calculating, for each target video frame of the target video frames, a cost function according to a main content in the target video frame and a plurality of candidate cropping boxes corresponding to the target video frame, the cost function comprising a first function for characterizing importance of the main content in the target video frame and a second function for characterizing a size difference between candidate cropping boxes in two of the target video frames;
determining, among the plurality of candidate cropping boxes, a target candidate cropping box that minimizes a calculation result of the cost function;
performing interpolation processing according to the target candidate cropping box corresponding to each target video frame of the target video frames to determine a target cropping box corresponding to each frame picture in the original video; and
cropping the original video according to the target cropping box corresponding to each frame picture,
wherein the first function is calculated by:
determining, for each candidate cropping box of the candidate cropping boxes, a content inclusion degree of the candidate cropping box to the main content in the target video frame, and determining a content proportion between the main content included in the candidate cropping box and the complete main content in the target video frame; and
calculating the first function according to the content inclusion degree and the content proportion.
2 . The method according to claim 1 , wherein an expression of the first function is:
f
=
1
-
(
β
1
A
(
C
i
)
S
(
C
i
)
+
β
2
A
(
C
i
)
A
(
I
i
)
)
where ƒ denotes a calculation result of the first function, β 1 and β 2 denote preset weight values, A(C i ) denotes a main content included in a candidate cropping box C i corresponding to an ith target video frame, S(C i ) denotes an area of the candidate cropping box C i corresponding to the ith target video frame, A(I i ) denotes a complete main content in the ith target video frame,
A
(
C
i
)
S
(
C
i
)
denotes a content inclusion degree of the candidate cropping box C i corresponding to the ith target video frame to the main content in the ith target video frame, and
A
(
C
i
)
A
(
I
i
)
denotes a content proportion between the main content included in the candidate cropping box C i corresponding to the ith target video frame and the complete main content in the ith target video frame.
3 . The method according to claim 1 , wherein the second function is calculated by:
determining a width difference and a length difference between a candidate cropping box in a first target video frame and a candidate cropping box in a second target video frame, wherein the first target video frame is an adjacent previous one video frame of the second target video frame; and
calculating the second function according to the width difference and the length difference.
4 . The method according to claim 1 , wherein performing the interpolation processing according to the target candidate cropping box corresponding to each target video frame of the target video frames to determine the target cropping box corresponding to each frame picture in the original video comprises:
performing smoothing processing according to the target candidate cropping box corresponding to each target video frame of the target video frames to obtain a smooth candidate cropping box corresponding to each target video frame of the target video frames; and
performing interpolation processing according to the smooth candidate cropping box corresponding to each target video frame of the target video frames to obtain the target cropping box corresponding to each frame picture in the original video.
5 . The method according to claim 1 , wherein the method further comprises:
acquiring a cropping width and a cropping length corresponding to the original video; and
performing border padding on each cropped frame picture, so that a width of each cropped frame picture is the cropping width and a length of each cropped frame picture is the cropping length.
6 . A non-transitory computer-readable medium having stored thereon computer programs which, when executed by a processing means, execute the instructions of:
acquiring an original video to be cropped;
performing frame extraction processing on the original video to obtain a plurality of target video frames;
calculating, for each target video frame of the target video frames, a cost function according to a main content in the target video frame and a plurality of candidate cropping boxes corresponding to the target video frame, the cost function comprising a first function for characterizing importance of the main content in the target video frame and a second function for characterizing a size difference between candidate cropping boxes in two of the target video frames;
determining, among the plurality of candidate cropping boxes, a target candidate cropping box that minimizes a calculation result of the cost function;
performing interpolation processing according to the target candidate cropping box corresponding to each target video frame of the target video frames to determine a target cropping box corresponding to each frame picture in the original video; and
cropping the original video according to the target cropping box corresponding to each frame picture,
wherein the first function is calculated by:
determining, for each candidate cropping box of the candidate cropping boxes, a content inclusion degree of the candidate cropping box to the main content in the target video frame, and determining a content proportion between the main content included in the candidate cropping box and the complete main content in the target video frame; and
calculating the first function according to the content inclusion degree and the content proportion.
7 . An electronic device, comprising:
a storage means having computer programs stored thereon; and
a processing means configured to execute the computer programs in the storage means to execute the instructions of:
acquiring an original video to be cropped;
performing frame extraction processing on the original video to obtain a plurality of target video frames;
calculating, for each target video frame of the target video frames, a cost function according to a main content in the target video frame and a plurality of candidate cropping boxes corresponding to the target video frame, the cost function comprising a first function for characterizing importance of the main content in the target video frame and a second function for characterizing a size difference between candidate cropping boxes in two of the target video frames;
determining, among the plurality of candidate cropping boxes, a target candidate cropping box that minimizes a calculation result of the cost function;
performing interpolation processing according to the target candidate cropping box corresponding to each target video frame of the target video frames to determine a target cropping box corresponding to each frame picture in the original video; and
cropping the original video according to the target cropping box corresponding to each frame picture,
wherein the first function is calculated by:
determining, for each candidate cropping box of the candidate cropping boxes, a content inclusion degree of the candidate cropping box to the main content in the target video frame, and determining a content proportion between the main content included in the candidate cropping box and the complete main content in the target video frame; and
calculating the first function according to the content inclusion degree and the content proportion.
8 . The electronic device according to claim 7 , wherein an expression of the first function is:
f
=
1
-
(
β
1
A
(
C
i
)
S
(
C
i
)
+
β
2
A
(
C
i
)
A
(
I
i
)
)
where ƒ denotes a calculation result of the first function, β 1 and β 2 denote preset weight values, A(C i ) denotes a main content included in a candidate cropping box C i corresponding to an ith target video frame, S(C i ) denotes an area of the candidate cropping box C i corresponding to the ith target video frame, A(I i ) denotes a complete main content in the ith target video frame,
A
(
C
i
)
S
(
C
i
)
denotes a content inclusion degree of the candidate cropping box C i corresponding to the ith target video frame to the main content in the ith target video frame, and
A
(
C
i
)
A
(
I
i
)
denotes a content proportion between the main content included in the candidate cropping box C i corresponding to the ith target video frame and the complete main content in the ith target video frame.
9 . The electronic device according to claim 7 , wherein the second function is calculated by:
determining a width difference and a length difference between a candidate cropping box in a first target video frame and a candidate cropping box in a second target video frame, wherein the first target video frame is an adjacent previous one video frame of the second target video frame; and
calculating the second function according to the width difference and the length difference.
10 . The electronic device according to claim 7 , wherein performing the interpolation processing according to the target candidate cropping box corresponding to each target video frame of the target video frames to determine the target cropping box corresponding to each frame picture in the original video comprises:
performing smoothing processing according to the target candidate cropping box corresponding to each target video frame of the target video frames to obtain a smooth candidate cropping box corresponding to each target video frame of the target video frames; and
performing interpolation processing according to the smooth candidate cropping box corresponding to each target video frame of the target video frames to obtain the target cropping box corresponding to each frame picture in the original video.
11 . The electronic device according to claim 7 , wherein the processing means is configured to execute the computer programs in the storage means to further execute the instructions of:
acquiring a cropping width and a cropping length corresponding to the original video; and
performing border padding on each cropped frame picture, so that a width of each cropped frame picture is the cropping width and a length of each cropped frame picture is the cropping length.