Disclosure of Invention
In view of this, embodiments of the present invention provide a video processing method and apparatus, where a user does not need to manually set a width and a height of a video during playing, and the video can automatically adapt to the size of a screen of a user equipment and is played at an original aspect ratio of the video.
In a first aspect, an embodiment of the present invention provides a video processing method, where the method includes:
acquiring playing parameters of a video, wherein the playing parameters comprise: the original aspect ratio of the video;
acquiring the width and height of a screen of user equipment;
calculating the width and height of an effective area when the video is output according to the original aspect ratio of the video and the width and height of the screen of the user equipment;
and outputting the video according to the calculated width and height of the effective area when the video is output.
In a first possible implementation manner of the first aspect, the playing parameters further include: the width and height of the current effective area of the video; the outputting the video according to the calculated width and height of the effective area when the video is output specifically comprises: and stretching or scaling the width and the height of the current effective area of the video so as to output the video with the calculated width and the calculated height of the effective area when the video is output.
With reference to the first aspect or the first possible implementation manner of the first aspect, in a second possible implementation manner, the acquiring the playing parameter of the video specifically includes: reading a data block included in the video; acquiring the playing parameters from the data blocks; wherein the data block stores the playing parameter.
With reference to the first aspect or the first possible implementation manner of the first aspect, in a third possible implementation manner, the acquiring the playing parameter of the video specifically includes: reading a file suffix name of the video; acquiring the playing parameters from the file suffix name; wherein the file suffix name contains the playing parameter.
With reference to the first possible implementation manner of the first aspect, in a fourth possible implementation manner, the acquiring the playing parameter of the video specifically includes: reading a frame of the video; acquiring the playing parameters through preset colors in the frame of the video or the width and the height of the preset colors and color areas; wherein, the color is used for representing the original aspect ratio of the video, and the width and height of the color area are used for representing the width and height of the current effective area of the video.
With reference to the first aspect, or the first possible implementation manner of the first aspect, or the second possible implementation manner of the first aspect, or the third possible implementation manner of the first aspect, or the fourth possible implementation manner of the first aspect, in a fifth possible implementation manner, the calculating the width and height of the effective area when the video is output specifically is: when in use
Time, calculate
y = b; when in use
When x = a, y = b is calculated; when in use
When, x = a is calculated,
wherein,
and in order to obtain the original aspect ratio of the video, a is the width of the screen of the user equipment, b is the height of the screen of the user equipment, x is the width of an effective area during video output, and y is the height of the effective area during video output.
In a second aspect, an embodiment of the present invention provides a video processing apparatus, including:
a first obtaining unit, configured to obtain a playing parameter of a video, where the playing parameter includes: the original aspect ratio of the video;
the second acquisition unit is used for acquiring the width and the height of a screen of the user equipment;
the calculating unit is used for calculating the width and the height of an effective area when the video is output according to the original aspect ratio of the video and the width and the height of the screen of the user equipment;
and an output unit configured to output the video according to the calculated width and height of the effective area when the video is output.
In a first possible implementation manner of the second aspect, the playing parameters further include: the width and height of the current effective area of the video; the output unit is specifically configured to: and stretching or scaling the width and the height of the current effective area of the video so as to output the video with the calculated width and the calculated height of the effective area when the video is output.
With reference to the second aspect or the first possible implementation manner of the second aspect, in a second possible implementation manner, the first obtaining unit is specifically configured to: reading a data block included in the video; acquiring the playing parameters from the data blocks; wherein the data block stores the playing parameter.
With reference to the second aspect or the first possible implementation manner of the second aspect, in a third possible implementation manner, the first obtaining unit is specifically configured to: reading a file suffix name of the video; acquiring the playing parameters from the file suffix name; wherein the file suffix name contains the playing parameter.
With reference to the first possible implementation manner of the second aspect, in a fourth possible implementation manner, the first obtaining unit is specifically configured to: reading a frame of the video; acquiring the playing parameters through preset colors in the frame of the video or the width and the height of the preset colors and color areas; wherein, the color is used for representing the original aspect ratio of the video, and the width and height of the color area are used for representing the width and height of the current effective area of the video.
In combination with the second aspect or the first possible implementation manner of the second aspect or the second possible implementation manner of the second aspect or the third possible implementation manner of the second aspect or the fourth possible implementation manner of the second aspect, in a fifth possible implementation manner, when
Time, calculate
y = b; when in use
When x = a, y = b is calculated; when in use
When, x = a is calculated,
wherein,
and in order to obtain the original aspect ratio of the video, a is the width of the screen of the user equipment, b is the height of the screen of the user equipment, x is the width of an effective area during video output, and y is the height of the effective area during video output.
According to the scheme, the width and the height of the effective area of the video output in the original width-to-height ratio can be calculated by acquiring the original width-to-height ratio of the video and the width and the height of the screen of the user equipment, and then the video is played according to the calculated width and the calculated height of the effective area of the video output. According to the scheme, manual setting by a user is not needed, the video can automatically adapt to the screen size of user equipment, and the video is guaranteed to be played in the original proportion.
Detailed Description
In order to make the objects, technical solutions and advantages of the present invention clearer, the present invention will be described in further detail with reference to the accompanying drawings, and it is apparent that the described embodiments are only a part of the embodiments of the present invention, not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Fig. 1 is a schematic flowchart illustrating a video processing method according to a first embodiment of the present invention in detail, and fig. 1 is a schematic flowchart illustrating the video processing method according to the first embodiment of the present invention. The execution subject of the video processing method is user equipment. As shown in fig. 1, the video processing method includes the steps of:
step S101, obtaining the playing parameters of the video.
The video playing parameters comprise: the original aspect ratio of the video
Video original aspect ratio
Refers to the aspect ratio of the video recording.
Optionally, the video playing parameters may further include: the width w and height h of the currently active area of the video. As shown in fig. 2, the width w and the height h of the current effective area of the video refer to the width and the height of the actual visible picture of the video with the black border removed under the current format (e.g., avi, rm, mov, etc.).
Three ways to obtain the playing parameters are described below, but this is only an example and not a limitation. In the following three ways, the playing parameters all include the original aspect ratio of the video
And the width w and the height h of the current effective area of the video, but this is only for convenience of description, and in fact, the playing parameters may only include the original aspect ratio of the video
Because the width w and the height h of the active area when outputting the video are calculated as will be described later, the width w and the height h of the current active area of the video may not necessarily be required, and refer to the detailed description of steps s103 and s104 later.
Alternatively, the video playing parameters may be stored in a data block of the video, and the user equipment obtains the playing parameters of the video by reading the data block of the video. The data block may be added to any data block in the original video by the transcoder when the transcoder transcodes the original video.
Specifically, as shown in fig. 3, the data block may be 24 bytes, wherein the first 4 bytes are used to identify the data block as 24 bytes in length. The 5 to 7 bytes are used to identify the type of the data block, which may be an mdat data block, for example. 8 to 24 bytes are used to store video playback parameters. Therefore, when the user equipment reads the data block, the playing parameters of the video can be obtained. It should be noted that the present invention is described only by the structure of the data block, and the present invention is not limited thereto.
Optionally, the file suffix name of the video may contain the video playing parameter, and the user equipment obtains the playing parameter of the video by reading the file suffix name of the video. For example, when the transcoder transcodes the original video, the transcoder adds the video playing parameters to the file suffix name of the video.
Specifically, the file name may be: filename. w _ h _ m _ n.3gp. For example, the existing video file is named<<Gaffea cat 3gp>>The width w of the current effective area of the video is 800, the height h is 450, and the original aspect ratio of the video
Is composed of
This video naming can be modified to<<Gaffefield cat 800_450_16_9.3gp>>. Therefore, when the user equipment reads the file name of the video, the playing parameters of the video can be obtained.
Optionally, the user equipment reads a frame of the video to obtain the playing parameters of the video. Wherein the color of the frame is used to represent the original aspect ratio of the video
The width and height of the color area are used to indicate the width w and height h of the currently active area of the video. The frame may be any frame of the video, and may be the first frame added to the original video by the transcoder when the transcoder transcodes the original video.
For example, red indicates that the original aspect ratio of the video is 5: 4. if the first frame of the video is red, and the actual effective area width of the red area is 800, and the actual effective area height is 540, the user equipment can know by reading the first frame of the video,
w =800, h = 540. It should be noted that the original aspect ratio of the video is represented by red only, and is 5: 4, the actual effective area width of the red area is 800, and the height is 540 for the illustration, which is not to limit the invention. Also, the frame may be used to represent the original aspect ratio of the video with only preset colors.
Step S102, acquiring the width a and the height b of the screen of the user equipment.
Step S103, according to the original aspect ratio of the video
And the width a and height b of the screen of the user equipment, and the width x and height y of the effective area when the video is output are calculated.
Specifically, when calculating the width x and the height y of the effective area in the video output, the following cases can be classified:
when in use
Time, calculate
y=b。
When aspect ratio of the screen of the user equipment
Greater than the original aspect ratio of the video
According to the original aspect ratio of the video
Outputting the video and playing the video in the maximum range on the screen of the user equipment, directly taking the height b of the screen of the user equipment as the height y of an effective area when the video is output, and then according to the original aspect ratio of the video
And the height y of the effective area when the video is output is determined, and the width x of the effective area when the video is output is calculated.
When in useWhen x = a, y = b is calculated.
When aspect ratio of the screen of the user equipment
Equal to the original aspect ratio of the video
According to the original aspect ratio of the video
And outputting the video and playing the video in the maximum range on the screen of the user equipment, wherein the width a of the screen of the user equipment can be directly used as the width x of an effective area when the video is output, and the height b of the screen of the user equipment can be used as the height y of the effective area when the video is output.
When in use
When, x = a is calculated,
when aspect ratio of the screen of the user equipment
Less than the original aspect ratio of the video
According to the original aspect ratio of the video
Outputting video and playing in the maximum range on the screen of the user equipment, the width a of the screen of the user equipment can be directly used as the width x of an effective area when the video is output, and then the video is output according to the original aspect ratio of the video
And the determined width x of the effective area when the video is output calculates the height y of the effective area when the video is output.
Step S104, according to the calculated width x and height y of the effective area when the video is output, the video is output.
Thus, according to the calculated width x and height y of the effective area when the video is output, the video is output to ensure that the video is played in the original proportion and in the maximum visible range.
Optionally, after the width x and the height y of the effective area in the video output are calculated, the width w and the height h of the current effective area of the video can be stretched or scaled according to x and y, respectively, so that the video is played on the screen in the maximum visual range according to the original scale.
With the video processing method provided by the first embodiment of the present invention, since the video may be a video after compression transcoding, the aspect ratio of the current effective area of the video may not be the aspect ratio of the video when recording, by obtaining the original aspect ratio of the video, and using the original aspect ratio of the video and the width and height of the screen of the user equipment, the original ratio of the video can be calculated, and in the case of playing in the maximum range on the user equipment, the width and height of the effective area that should be output are calculated, and then the video is played according to the calculated width and height of the effective area when the video is output. The method does not need manual setting of a user, can enable the video to automatically adapt to the screen size of user equipment, and ensures that the video is played in the original proportion and in the maximum visual range.
Fig. 4 is a schematic diagram illustrating a video processing apparatus according to a second embodiment of the present invention, and fig. 4 is a schematic diagram illustrating a structure of the video processing apparatus according to the second embodiment of the present invention. The video apparatus is used for a user equipment to implement the video processing method provided by the first embodiment of the present invention, and similar parts are not described again.
As shown in fig. 4, the video processing apparatus includes: a first obtainingunit 210, a second obtainingunit 220, a calculatingunit 230 and anoutput unit 240.
The first obtainingunit 210 is configured to obtain a playing parameter of a video.
The video playing parameters comprise: the original aspect ratio of the video
Video original aspect ratio
Refers to the aspect ratio of the video recording.
Optionally, the video playing parameters may further include: the width w and height h of the currently active area of the video.
Optionally, the first obtainingunit 210 is specifically configured to read a data block of the video, and obtain the playing parameter from the first data block, where the playing parameter is stored in the data block. The data block may be added to any data block in the original video by the transcoder when the transcoder transcodes the original video.
Specifically, the data block may be 24 bytes, wherein the first 4 bytes are used to identify the data block as 24 bytes in length. The 5 to 7 bytes are used to identify the type of the data block, which may be an mdat data block, for example. 8 to 24 bytes are used to store video playback parameters. Therefore, when the first obtainingunit 210 reads the first data block of the video, the playing parameters of the video can be known. It should be noted that the present invention is described only by the structure of the data block, and the present invention is not limited thereto.
Optionally, the first obtainingunit 210 is specifically configured to read a file suffix name of the video, and obtain the playing parameter from the file suffix name, where the file suffix name of the video includes the video playing parameter. For example, when the transcoder transcodes the original video, the transcoder adds the video playing parameters to the file suffix name of the video.
Optionally, the first obtaining
unit 210 is specifically configured to read one frame of the video; the playback parameters are obtained by the color of the frame and the width and height of the color area. Wherein the color of the frame is used to represent the original aspect ratio of the video
The width and height of the color area are used to indicate the width w and height h of the currently active area of the video. The frame may be any frame of the video that may be added to the original video by the transcoder when the transcoder transcodes the original video.
The second obtainingunit 220 is used for obtaining the width a and the height b of the screen of the user equipment.
The
computing unit 230 is used for calculating the original aspect ratio of the video
And the width a and height b of the screen of the user equipment, and the width x and height y of the effective area when the video is output are calculated.
Specifically, when calculating the width x and the height y of the effective area when outputting the video, the calculatingunit 230 may be divided into the following cases:
when in use
Time, calculate
y=b。
When aspect ratio of the screen of the user equipment
Greater than the original aspect ratio of the video
According to the original aspect ratio of the video
Outputting the video and playing the video in the maximum range on the screen of the user equipment, directly taking the height b of the screen of the user equipment as the height y of an effective area when the video is output, and then according to the original aspect ratio of the video
And the height y of the effective area when the video is output is determined, and the width x of the effective area when the video is output is calculated.
When in use
When x = a, y = b is calculated.
When aspect ratio of the screen of the user equipment
Equal to the original aspect ratio of the video
According to the original aspect ratio of the video
And outputting the video and playing the video in the maximum range on the screen of the user equipment, wherein the width a of the screen of the user equipment can be directly used as the width x of an effective area when the video is output, and the height b of the screen of the user equipment can be used as the height y of the effective area when the video is output.
When in use
When, x = a is calculated,
when aspect ratio of the screen of the user equipment
Less than the original aspect ratio of the video
According to the original aspect ratio of the video
Outputting video and playing in the maximum range on the screen of the user equipment, the width a of the screen of the user equipment can be directly used as the width x of an effective area when the video is output, and then the video is output according to the original aspect ratio of the video
And the determined width x of the effective area when the video is output calculates the height y of the effective area when the video is output.
Theoutput unit 240 is configured to output the video according to the calculated width x and height y of the effective area when the video is output.
Optionally, after the calculatingunit 230 calculates the width x and the height y of the effective area when the video is output, theoutput unit 240 is specifically configured to stretch or scale the width w and the height h of the current effective area of the video according to x and y, respectively, so that the video is played on the screen in the maximum visible range according to the original scale.
It should be noted that, similar to the method embodiment, the playing parameters may also include only the original aspect ratio of the video
The width w and height h of the currently active area of the video may not necessarily be required.
With the video processing apparatus provided in the second embodiment of the present invention, since the video may be a video after compression transcoding, the aspect ratio of the current effective area of the video may not be the aspect ratio of the video when recording, by obtaining the original aspect ratio of the video, and using the original aspect ratio of the video and the width and height of the screen of the user equipment, the width and height of the effective area that should be output can be calculated, and when playing is performed in the maximum range on the user equipment, the width and height of the effective area that should be output are calculated, and then the video is played according to the calculated width and height of the effective area when the video is output. The device can automatically adapt to the screen size of the user equipment without manual setting of a user, and ensures that the video is played in the original proportion and in the maximum visual range.
Fig. 5 is a schematic structural diagram of a user equipment according to a third embodiment of the present invention. The user equipment includes a transceiver 310, amemory 320, and a processor 330 connected to the transceiver 310 and thememory 320, respectively. Of course, the user equipment may further include general components such as an antenna, a baseband processing component, a medium radio frequency processing component, and an input/output device, and the embodiment of the present invention is not limited in any way here.
Wherein thememory 320 stores a set of program codes therein, and the processor 330 is configured to call the program codes stored in thememory 320 for performing the following operations:
acquiring playing parameters of a video, wherein the playing parameters comprise: the original aspect ratio of the video;
acquiring the width and height of a screen of user equipment;
calculating the width and height of an effective area when the video is output according to the original aspect ratio of the video and the width and height of the screen of the user equipment;
and outputting the video according to the calculated width and height of the effective area when the video is output.
Further, the playing parameters further include: the width and height of the current effective area of the video; the outputting the video according to the calculated width and height of the effective area when the video is output specifically comprises: and stretching or scaling the width and the height of the current effective area of the video so as to output the video with the calculated width and the calculated height of the effective area when the video is output.
Further, the acquiring of the playing parameters of the video specifically includes:
reading a data block included in the video; acquiring the playing parameters from the data blocks; wherein the data block stores the playing parameter.
Further, the acquiring of the playing parameters of the video specifically includes:
reading a file suffix name of the video; acquiring the playing parameters from the file suffix name; wherein the file suffix name contains the playing parameter.
Further, the acquiring of the playing parameters of the video specifically includes:
reading a frame of the video; acquiring the playing parameters through preset colors in the frame of the video or the width and the height of the preset colors and color areas; wherein, the color is used for representing the original aspect ratio of the video, and the width and height of the color area are used for representing the width and height of the current effective area of the video.
Further, the calculating the width and height of the effective area when the video is output specifically includes:
when in use
Time, calculate
y = b; when in use
When x = a, y = b is calculated; when in use
When, x = a is calculated,
with the user equipment provided by the third embodiment of the present invention, since the video may be a video after compression transcoding, the aspect ratio of the current effective area of the video may not be the aspect ratio of the video when recording, by obtaining the original aspect ratio of the video, and using the original aspect ratio of the video and the width and height of the screen of the user equipment, the original ratio of the video can be calculated, and in the case of playing in the maximum range on the user equipment, the width and height of the effective area that should be output are calculated, and then the video is played according to the calculated width and height of the effective area when the video is output. By utilizing the user equipment, the user does not need to manually set, the video can automatically adapt to the screen size of the user equipment, and the video is ensured to be played in the original proportion and in the maximum visual range.
Those of skill would further appreciate that the various illustrative components and algorithm steps described in connection with the embodiments disclosed herein may be implemented as electronic hardware, computer software, or combinations of both, and that the various illustrative components and steps have been described above generally in terms of their functionality in order to clearly illustrate this interchangeability of hardware and software. Whether such functionality is implemented as hardware or software depends upon the particular application and design constraints imposed on the implementation. Skilled artisans may implement the described functionality in varying ways for each particular application, but such implementation decisions should not be interpreted as causing a departure from the scope of the present invention.
The steps of a method or algorithm described in connection with the embodiments disclosed herein may be embodied in hardware, a software module executed by a processor, or a combination of the two. A software module may reside in Random Access Memory (RAM), memory, Read Only Memory (ROM), electrically programmable ROM, electrically erasable programmable ROM, registers, hard disk, a removable disk, a CD-ROM, or any other form of storage medium known in the art.
The above-mentioned embodiments are intended to illustrate the objects, technical solutions and advantages of the present invention in further detail, and it should be understood that the above-mentioned embodiments are merely exemplary embodiments of the present invention, and are not intended to limit the scope of the present invention, and any modifications, equivalent substitutions, improvements and the like made within the spirit and principle of the present invention should be included in the scope of the present invention.