Animation subtitle drawing method with changeable effect
Technical Field
The invention relates to the field of video subtitles, in particular to an animation subtitle drawing method with changeable effect.
Background
With the popularization of mobile internet, more and more people use mobile phones to make micro videos and share the micro videos on line. Many short films (such as teaching videos, making fun films, etc.) require caption aids. However, most of the existing caption tools in the market can only add basic static characters or store animation captions by a group of picture sequences, and have large volume and poor expansibility. In addition, the simple animation effect cannot satisfy diversified production requirements.
Disclosure of Invention
The invention aims to provide an animation subtitle drawing method with changeable effects, so that each animation only needs one configuration file, a plurality of picture files do not need to be packed, the size is small, and the performance on a mobile phone is good.
In order to solve the technical problems, the technical scheme of the invention is as follows:
a method for drawing animation subtitles with changeable effects specifically comprises the following steps:
101) and a step of drawing characters: drawing characters on another blank picture, and transmitting the characters into OpenGL, wherein the OpenGL is a professional graphical program interface which defines a cross-programming language and cross-platform programming interface specification;
102) a step of acquiring characters: analyzing the caption configuration file to obtain the attribute of the characters, and constructing a cubic Bezier curve to obtain the path and position information of the characters;
103) character effect step: calculating an animation matrix of the characters according to an interpolation mode and animation attributes, wherein the interpolation mode determines a position matrix of the characters according to the character path and the position information obtained in the step 102), and an animation matrix is superposed on the position matrix of each character to achieve an animation effect;
104) rendering characters: transmitting the texture obtained by drawing in the step 101) into OpenGL, rendering by a Shader, namely a Shader, and putting the character texture on a corresponding position according to the matrix obtained in the step 103) to synthesize the character texture with a background video or a picture to form an animation subtitle effect.
Further, in the step 101), the area information of the characters on the blank picture is calculated by measuring each drawn character.
Further, the attributes of the text in the step 102) include coordinates of curve points, animation attributes, time points and animation interpolation modes.
Further, the animation attributes include displacement, scaling, rotation, and blurring.
Further, the following formula (1) is adopted for obtaining the path and position information of the characters in the step 102):
[x,y]=(1-t)3P0+3(1-t)2tP1+3(1-t)2P2+t3P3formula (1)
Wherein [ x, y]Is the position of a point on the Bezier curve, t is a Bezier curve parameter, and the value P is between 0 and 10,P1,P2,P3Four control points on the bezier curve.
Further, the animation interpolation mode of step 103) includes triangle change, smooth change, fade-out change and fade-in change, and the specific processing is respectively as the following formula (2), formula (3), formula (4) and formula (5),
r ═ 0.5? r 2.0 (1.0-r) formula (2)
This formula (2) is a conditional expression, which indicates that if r < 0.5 holds, r < 2.0 r, and if r < 0.5 does not hold, r < 2.0 (1.0-r);
r ═ (1-R) × (1-R) formula (4)
R ═ R formula (5)
Wherein R is the ratio of the position of a certain character relative to the width of the whole line of characters, and R is a coefficient obtained by processing; abs is a function of the absolute value of a floating-point number.
Compared with the prior art, the invention has the advantages that:
1. the subtitle file of the invention has various effects (including character-by-character animation, integral character movement, three-dimensional transformation, character blurring and the like). Only the relevant properties of the configuration file need to be changed, and theoretically, an infinite animation form exists.
2. The user can select different animation templates at the mobile phone end, freely edit the text content and generate corresponding animation subtitles.
3. Each animation only needs one configuration file, a plurality of picture files do not need to be packaged, the size is small, and the performance on a mobile phone is good.
Drawings
Fig. 1 is a flowchart of an animation subtitle rendering method with changeable effects according to the present invention.
Detailed Description
The invention is further described with reference to the following figures and detailed description.
As shown in fig. 1, a method for drawing an animation subtitle with a changeable effect specifically includes the following steps:
101) and a step of drawing characters: and drawing characters on another blank picture, and transmitting the characters into OpenGL, wherein the OpenGL is a professional graphical program interface which defines a cross-programming language and cross-platform programming interface specification. And measuring each drawn character to calculate the region information of the character on the blank picture. Therefore, each animation only needs one configuration file, a plurality of picture files do not need to be packed, and each character can be selected in different matching sequences, so that the stored animation characters are small in size and small in storage capacity, and can be operated on a mobile phone with good performance.
102) A step of acquiring characters: and analyzing the caption configuration file to obtain the attribute of the characters, and constructing a cubic Bezier curve to obtain the path and position information of the characters. The attributes of the characters comprise curve point coordinates, animation attributes, time points and animation interpolation modes. The animation properties include displacement, zoom, rotation, blur, and the like. The path and position information of the obtained characters adopts the following formula (1):
[x,y]=(1-t)3P0+3(1-t)2tP1+3(1-t)2P2+t3P3formula (1)
Wherein [ x, y]Is the position of a point on the Bezier curve, t is a Bezier curve parameter, and the value P is between 0 and 10,P1,P2,P3Four control points on the bezier curve.
103) Character effect step: and calculating an animation matrix of the characters according to the interpolation mode and the animation attribute, wherein the interpolation mode determines the position matrix of the characters according to the character path and the position information obtained in the step 102), and the animation matrix is superposed on the position matrix of each character so as to achieve the animation effect. The animation interpolation mode comprises triangle change, smooth change, fade-out change and fade-in change, and the specific processing is respectively the following formula (2), formula (3), formula (4) and formula (5),
r ═ 0.5? r 2.0 (1.0-r) formula (2)
This formula (2) is a conditional expression, which indicates that if r < 0.5 holds, r < 2.0 r, and if r < 0.5 does not hold, r < 2.0 (1.0-r);
r ═ (1-R) × (1-R) formula (4)
R ═ R formula (5)
Wherein R is the ratio of the position of a certain character relative to the width of the whole line of characters, and R is a coefficient obtained by processing; abs is a function of the absolute value of a floating-point number.
104) Rendering characters: transmitting the texture obtained by drawing in the step 101) into OpenGL, and rendering by a Shader, namely a color Shader, so that the color, transparency, fuzzy degree and the like of each character can be changed, and the Shader also has infinite expansibility. And (4) putting the character texture on a corresponding position according to the matrix obtained in the step 103), and synthesizing the character texture with the background video or the picture to finally achieve the expected animation subtitle effect.
In summary, after selecting a movie in the mobile phone video app, the animation configuration file in the step 101) of presetting and downloading is added, so that the user can select a desired effect or a system recommended effect by himself to generate a corresponding animation, and perform text rendering of subtitles. The system can generate visible animation subtitles on the screen through the processing method.
The foregoing is only a preferred embodiment of the present invention, and it should be noted that, for those skilled in the art, several modifications and decorations can be made without departing from the spirit of the present invention, and these modifications and decorations should also be regarded as being within the scope of the present invention.