Video compression method and device, processing equipment, program product and medium
By acquiring video requirement information and utilizing canvas drawing capabilities, combined with a neural network model for target recognition and cropping, the problem of low video compression efficiency on web pages was solved, achieving efficient video stream uploading and quality assurance.
Patent Information
- Application Number
- CN202511095019.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-08-06
- Publication Date
- 2025-11-07
AI Technical Summary
Existing technologies for web-based video compression are inefficient and fail to guarantee the quality of the compressed video, resulting in user interface response delays and video distortion, making it difficult to meet the needs of more video usage scenarios.
By acquiring video requirement information, determining the target size, and using the canvas drawing function to compress the source video into a target video that meets the target size, and combining a neural network model for target recognition and cropping, progressive video compression is achieved.
While ensuring the quality of the compressed image, it effectively reduces the resource consumption of video stream transmission on the web, increases the upload speed of the video stream, reduces transmission time, and improves the user experience.
Smart Images

Figure CN120916007A_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of artificial intelligence, in particular to a video compression method and device, processing equipment, program product and medium. BACKGROUND
[0002] With the development of the fifth generation mobile communication technology (5G) and artificial intelligence (AI) technology, the demand for uploading videos through mobile web pages has surged (such as face recognition verification requiring recording dynamic videos and transmitting them to the server). The sizes of the videos uploaded by users vary (from several tens of KB to several tens of MB), and the larger the video, the longer the time it takes to transmit to the server, which seriously affects the user experience.
[0003] In the existing scheme, video compression is achieved by splitting the video into picture frames, compressing each frame of the picture frame, and then recombining the frames into a complete video to shorten the video upload time. However, the processing speed and efficiency of splitting the video and compressing each frame in this scheme are low, resulting in a delay in the response of the user interface, and the user may lose patience and give up the business, resulting in poor user experience. In addition, due to the complexity of the video compression process, there is a risk of frame loss, which may cause video distortion and make it difficult to meet the needs of more video use scenarios. SUMMARY
[0004] The purpose of the present application is to provide a video compression method, device, processing equipment, program product and medium, which solves the problem of low video compression efficiency and difficulty in ensuring the quality of the compressed picture in the prior art.
[0005] One embodiment of the present application provides a video compression method, which comprises:
[0006] Obtaining a source video and video requirement information corresponding to the source video, wherein the video requirement information includes a video size parameter;
[0007] According to the video requirement information, determining a target size corresponding to the source video;
[0008] Based on the drawing function of canvas, the source video is compressed into a target video that meets the target size.
[0009] Optionally, the step of determining the target size corresponding to the source video according to the video requirement information comprises:
[0010] According to the video size parameter, determining the maximum value of the video size;
[0011] In a case where the video requirement information further comprises a video size parameter, if a value of the video size parameter is less than or equal to the maximum value, the value of the video size parameter is taken as the target size, and if the value of the video size parameter is greater than the maximum value, the maximum value is taken as the target size.
[0012] In a case where the video requirement information does not comprise the video size parameter, if a screen resolution is less than or equal to the maximum value, the screen resolution is taken as the target size, and if the screen resolution is greater than the maximum value, the maximum value is taken as the target size, wherein the screen resolution is a screen resolution of an electronic device that uploads the source video.
[0013] Optionally, the canvas-based drawing function compresses the source video into a target video that conforms to the target size, and the method comprises:
[0014] creating a canvas according to the target size;
[0015] determining a drawing parameter corresponding to the source video according to the target size;
[0016] drawing the source video on the canvas according to the drawing parameter to obtain the target video.
[0017] Optionally, the determining the drawing parameter corresponding to the source video according to the target size comprises:
[0018] obtaining a width and a height of the source video;
[0019] determining the drawing parameter corresponding to the source video according to the width and the height of the source video and the target size.
[0020] Optionally, the determining the drawing parameter corresponding to the source video according to the target size comprises:
[0021] inputting the source video into a neural network model to obtain a bounding box;
[0022] obtaining coordinate information of the bounding box in the source video;
[0023] determining the drawing parameter corresponding to the source video according to the target size and the coordinate information of the bounding box.
[0024] Optionally, before the determining the target size corresponding to the source video according to the video requirement information, the method further comprises:
[0025] According to influence factor information corresponding to the source video, the video requirement information is corrected, and the influence factor information includes service scenario information and / or network state information.
[0026] An embodiment of the present application also provides a video compression device, which comprises:
[0027] An acquisition module is configured to acquire a source video and video requirement information corresponding to the source video, wherein the video requirement information comprises a video size parameter.
[0028] A processing module is configured to determine a target size corresponding to the source video according to the video requirement information.
[0029] A compression module is configured to compress the source video into a target video conforming to the target size based on a drawing function of a canvas.
[0030] Optionally, the processing module comprises:
[0031] A first processing unit is configured to determine a maximum value of a video size according to the video size parameter.
[0032] A second processing unit is configured to, if the video requirement information further comprises a video size parameter, take a value of the video size parameter as the target size if the value of the video size parameter is less than or equal to the maximum value, or take the maximum value as the target size if the value of the video size parameter is greater than the maximum value.
[0033] A third processing unit is configured to, if the video requirement information does not comprise the video size parameter, take a screen resolution as the target size if the screen resolution is less than or equal to the maximum value, or take the maximum value as the target size if the screen resolution is greater than the maximum value, wherein the screen resolution is a screen resolution of an electronic device uploading the source video.
[0034] Optionally, the compression module comprises:
[0035] A canvas creation unit is configured to create a canvas according to the target size.
[0036] A parameter determination unit is configured to determine a drawing parameter corresponding to the source video according to the target size.
[0037] A video drawing unit is configured to draw the source video on the canvas according to the drawing parameter, and obtain the target video.
[0038] Optionally, the parameter determination unit comprises:
[0039] A size obtaining sub-unit is configured to obtain the width and height of the source video.
[0040] A first determining sub-unit is configured to determine the drawing parameter corresponding to the source video according to the width and height of the source video and the target size.
[0041] Optionally, the parameter determining unit comprises:
[0042] A target identifying sub-unit is configured to input the source video into a neural network model to perform target identification and obtain a bounding box.
[0043] A coordinate obtaining sub-unit is configured to obtain coordinate information of the bounding box in the source video.
[0044] A second determining sub-unit is configured to determine the drawing parameter corresponding to the source video according to the target size and the coordinate information of the bounding box.
[0045] Optionally, the device further comprises:
[0046] A correction module is configured to correct the video requirement information according to the influence factor information corresponding to the source video, wherein the influence factor information comprises business scenario information and / or network state information.
[0047] An embodiment of the present application further provides a processing device, comprising a processor, a memory and a program stored in the memory and executable on the processor, wherein the program is executed by the processor to implement the video compression method according to any one of the above.
[0048] An embodiment of the present application further provides a computer program product, comprising computer instructions, wherein the computer instructions are executed by a processor to implement the steps of the video compression method according to any one of the above.
[0049] An embodiment of the present application further provides a readable storage medium, wherein the readable storage medium stores a program, and the program is executed by a processor to implement the steps of the video compression method according to any one of the above.
[0050] The above technical solutions of the present application have at least one of the following beneficial effects:
[0051] In the video compression method of the embodiment of the present application, after the source video and the video requirement information are obtained, the target size can be determined according to the video requirement information, and finally the source video is compressed into a target video conforming to the target size based on the drawing function of the canvas. Since the determination of the target size takes into account the video requirement information, the picture quality after compression can be ensured while the compression of the source video is realized, the resource consumption of the web page end for transmitting the video stream can be effectively reduced, the uploading speed of the video stream is improved, and the transmission time is reduced. BRIEF DESCRIPTION OF DRAWINGS
[0052] Figure 1 A flowchart of the video compression method of one embodiment of the present application is shown.
[0053] Figure 2 A flowchart of the video compression method of another embodiment of the present application is shown.
[0054] Figure 3 A working schematic diagram of the video compression system of one embodiment of the present application is shown.
[0055] Figure 4 A schematic diagram of the cropped video in one embodiment of the present application is shown.
[0056] Figure 5 A schematic diagram of the cropped video in another embodiment of the present application is shown.
[0057] Figure 6 A structural schematic diagram of the video compression device of one embodiment of the present application is shown. DETAILED DESCRIPTION
[0058] The terms "first", "second", and the like in the specification and claims of the present application are used to distinguish similar objects, and are not used to describe a specific order or sequence. It should be understood that the terms used in this way can be interchanged under appropriate circumstances, so that the embodiments of the present application can be implemented in an order other than that illustrated or described herein, and the objects distinguished by "first", "second" are generally a class, not limited to the number of objects, for example, the first object can be one or more.
[0059] In various embodiments of the present application, it should be understood that the size of the serial number of the following processes does not mean the order of execution, and the execution order of the processes should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.
[0060] In the embodiments of the present application, the term "and / or" describes the association relationship of the associated objects, which means that there can be three relationships, for example, A and / or B can mean that A exists alone, A and B exist together, and B exists alone. The character " / " generally represents that the associated objects before and after it are in an "or" relationship.
[0061] It should be understood that "B corresponding to A" means that B is associated with A, and B can be determined according to A. However, it should also be understood that determining B according to A does not mean that B is determined only according to A, but B can also be determined according to A and / or other information.
[0062] The term "multiple" in the embodiments of the present application refers to two or more, and other quantifiers are similar.
[0063] In addition, the terms "system" and "network" are often used interchangeably in this paper.
[0064] The technical solutions in the embodiments of the present application will be described clearly and completely in the following with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative labor are within the scope of protection of the present application.
[0065] To solve the problem of low video compression efficiency and difficulty in ensuring the quality of compressed pictures in the prior art, a video compression method is provided.
[0066] As shown in Figure 1 The video compression method described in one embodiment of the present application includes:
[0067] Step 101, obtaining a source video and video requirement information corresponding to the source video, the video requirement information including video size parameters.
[0068] Here, the video requirement information can include video size requirement information and / or video size requirement information. The video size requirement information can specifically include video size parameters and their values, which are used to limit the maximum value of the storage space occupied by the target video obtained by compressing the source video (also known as the target video stream, also known as the video stream to be uploaded); the video size requirement information can specifically include video size parameters and their values, which are used to limit the video frame size of the target video. For example, in an example, the video uploaded to the server has video size requirement information, in which the video size parameter limits the width and height of the video to 480*640px, and the video size parameter limits the video size of the video to 10m.
[0069] In this step 101, as Figure 2As shown, the source video requested by the user (i.e., the target video stream that needs to be compressed) and the video requirement information configured in the upload request can be obtained in response to a video upload request of the user. The video upload request is triggered by the user clicking a preset request button on the webpage. For example, in the business scenario of live face detection, the video upload request is triggered by the user clicking a button for starting verification.
[0070] Specifically, the source video can be obtained in step 101 in the following ways:
[0071] If the browser supports mediaDevices.getUserMedia, the source video can be obtained through the browser. If the browser does not support mediaDevices.getUserMedia, the source video can be obtained through an input tag, for example: <input type="file"accept="video *"capture="user"> A video file of a type of file can be obtained.
[0072] It should be noted that, as shown in Figures 2-3 After the source video (i.e., the target video stream) is obtained, the source video can be set as the video source of a video player on the webpage, so that the video player plays the target video stream. In this way, the user can see the uploaded video during the waiting process, which can guide the visual focus of the user and reduce the anxiety and discomfort caused by waiting.
[0073] In step 102, the target size corresponding to the source video is determined according to the video requirement information.
[0074] In step 103, the source video is compressed to a target video conforming to the target size based on the drawing function of the canvas.
[0075] In this embodiment, after the source video and the video requirement information are obtained, the target size is determined according to the video requirement information, and finally the source video is compressed to a target video conforming to the target size based on the drawing function of the canvas. Since the determination of the target size takes into account the video requirement information, the picture quality of the compressed video can meet the business requirements while the source video is compressed, which can effectively reduce the resource consumption of the webpage for transmitting the video stream, improve the speed of uploading the video stream, and reduce the transmission time.
[0076] In some embodiments, before the target size corresponding to the source video is determined according to the video requirement information, the method further includes: correcting the video requirement information according to influence factor information corresponding to the source video, wherein the influence factor information includes business scenario information and / or network state information.
[0077] Here, the business scenario information can be a level or type of the business scenario, for example, in a high-security level face verification business scenario, higher video requirement information is required, for example, when the video requirement information is modified, the value of the video size parameter in this scenario can be modified to a larger value; the network status information can include information that can reflect the current network status, for example, transmission rate, signal strength, etc. If the current network status is not good, when the video requirement information is modified, the video requirement can be appropriately reduced, for example, the value of the video size parameter in this scenario is modified to a smaller value, so as to prioritize transmission speed and success rate.
[0078] It should be noted that the above video requirement information can be information configured by a business party (such as a manager corresponding to a face verification business), for example, an input box for inputting video requirement information by relevant personnel (such as a manager) can be configured on a webpage, and the relevant personnel can configure the related requirements of the user uploaded source video based on the demand.
[0079] The video compression method provided by the embodiments of the present application can be applied to video collection in business scenarios such as artificial intelligence and live face detection (but not limited to this scenario), especially in the case where a mobile device does not support Web Real-Time Communication (WebRTC). WebRTC is a real-time communication technology that allows web browsers to conduct real-time voice, video conversations, and other types of data transmission without the need to install additional plug-ins or applications. The main process of live face detection includes: the user records a video of the specified action according to the identity verification requirements (for example, reading a random number or doing a set of random actions such as shaking head, opening mouth, etc.) prompted by the system on the webpage, and the front-end collects the video data recorded by the user and uploads it to the server, so that the server can perform security authentication (including identity security verification and environment security verification, etc.) on the user who is handling the business based on the video.
[0080] In some embodiments, the determining the target size corresponding to the source video according to the video requirement information comprises:
[0081] (I) determining a maximum value of the video size according to the video size parameter.
[0082] Here, the reference video size (that is, the maximum value of the video size) can be calculated based on the value of the video size parameter. It should be noted that the reference video size is the maximum value of the video size (that is, the maximum value of the video frame size) inferred from the video size requirement. In other words, if the video frame size is greater than the reference video size, the video size of the final target video will exceed the video size requirement.
[0083] It can be understood that the video size parameter in the video requirement information can also be corrected according to the influence factor information (such as the business scene information and / or the network state information) corresponding to the source video, and then the maximum value of the video size is determined by using the corrected video size parameter, so that the maximum value of the video size has more reference value in the process of determining the target size later.
[0084] (II) If the value of the video size parameter is less than or equal to the maximum value, the value of the video size parameter is taken as the target size, and if the value of the video size parameter is greater than the maximum value, the maximum value is taken as the target size.
[0085] That is, the smaller one of the value of the video size parameter and the reference video size (i.e., the maximum value) is determined as the target size. For example, the video size parameter in the video requirement information limits the video size to 10m, so the maximum value of the video size is determined to be 520*740 (i.e., the video size will be greater than 10m when the video exceeds this value), and if the width and height limited by the video size parameter in the video requirement information are 480*640, the final target size can be determined to be 480*640.
[0086] (III) If the screen resolution is less than or equal to the maximum value, the screen resolution is taken as the target size, and if the screen resolution is greater than the maximum value, the maximum value is taken as the target size, wherein the screen resolution is the screen resolution of the electronic device uploading the source video.
[0087] That is, the smaller one of the screen resolution and the reference video size (i.e., the maximum value) is determined as the target size. For example, the screen resolution of some iOS system mobile phones is 1170*2532, and the screen resolution of some mobile phones is 1179*2532. Therefore, the target size can be determined in combination with the screen resolution of the actual electronic device (such as a mobile phone) uploading the video, so as to flexibly limit the size of the target video, reduce the video size, and ensure that the video clarity is considered while the video is compressed.
[0088] In this embodiment, the target size is determined based on the configured video requirement information, network state information, and screen resolution and other factors, so that the video quality, compression space requirement, and video size requirement can be considered, and the flexibility of compression is improved.
[0089] In some embodiments, step 103, the canvas-based drawing function compresses the source video into a target video conforming to the target size, including:
[0090] Step 1031, create a canvas according to the target size.
[0091] Here, after the canvas is configured according to the target size, the target canvas (that is, the canvas created in step 1031) is obtained.
[0092] Step 1032, determine the drawing parameter corresponding to the source video according to the target size.
[0093] Step 1033, draw the source video on the canvas according to the drawing parameter, and obtain the target video.
[0094] Here, the video frames of the source video (that is, the video frames of the source video) played by the video player from the beginning to the end can be drawn to the target canvas through the MediaRecorder object. The target coordinates of the target point in each video frame are aligned with the reference coordinates of the reference point of the target canvas, so that each video frame is drawn to the target canvas.
[0095] It should be noted that the video stream drawn to the target canvas can also be obtained through the MediaRecorder object, so as to obtain the video file (that is, the target video) processed by video compression.
[0096] In the embodiments of the present application, the source video to be uploaded by the user on the web page can be played through the player, and the played video stream can be continuously drawn to the canvas of the target size. In this way, by obtaining the picture drawn to the canvas, the video stream with the video frame as the target size (that is, the target video) can be obtained, thereby achieving the purpose of gradually compressing the video, maximizing the compression of the video size in the shortest time, and improving the video compression efficiency.
[0097] It should be noted that in some optional embodiments, the drawing parameter corresponding to the source video can be determined according to the following manner:
[0098] Manner one:
[0099] In some embodiments, the drawing parameter corresponding to the source video is determined according to the target size, including: obtaining the width and height of the source video; determining the drawing parameter corresponding to the source video according to the width and height of the source video and the target size.
[0100] It should be noted that when the source video is drawn on the target canvas, the source video needs to be cropped in the drawing process due to the different sizes of the two, and the API: drawImage(image, sx, sy, sw, sh, dx, dy, dw, dh) of the canvas can be used to crop the source video, and the part to be cut is positioned on the target canvas through a series of coordinate calculations, and then the size is cropped in the drawing process. Therefore, the drawing parameters described above refer to the parameters in the API: drawImage(image, sx, sy, sw, sh, dx, dy, dw, dh) of the canvas, such as sx, sy, sw, sh, dx, dy, dw and dh. Among them, image represents the source picture (i.e. source image) or the source video (i.e. source video); sx and sy represent the initial x-coordinate and y-coordinate of the source picture or the source video on the canvas; sw and sh represent the width and height of the source picture or the source video that needs to be placed on the target canvas (destination canvas); dx and dy represent the x-coordinate and y-coordinate of the beginning of the target canvas; dw and dh represent the width and height of the target canvas.
[0101] Specifically, the videoWidth (i.e. the width of the source video) and the videoHeight (i.e. the height of the source video) of the source video can be obtained, and the maximum width and height that can be cropped in proportion can be obtained. In the case of fixed target width and height, dx = 0, dy = 0, dw = 480, and dh = 640 can be obtained. Next, the coordinates and width and height of the crop, i.e. sx, sy, sw and sh, are determined.
[0102] In the case where the targetWidth (i.e. the width of the target canvas) is less than or equal to the videoWidth, the equal width ratio dw1 and the equal height ratio dh1 of the target video (consistent with the size of the target canvas) and the source video are obtained, which are represented as: dw1 = targetWidth / videoWidth; dh1 = targetHeight / videoHeight.
[0103] Among them, as shown in Figure 4 In the case where dw1 is greater than dh1, sx = 0, sy = (videoHeight-targetHeight / dw) / 2, sw = videoWidth, and sh = videoHeight / dw. As shown in Figure 5As shown, in the case where dw is less than dh, sx = (videoWidth-targetWidth / dh) / 2, sy = 0, sw = videoWidth / dh, and sh = videoHeight.
[0104] In this embodiment, during video compression (i.e., video rendering), a cropping scheme (including rendering parameters) is obtained based on the target size, then the pictures of the source video are cropped and rendered in the target canvas, the selected region is cropped in proportion to the target size and the source video size, and then the target canvas is compressed in proportion, so that the video picture is not distorted due to size changes, thereby ensuring the completeness and clarity of the video picture to the maximum extent while ensuring the size of the compressed video, and ensuring the picture quality of the target video obtained through compression processing.
[0105] Method two:
[0106] In some embodiments, the determining the rendering parameters corresponding to the source video according to the target size comprises:
[0107] (I) inputting the source video into a neural network model for target recognition to obtain a bounding box.
[0108] Here, the target recognition can be face recognition, and the obtained bounding box can be a face recognition box (in subsequent embodiments, the face recognition box is exemplified), or can be a recognition box of other target objects. Specifically, the coordinates of the face recognition box in the source video picture can be identified using a neural network model.
[0109] (II) obtaining coordinate information of the bounding box in the source video.
[0110] Here, the face recognition box can be obtained through face-api.js.
[0111] (III) determining the rendering parameters corresponding to the source video according to the target size and the coordinate information of the bounding box.
[0112] Specifically, the face recognition frame is enlarged according to a target ratio, and a target drawing frame is obtained based on the face recognition frame as the center, wherein the target ratio includes a target width ratio and a target length ratio, the target width ratio is a ratio between a width in the target size and a width of the face recognition frame, and the target length ratio is a ratio between a length in the target size and a length of the face recognition frame. In this way, the face recognition frame is enlarged according to the target ratio to obtain a drawing frame conforming to the target size, which can ensure that the face is the center position of the drawing picture and improve the integrity of the main object of the picture. Then, the key point coordinates of the target drawing frame are obtained, and the video frame picture is cropped and drawn according to the cropping method in mode one. The key points can include preset points of the target drawing frame.
[0113] In this embodiment, the neural network model is used to identify the picture main body region in the source video, so that the video picture can be cropped based on the picture main body region, thereby ensuring the integrity of the target object in the video stream picture and ensuring that the target object in the cropped video picture is located in the main position, thereby ensuring the compression quality of the video content.
[0114] It should be noted that in some optional embodiments, face detection can be started during the process of recording the video stream by the user. If the coordinate position of the face recognition frame is too close to the edge frame position or the cropping coordinates, the user can be reminded on the recording interface to ensure that the position of the face recognition frame is in the middle position of the screen, thereby ensuring the integrity of the face position in the source video.
[0115] It should be further noted that in order to ensure the integrity of the target object (such as a face) to be verified in the source video in the picture frame, the target coordinates can be calculated according to the main body region, which can be realized by introducing the face-api.js library. The face-api.js library is based on the machine learning library TensorFlow.js to create, train and use a neural network model in the browser, and the neural network model is used for object recognition. In this scenario, the neural network model is used to identify a face to obtain the coordinates of the face recognition frame in the video stream picture.
[0116] It should be noted that with the development of the network, more and more scenarios require users to upload videos to the server through the webpage for the next step of video processing, especially in the financial field. Based on real-time video stream, biological features and behavior features are identified to realize security verification, which can maximize the security of business execution.
[0117] Compared with the prior art of processing a video frame and then recombining, the above-mentioned video compression method can combine the plug-in functions such as a player, a canvas and a MediaRecorder object which are easy to realize on a webpage, realize continuous and progressive video compression, and does not need to be recombined, thereby effectively improving the video compression processing speed, and can be applied to a scene of video stream interaction between an arbitrary webpage product and a server, especially in security verification, can improve the business execution efficiency of the webpage product, effectively reduces the user waiting time, helps to realize the security verification process of nearly no sense, and improves the user experience.
[0118] The video compression method can play the source video to be uploaded by a user from a webpage through a player, continuously draw the played video stream into a canvas of a target size, and then obtain a target video by obtaining a picture on the canvas, so as to realize the purpose of progressive compression of the target video stream (i.e. the source video) based on the canvas. Therefore, the video compression method can realize the compression of the video stream quickly while ensuring the video quality, thereby reducing the resource consumption of the video stream transmission between the front end and the back end, effectively improving the video stream uploading speed, reducing the video transmission time, and improving the user experience.
[0119] As shown in Figure 6 One embodiment of the application further provides a video compression device, which comprises:
[0120] The acquisition module 610 is configured to acquire a source video and video requirement information corresponding to the source video, wherein the video requirement information comprises a video size parameter.
[0121] The processing module 620 is configured to determine a target size corresponding to the source video according to the video requirement information.
[0122] The compression module 630 is configured to compress the source video into a target video conforming to the target size based on the drawing function of the canvas.
[0123] In this embodiment, after the source video and the video requirement information are acquired, the target size is determined according to the video requirement information, and finally the source video is compressed into a target video conforming to the target size based on the drawing function of the canvas. Since the determination of the target size takes into account the video requirement information, the picture quality after compression can be ensured while the source video is compressed, the resource consumption of the video stream transmission on the webpage can be effectively reduced, the video stream uploading speed is improved, and the transmission time is reduced.
[0124] Optionally, the processing module 620 comprises:
[0125] The first processing unit is configured to determine a maximum value of a video size according to the video size parameter;
[0126] The second processing unit is configured to, if the video requirement information further comprises a video size parameter, and if a value of the video size parameter is less than or equal to the maximum value, take the value of the video size parameter as the target size, or if the value of the video size parameter is greater than the maximum value, take the maximum value as the target size.
[0127] The third processing unit is configured to, if the video requirement information does not comprise the video size parameter, and if a screen resolution is less than or equal to the maximum value, take the screen resolution as the target size, or if the screen resolution is greater than the maximum value, take the maximum value as the target size, wherein the screen resolution is a screen resolution of an electronic device that uploads the source video.
[0128] Optionally, the compression module 630 comprises:
[0129] The canvas creation unit is configured to create a canvas according to the target size.
[0130] The parameter determination unit is configured to determine a drawing parameter corresponding to the source video according to the target size.
[0131] The video drawing unit is configured to draw the source video on the canvas according to the drawing parameter, to obtain the target video.
[0132] Optionally, the parameter determination unit comprises:
[0133] The size acquisition sub-unit is configured to acquire a width and a height of the source video.
[0134] The first determination sub-unit is configured to determine a drawing parameter corresponding to the source video according to the width and the height of the source video and the target size.
[0135] Optionally, the parameter determination unit comprises:
[0136] The target identification sub-unit is configured to input the source video into a neural network model to perform target identification, to obtain a bounding box.
[0137] The coordinate acquisition sub-unit is configured to acquire coordinate information of the bounding box in the source video.
[0138] The second determination sub-unit is configured to determine a drawing parameter corresponding to the source video according to the target size and the coordinate information of the bounding box.
[0139] Optionally, the apparatus further comprises:
[0140] A correction module is configured to correct the video requirement information according to influence factor information corresponding to the source video, wherein the influence factor information includes service scenario information and / or network state information.
[0141] The apparatus provided by the embodiments of the present application can execute the method embodiments described above, and has similar implementation principles and technical effects. Therefore, the apparatus will not be described here again.
[0142] It should be noted that the division of units in the embodiments of the present application is illustrative, and is only a logical function division. In actual implementation, another division manner can be used. In addition, each functional unit in each embodiment of the present application can be integrated in one processing unit, or each unit can exist physically, or two or more units can be integrated in one unit. The integrated unit can be realized in the form of hardware or in the form of a software functional unit.
[0143] When the integrated unit is realized in the form of a software functional unit and sold or used as an independent product, the integrated unit can be stored in a processor-readable storage medium. Based on this understanding, the technical solutions of the present application, essentially or the part that contributes to the prior art, or all or part of the technical solutions can be embodied in the form of a software product. The computer software product is stored in a storage medium, and includes several instructions for causing a computer device (which can be a personal computer, a server, or a network device, etc.) or a processor to execute all or part of the steps of the methods described in the various embodiments of the present application. The foregoing storage medium includes various media that can store program codes, such as a U disk, a mobile hard disk, a read-only memory (ROM), a random access memory (RAM), a magnetic disk, or an optical disk.
[0144] One of the embodiments of the present application further provides a processing device, which includes a processor, a memory, and a program stored in the memory and executable on the processor. When the program is executed by the processor, the video compression method according to any one of the above embodiments is implemented.
[0145] The program executable on the processor of the processing device executes the specific implementation of the video compression method, and the detailed description of the video compression method can be referred to, and will not be described here again.
[0146] In addition, the embodiment of the present application further provides a readable storage medium, which stores a program, and the program is executed by a processor to realize the processes of the above-mentioned video compression method embodiment and achieve the same technical effects. To avoid repetition, details are not described herein. The readable storage medium can be any available medium or data storage device accessible by the processor, including but not limited to a magnetic memory (such as a floppy disk, a hard disk, a magnetic tape, a magneto-optical disk (MO), etc.), an optical memory (such as a CD, a DVD, a BD, a HVD, etc.), and a semiconductor memory (such as a ROM, an EPROM, an EEPROM, a non-volatile memory (NAND FLASH), a solid state disk (SSD), etc.), etc.
[0147] In particular, the readable storage medium is applied to the above-mentioned execution step of the video compression method, and details are not described herein.
[0148] The embodiment of the present application further provides a computer program product, which includes computer instructions, and the computer instructions are executed by a processor to realize the processes of the above-mentioned video compression method embodiment and achieve the same technical effects. To avoid repetition, details are not described herein.
[0149] Optionally, the embodiment of the present application can adopt the form of a computer program product implemented on one or more computer usable storage media (including but not limited to a disk memory, a CD-ROM, an optical memory, etc.) containing computer usable program codes.
[0150] The computer program product described in the embodiment of the present application includes computer instructions, and the computer instructions are executed by a processor to realize the processes of the above-mentioned method embodiment and achieve the same technical effects. To avoid repetition, details are not described herein.
[0151] It should be noted that in this document, the term "comprising" or "including" or any other variant thereof is intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements not only includes those elements, but also includes other elements not explicitly listed or inherent to such a process, method, article or device. Without more limitations, the element defined by the statement "including a" does not exclude the presence of another identical element in the process, method, article or device including the element.
[0152] It should be noted that many functional components described in this specification are referred to as modules / sub-modules in order to more particularly emphasize the independence of their implementation.
[0153] In the embodiments of the present application, the modules / sub-modules can be implemented in software, so as to be executed by various types of processors. For example, an identified executable code module can include one or more physical or logical blocks of computer instructions. For instance, it can be structured as an object, a procedure, or a function. However, the executable code of the identified module need not be physically located together, but can include different instructions stored in different locations which, when joined logically together, comprise the module and achieve the stated purpose for the module.
[0154] In fact, the executable code modules can be a single instruction, or many instructions, and even can be spread across multiple different code segments, across different programs, and across multiple memory devices. Similarly, operational data can be identified within the modules, and can be implemented in any suitable form and organized within any suitable type of data structure. The operational data can be collected as a single data set, or can be distributed over different locations including over different storage devices, and can exist at least in part only as electronic signals on a system or network.
[0155] When the modules can be implemented by software, the modules implemented by software can be built into corresponding hardware circuitry by those skilled in the art without considering the cost, under the current level of hardware technology. The hardware circuitry includes conventional very large scale integrated (VLSI) circuit or gate array, and existing semiconductors or other discrete elements such as logic chips, transistors, etc. The modules can also be implemented by programmable hardware devices, such as field programmable gate array, programmable array logic, programmable logic device, etc.
[0156] The above is the preferred embodiment of the present application. It should be noted that for those skilled in the art, without departing from the principles of the present application, a number of improvements and refinements can be made, which should also be considered as the protection scope of the present application.
Claims
1. A method of video compression, characterized by, The method comprises: obtaining a source video and video requirement information corresponding to the source video, the video requirement information comprising a video size parameter; determining a target size corresponding to the source video according to the video requirement information; compressing the source video into a target video conforming to the target size based on a canvas drawing function.
2. The video compression method of claim 1, wherein, The determining of the target size corresponding to the source video according to the video requirement information comprises: determining a maximum value of video size according to the video size parameter; if the video size parameter value is less than or equal to the maximum value, taking the video size parameter value as the target size, and if the video size parameter value is greater than the maximum value, taking the maximum value as the target size, in the case that the video requirement information further comprises a video size parameter; if the screen resolution is less than or equal to the maximum value, taking the screen resolution as the target size, and if the screen resolution is greater than the maximum value, taking the maximum value as the target size, in the case that the video requirement information does not comprise the video size parameter, wherein the screen resolution is the screen resolution of an electronic device uploading the source video.
3. The video compression method of claim 1, wherein, The compressing of the source video into the target video conforming to the target size based on the canvas drawing function comprises: creating a canvas according to the target size; determining a drawing parameter corresponding to the source video according to the target size; drawing the source video on the canvas according to the drawing parameter to obtain the target video.
4. The video compression method of claim 3, wherein, The determining of the drawing parameter corresponding to the source video according to the target size comprises: obtaining the width and height of the source video; determining the drawing parameter corresponding to the source video according to the width and height of the source video and the target size.
5. The video compression method of claim 3, wherein, The determining of the drawing parameter corresponding to the source video according to the target size comprises: inputting the source video into a neural network model for target recognition to obtain a bounding box; obtaining coordinate information of the bounding box in the source video; determining the drawing parameter corresponding to the source video according to the target size and the coordinate information of the bounding box.
6. The video compression method of claim 1, wherein, Before the determining of the target size corresponding to the source video according to the video requirement information, the method further comprises: modifying the video requirement information according to influence factor information corresponding to the source video, the influence factor information comprising business scenario information and / or network state information.
7. A video compression apparatus characterized by comprising: The device comprises: an obtaining module configured to obtain a source video and video requirement information corresponding to the source video, the video requirement information comprising a video size parameter; a processing module configured to determine a target size corresponding to the source video according to the video requirement information; a compression module configured to compress the source video into a target video conforming to the target size based on a canvas drawing function.
8. A processing device, characterized by The device comprises a processor, a memory, and a program stored in the memory and executable on the processor, and the program is executed by the processor to implement the video compression method according to any one of claims 1 to 6.
9. A computer program product, characterised in that, Computer program comprising computer instructions which, when executed by a processor, implement the steps of the method according to any one of claims 1 to 6.
10. A readable storage medium, characterized by, Program stored on a readable storage medium, which, when executed by a processor, implements the steps of the video compression method according to any one of claims 1 to 6.