Disclosure of Invention
In view of this, the invention provides a video frame processing method, a device and an electronic device, so as to solve the problems that when a filter effect is added to a video frame, the filter effect is single, the video special effect is poor, the video synthesis quality is reduced, and the filter requirement of a user cannot be met by uniformly processing the whole Zhang Shipin frame.
In order to solve the technical problems, the invention adopts the following technical scheme:
a video frame processing method, comprising:
acquiring a video frame which needs filter adding operation in a target video, and converting the video frame into a target video frame in a preset format;
partitioning the target video frame to obtain a plurality of sub video frames;
and dynamically setting the gray value of the edge of the sub-video frame as a corresponding target gray value and the transparency of the edge of the sub-video frame as a corresponding target transparency according to the arrangement sequence of the plurality of sub-video frames.
Optionally, after converting the video frame into a target video frame in a preset format, the method further includes:
extracting channel values of preset channels of pixels in the target video frame, and correcting the channel values to obtain corrected channel values;
calculating a linear correction value of the pixel according to the corrected channel value;
and determining a gray value corresponding to the linear correction value and taking the gray value as the gray value of the pixel.
Optionally, after determining the gray value corresponding to the linear correction value and serving as the gray value of the pixel, the method further includes, before performing blocking on the target video frame to obtain a plurality of sub video frames:
and filtering the target video frame.
Optionally, the target video frame is segmented to obtain a plurality of sub video frames, including:
splitting the target video frame into a plurality of rectangular pictures with side lengths of a preset length, and taking each rectangular picture as a sub video frame;
and setting the pixel value of the side length of the sub-video frame based on the preset length.
Optionally, dynamically setting the gray value of the edge of the sub-video frame to be a corresponding target gray value and the transparency of the edge of the sub-video frame to be a corresponding target transparency according to the arrangement sequence of the plurality of sub-video frames, including:
determining a target gray value and a target transparency of the edge of the sub-video frame;
according to the arrangement sequence of the plurality of sub-video frames, setting the gray level value of the edge of the sub-video frame corresponding to the filter adding time as the target gray level value and setting the transparency of the edge of the sub-video frame as the target transparency in different filter adding times.
Optionally, determining the target gray value and the target transparency of the edge of the sub-video frame includes:
performing edge detection processing on the sub-video frames to determine edges of the sub-video frames;
acquiring a gray value of a pixel in a preset range of the edge;
correcting the gray value of the edge based on the gray value of the pixel in the preset range of the edge to obtain the target gray value of the edge of the sub-video frame;
acquiring transparency of the edge of the sub-video frame and a transparency coefficient of a transparency interval in which the transparency is located;
and calculating the target transparency of the edge of the sub-video frame according to the preset maximum transparency value, the transparency of the edge of the sub-video frame and the transparency coefficient.
Optionally, in accordance with the arrangement sequence of the plurality of sub-video frames, setting, in different filter adding times, a gray value of an edge of the sub-video frame corresponding to the filter adding time to the target gray value, and setting a transparency of the edge of the sub-video frame to the target transparency, includes:
acquiring the total filter adding time of the target video frame, and calculating the filter adding time of the sub video frame according to the total filter adding time and the number of the sub video frames;
determining a sub-video frame corresponding to each filter adding time according to the arrangement sequence of the plurality of sub-video frames;
and setting the gray value of the edge of the sub-video frame corresponding to the filter adding time as the target gray value and setting the transparency of the edge of the sub-video frame as the target transparency in different filter adding times.
A video frame processing apparatus comprising:
the video frame conversion module is used for acquiring a video frame which needs filter adding operation in the target video and converting the video frame into a target video frame in a preset format;
the video frame processing module is used for blocking the target video frame to obtain a plurality of sub video frames;
the filter processing module is used for dynamically setting the gray value of the edge of the sub-video frame to be a corresponding target gray value and the transparency of the edge of the sub-video frame to be a corresponding target transparency according to the arrangement sequence of the plurality of sub-video frames.
Optionally, the method further comprises:
the channel value processing module is used for extracting the channel value of the preset channel of the pixel in the target video frame, and correcting the channel value to obtain a corrected channel value;
the correction module is used for calculating the linear correction value of the pixel according to the corrected channel value;
and the gray value determining module is used for determining a gray value corresponding to the linear correction value and taking the gray value as the gray value of the pixel.
Optionally, the method further comprises:
and the filter module is used for carrying out filtering operation on the target video frame.
Optionally, the video frame processing module is specifically configured to:
splitting the target video frame into a plurality of rectangular pictures with side lengths of a preset length, taking each rectangular picture as a sub video frame, and setting pixel values of the side lengths of the sub video frame based on the preset length.
Optionally, the filter processing module includes:
the data determining submodule is used for determining a target gray value and a target transparency of the edge of the sub-video frame;
and the filter adding sub-module is used for setting the gray value of the edge of the sub-video frame corresponding to the filter adding time as the target gray value and setting the transparency of the edge of the sub-video frame as the target transparency in different filter adding times according to the arrangement sequence of the plurality of sub-video frames.
An electronic device, comprising: a memory and a processor;
wherein the memory is used for storing programs;
the processor invokes a program and is configured to perform the video frame processing method described above.
Compared with the prior art, the invention has the following beneficial effects:
the invention provides a video frame processing method, a video frame processing device and electronic equipment, which are used for acquiring a video frame which needs filter adding operation in a target video, converting the video frame into a target video frame with a preset format, partitioning the target video frame to obtain a plurality of sub-video frames, and dynamically setting the gray value of the edge of the sub-video frame as a corresponding target gray value and the transparency of the edge of the sub-video frame as a corresponding target transparency according to the arrangement sequence of the plurality of sub-video frames. In the invention, the filter is dynamically added to the sub-video frames obtained by splitting one video frame, so that the filter effect is increased, the video special effect is further improved, the video synthesis quality is improved, and the filter requirement of a user is met. In addition, in the invention, the video frame is converted into the target video frame with the preset format, so that the lossless filter processing effect can be realized when the filter effect is added.
Detailed Description
The following description of the embodiments of the present invention will be made clearly and completely with reference to the accompanying drawings, in which it is apparent that the embodiments described are only some embodiments of the present invention, but not all embodiments. All other embodiments, which can be made by those skilled in the art based on the embodiments of the invention without making any inventive effort, are intended to be within the scope of the invention.
At present, when a filter effect is added to a video frame, the filter effect is uniformly processed on the whole Zhang Shipin frame, the filter effect is single, the special effect is poor in display, the filter effect is difficult to adapt to the diversified requirements in the content, and the filter requirement of a user cannot be met.
In order to solve the technical problem, the inventor finds that the video frame can be subjected to blocking treatment, and the filter is dynamically added to the blocked sub-video frame, so that the filter effect is improved, the special effect is improved, the diversified requirements are met, and further the filter requirement of a user is met.
Specifically, the embodiment of the invention provides a video frame processing method, a video frame processing device and electronic equipment, which are used for acquiring a video frame which needs filter adding operation in a target video, converting the video frame into a target video frame with a preset format, partitioning the target video frame to obtain a plurality of sub-video frames, and dynamically setting the gray value of the edge of the sub-video frame as a corresponding target gray value and the transparency of the edge of the sub-video frame as a corresponding target transparency according to the arrangement sequence of the plurality of sub-video frames. In the invention, the filter is dynamically added to the sub-video frames obtained by splitting one video frame, so that the filter effect is increased, the video special effect is further improved, the video synthesis quality is improved, and the filter requirement of a user is met. In addition, in the invention, the video frame is converted into the target video frame with the preset format, so that the lossless filter processing effect can be realized when the filter effect is added.
Based on the foregoing, another embodiment of the present invention provides a video frame processing method, referring to fig. 1, which may include:
s11, acquiring a video frame which needs to be subjected to filter adding operation in the target video, and converting the video frame into a target video frame in a preset format.
Wherein the preset format is a preset PGM format.
In this embodiment, a filter operation may be sequentially added to video frames in the video, which is referred to as a target video in this embodiment.
And converting the video frames which need to be subjected to filter adding operation in the target video into target video frames in a preset PGM format.
Among them, PGM (one of simple file formats for storing and exchanging image data) is composed of two parts of data, a file header part and a pixel data part, respectively.
The first line in the header section identifies the picture format in a "Magic Number" which is a pattern of P1, P2, P3, P4, P5, P6, etc. Wherein the P1-P3 mode reading uses a mode supporting the Ascii code format reading, and the PIL only supports the binary format P4-P6 mode reading.
The second row is picture width, picture height.
The third line is the maximum value of this picture data.
The pixel data is stored in rows in a "row-major order". Default condition. Each line cannot be longer than 70 characters, and it is safe to store one pixel per line.
In this embodiment, the video frame format is converted into the preset PGM format, because the existing jgp, png, bmp, yuv format files are only processed, so that there is necessarily a phenomenon that the values of some pixels are damaged, and the value of each pixel of the PGM file is vector, so that the lossless filter can be achieved. The filter effect adopts a pgm format, visual preview can be realized in the earlier stage of the pgm format, the visual preview can be realized, and the filter effect is set for the processed video in the later stage, and then the effect of lossless filter processing is achieved.
It should be noted that, the filter effect picture may be set in advance, and the modes of the filter effect picture may be modes of P1, P2, P3, P4, P5, P6, etc. in this embodiment, the preset PGM format is the mode of the filter effect picture, such as P2.
After converting the video frame into a target video frame in a preset format, gray values of pixels in the target video frame may also be determined.
In practical applications, for each pixel in the target video frame, its corresponding gray value is determined.
Specifically, determining the gray value of the pixel in the target video frame may include:
1) Extracting channel values of preset channels of pixels in the target video frame, and correcting the channel values to obtain corrected channel values.
Specifically, for a pixel in a target video frame, a channel value of a preset channel thereof may be extracted. The preset channel may be a R, G, B channel. An RGBA channel map of the pixel can be obtained and R, G, B values extracted therefrom. And then carrying out correction operation on the channel value to obtain a corrected channel value.
Wherein, the corrected channel value is:
Rlinear=pow(R,1/Gamma)
Glinear=pow(G,1/Gamma)
Blinear=pow(B,1/Gamma);
wherein, rline, glline, bliner is in [0,1] range, rline is corrected R value, glline is corrected G value, bliner is corrected B value. Gamma is a fixed value, such as 2.2.
2) And calculating the linear correction value of the pixel according to the corrected channel value.
Specifically, the linear correction value clear of the pixel is:
Clinear=0.2126Rlinear+0.7152Glinear+0.0722Blinear。
3) And determining a gray value corresponding to the linear correction value and taking the gray value as the gray value of the pixel.
Specifically, the linear correction value obtained by linear transformation is corrected according to a linear Gamma correction formula to obtain a gray value Csrgb corresponding to the linear correction value, specifically:
csrgb=12.92 x clear, when clear < = 0.0031308;
Csrgb=1.055*Clinear 1/2.4 -0.055, when clear>0.0031308
Through the step, the gray value of the gray image input by PGM can be obtained by the pixel value corresponding to each pixel point.
In this embodiment, the gray value corresponding to the linear correction value is determined, that is, the image is subjected to the graying process.
It should be noted that, after the gray value of the pixel in the target video frame is determined (specifically, after the gray value corresponding to the linearity correction value is determined and the gray value of the pixel is used), the filtering operation may also be performed on the target video frame before step S12 is performed.
In the filtering, gaussian filtering can be adopted, and interference can be avoided through filtering.
S12, the target video frames are segmented, and a plurality of sub video frames are obtained.
Specifically, the target video frame is split into a plurality of rectangular pictures with side lengths of a preset length, each rectangular picture is used as a sub video frame, and pixel values of the side lengths of the sub video frames are set based on the preset length.
For example, a target video frame, which is a gray image, is read into a pixel array, and is partitioned, the PGM full image is divided into squares with a side length of m (a preset length), and sub-images are generated in a column order, and each sub-image is a sub-video frame.
The regional pixel p=m/original resolution size corresponding to the side length of the sub-video frame.
The number of sub-video frames in the row and column directions = original resolution size/pixel (p) corresponding to the sub-picture side length.
The sub-tile sequence numbers are arranged in 1, 2, 3, 4, … ….
S13, dynamically setting the gray value of the edge of the sub-video frame to be a corresponding target gray value according to the arrangement sequence of the plurality of sub-video frames, and setting the transparency of the edge of the sub-video frame to be a corresponding target transparency.
In practical application, when dynamically setting the gray value and transparency of the edge of the sub-video frame, determining the target gray value and target transparency of the edge of the sub-video frame, and then performing the dynamic filter adding operation.
Namely, step S13 includes:
1) Determining a target gray value and a target transparency of the edge of the sub-video frame;
2) According to the arrangement sequence of the plurality of sub-video frames, setting the gray level value of the edge of the sub-video frame corresponding to the filter adding time as the target gray level value and setting the transparency of the edge of the sub-video frame as the target transparency in different filter adding times.
The implementation process of determining the target gray value and the target transparency of the edge of the sub-video frame is as follows:
in this embodiment, when the filter is added, the gray value and the transparency of the edge of the sub-video frame are adjusted, but the gray value and the transparency value of the non-edge area of the sub-video frame remain unchanged.
Referring to fig. 2, determining a target gray value and a target transparency of an edge of the sub-video frame may include:
s21, carrying out edge detection processing on the sub-video frames to determine edges of the sub-video frames.
In this embodiment, a canny operator may be used to detect an edge of a sub-video frame, so as to obtain an edge of the sub-video frame.
S22, acquiring the gray value of the pixel in the preset range of the edge.
Specifically, in order to ensure that the gray value of the pixel changes naturally when the filter effect is added, the gray value of the edge can be corrected by using the gray value of the pixel near the edge, so that the gray value of the edge changes naturally.
The pixels within the preset range in the present embodiment may be four pixels up, down, left, and right of the pixel at the edge. Then, gradation values of the four pixels are acquired.
S23, correcting the gray value of the edge based on the gray value of the pixel in the preset range of the edge to obtain the target gray value of the edge of the sub-video frame.
Specifically, the boundary line may be an edge, and weights of gray values of four pixels around the boundary line may be preset for pixels located at the edge, and then a product of the gray values of the pixels and the weights may be used as a target gray value of the edge of the sub-video frame.
The gray values of the pixels inside and outside the edge are consistent with the gray of the corresponding position of the sub-video frame.
S24, acquiring transparency of the edge of the sub-video frame and transparency coefficients of a transparency interval where the transparency is located.
Specifically, transparency intervals are preset, and different transparency intervals correspond to different transparency coefficient intervals, such as [ under, over ]. Wherein, under is the transparency coefficient minimum value of the interval, and over is the transparency coefficient maximum value of the interval.
In this embodiment, the transparency of the edge of the sub-video frame is obtained, then a transparency interval where the transparency is located is determined, and then transparency coefficients under and over corresponding to the transparency interval are determined.
S25, calculating the target transparency of the edge of the sub-video frame according to the preset maximum transparency value, the transparency of the edge of the sub-video frame and the transparency coefficient.
Specifically, the target transparency of the edge of the sub-video frame is:
under*(1-(alpha/alpha_maxval))+over*(alpha/alpha_maxval)
wherein alpha_maxval is a preset maximum transparency value, alpha is the transparency of the edge of the sub-video frame, under is a transparency coefficient minimum value, and over is a transparency coefficient maximum value.
In another implementation manner of the present invention, according to the arrangement order of the plurality of sub-video frames, in different filter adding times, the implementation process of setting the gray value of the edge of the sub-video frame corresponding to the filter adding time to the target gray value and setting the transparency of the edge of the sub-video frame to the target transparency is as follows:
in this embodiment, the filter adding operation is not performed uniformly on the entire target video frame, but may be performed on different sub-video frames within different filter adding times for the sub-video frames in the target video frame.
In this embodiment, referring to fig. 3, "according to the arrangement order of the plurality of sub-video frames, setting the gray value of the edge of the sub-video frame corresponding to the filter addition time to the target gray value in different filter addition times, and setting the transparency of the edge of the sub-video frame to the target transparency" specifically includes:
s31, acquiring the total filter adding time of the target video frame, and calculating the filter adding time of the sub video frame according to the total filter adding time and the number of the sub video frames.
Specifically, filter addition time=filter addition total time/number of sub-video frames.
S32, determining the sub-video frames corresponding to the adding time of each filter according to the arrangement sequence of the plurality of sub-video frames.
In this embodiment, in the time of adding each filter, the filter operation is performed on which sub-video frame may be preset, for example, may be set in the order of columns or rows according to the sub-video frames.
S33, setting the gray value of the edge of the sub-video frame corresponding to the filter adding time as the target gray value and setting the transparency of the edge of the sub-video frame as the target transparency in different filter adding times.
For example, if the filter adding operation is performed on 30 sub-video frames within 1s, the filter operation may be performed on the first sub-video frame in the column order within 1/30 s. Then within 2/30s, a filter operation … … may be performed on the second sub-video frame, and so on, until within 30/30s, a filter operation may be performed on the thirty-th sub-video frame.
In addition, a filter operation may be performed on at least one sub-video frame at the same time, for example, a filter operation may be performed on a first sub-video frame within 1/30s, and a filter operation … … may be performed on a second and third sub-video frames at the same time within 2/30 s. When the filter operation is performed on the second sub-video frame and the third sub-video frame simultaneously, the parallel filter adding operation can be adopted, so that the processing speed is improved, and the time consumption is reduced.
Wherein adding a filter means setting a gray value of an edge of a sub-video frame to the target gray value and setting a transparency of the edge of the sub-video frame to the target transparency.
Namely, the gradient change of the picture color of the video frame is changed through the change of the PGM pixel value, and the effect of the video 'track' filter is further achieved. If so, the preset PGM format is changed, and the final displayed filter effect is different.
After the filter addition is performed on the present video frame, the filter addition may be performed on the next video frame, and so on, until the last video frame.
In this embodiment, a video frame in a target video, in which a filter adding operation is required, is acquired, the video frame is converted into a target video frame in a preset format, the target video frame is segmented to obtain a plurality of sub video frames, and according to the arrangement sequence of the plurality of sub video frames, the gray level value of the edge of the sub video frame is dynamically set to be a corresponding target gray level value, and the transparency of the edge of the sub video frame is set to be a corresponding target transparency. In the invention, the filter is dynamically added to the sub-video frames obtained by splitting one video frame, so that the filter effect is increased, the video special effect is further improved, the video synthesis quality is improved, and the filter requirement of a user is met. In addition, in the invention, the video frame is converted into the target video frame with the preset format, so that the lossless filter processing effect can be realized when the filter effect is added.
In addition, the filter is added in the embodiment, so that the efficiency is higher, the video special effect output effect can be edited, the design and research cost of the special effect can be reduced, the video special effect is more abundant and diversified, the final synthesis quality is ensured, and the editing efficiency is improved. In addition, the operation is simple and convenient, and easy to learn and use.
In addition, when the filter is added, the filter can be added in a parallel mode, so that the efficiency is improved and the time consumption is reduced.
Optionally, on the basis of the embodiment of the video frame processing method, another embodiment of the present invention provides a video frame processing apparatus, referring to fig. 4, may include:
the video frame conversion module 11 is configured to obtain a video frame in the target video, where the video frame needs to be subjected to filter adding operation, and convert the video frame into a target video frame in a preset format;
the video frame processing module 12 is configured to block the target video frame to obtain a plurality of sub video frames;
the filter processing module 13 is configured to dynamically set the gray value of the edge of the sub-video frame to a corresponding target gray value and the transparency of the edge of the sub-video frame to a corresponding target transparency according to the arrangement sequence of the plurality of sub-video frames.
Further, the method further comprises the following steps:
the channel value processing module is used for extracting the channel value of the preset channel of the pixel in the target video frame, and correcting the channel value to obtain a corrected channel value;
the correction module is used for calculating the linear correction value of the pixel according to the corrected channel value;
and the gray value determining module is used for determining a gray value corresponding to the linear correction value and taking the gray value as the gray value of the pixel.
Further, the method further comprises the following steps:
and the filter module is used for carrying out filtering operation on the target video frame.
Further, the video frame processing module is specifically configured to:
splitting the target video frame into a plurality of rectangular pictures with side lengths of a preset length, taking each rectangular picture as a sub video frame, and setting pixel values of the side lengths of the sub video frame based on the preset length.
Further, the filter processing module 13 includes:
the data determining submodule is used for determining a target gray value and a target transparency of the edge of the sub-video frame;
and the filter adding sub-module is used for setting the gray value of the edge of the sub-video frame corresponding to the filter adding time as the target gray value and setting the transparency of the edge of the sub-video frame as the target transparency in different filter adding times according to the arrangement sequence of the plurality of sub-video frames.
Further, the data determination submodule includes:
performing edge detection processing on the sub-video frames to determine edges of the sub-video frames;
a gray value obtaining unit, configured to obtain a gray value of a pixel within a preset range of the edge;
the correcting unit is used for correcting the gray value of the edge based on the gray value of the pixel in the preset range of the edge to obtain the target gray value of the edge of the sub-video frame;
the transparency processing unit is used for acquiring the transparency of the edge of the sub-video frame and the transparency coefficient of the transparency interval where the transparency is located;
and the transparency calculation unit is used for calculating the target transparency of the edge of the sub-video frame according to a preset maximum transparency value, the transparency of the edge of the sub-video frame and the transparency coefficient.
Further, the filter adding submodule includes:
the time processing unit is used for obtaining the total filter adding time of the video and calculating the filter adding time of the sub-video frames according to the total filter adding time and the number of the sub-video frames;
the video frame determining unit is used for determining the sub-video frames corresponding to the adding time of each filter according to the arrangement sequence of the plurality of sub-video frames;
and the filter adding unit is used for setting the gray value of the edge of the sub-video frame corresponding to the filter adding time as the target gray value and setting the transparency of the edge of the sub-video frame as the target transparency in different filter adding times.
In this embodiment, a video frame in a target video, in which a filter adding operation is required, is acquired, the video frame is converted into a target video frame in a preset format, the target video frame is segmented to obtain a plurality of sub video frames, and according to the arrangement sequence of the plurality of sub video frames, the gray level value of the edge of the sub video frame is dynamically set to be a corresponding target gray level value, and the transparency of the edge of the sub video frame is set to be a corresponding target transparency. In the invention, the filter is dynamically added to the sub-video frames obtained by splitting one video frame, so that the filter effect is increased, the video special effect is further improved, the video synthesis quality is improved, and the filter requirement of a user is met. In addition, in the invention, the video frame is converted into the target video frame with the preset format, so that the lossless filter processing effect can be realized when the filter effect is added.
In addition, the filter is added in the embodiment, so that the efficiency is higher, the video special effect output effect can be edited, the design and research cost of the special effect can be reduced, the video special effect is more abundant and diversified, the final synthesis quality is ensured, and the editing efficiency is improved. In addition, the operation is simple and convenient, and easy to learn and use.
In addition, when the filter is added, the filter can be added in a parallel mode, so that the efficiency is improved and the time consumption is reduced.
It should be noted that, in the working process of each module, sub-module and unit in this embodiment, please refer to the corresponding description in the above embodiment, and the description is omitted here.
Optionally, on the basis of the embodiments of the video frame processing method and apparatus, another embodiment of the present invention provides an electronic device, including: a memory and a processor;
wherein the memory is used for storing programs;
the processor invokes a program and is configured to perform the video frame processing method described above.
In this embodiment, a video frame in a target video, in which a filter adding operation is required, is acquired, the video frame is converted into a target video frame in a preset format, the target video frame is segmented to obtain a plurality of sub video frames, and according to the arrangement sequence of the plurality of sub video frames, the gray level value of the edge of the sub video frame is dynamically set to be a corresponding target gray level value, and the transparency of the edge of the sub video frame is set to be a corresponding target transparency. In the invention, the filter is dynamically added to the sub-video frames obtained by splitting one video frame, so that the filter effect is increased, the video special effect is further improved, the video synthesis quality is improved, and the filter requirement of a user is met. In addition, in the invention, the video frame is converted into the target video frame with the preset format, so that the lossless filter processing effect can be realized when the filter effect is added.
In addition, the filter is added in the embodiment, so that the efficiency is higher, the video special effect output effect can be edited, the design and research cost of the special effect can be reduced, the video special effect is more abundant and diversified, the final synthesis quality is ensured, and the editing efficiency is improved. In addition, the operation is simple and convenient, and easy to learn and use.
In addition, when the filter is added, the filter can be added in a parallel mode, so that the efficiency is improved and the time consumption is reduced.
The previous description of the disclosed embodiments is provided to enable any person skilled in the art to make or use the present invention. Various modifications to these embodiments will be readily apparent to those skilled in the art, and the generic principles defined herein may be applied to other embodiments without departing from the spirit or scope of the invention. Thus, the present invention is not intended to be limited to the embodiments shown herein but is to be accorded the widest scope consistent with the principles and novel features disclosed herein.