Method, device and computer program product for dynamically adjusting optimal resolution of WebCam
By generating resolution constraint functions and progressive resolution adjustment mechanisms, the problem that existing WebCam is difficult to find universal optimal resolution is solved, and the optimal resolution adjustment is achieved to adapt to different devices and scenarios, improving video quality and user experience.
Patent Information
- Application Number
- CN202510012458.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2025-01-06
- Publication Date
- 2025-03-28
- Estimated Expiration
- 2045-01-06
AI Technical Summary
The existing WebCam video capture solutions have shortcomings in addressing device diversity, scenario complexity and user needs, and it is difficult to find a universal optimal resolution, resulting in limited user experience and application effects.
By obtaining the desired resolution and resolution adjustment parameters of the webcam, a resolution constraint function is generated, and the progressive resolution adjustment mechanism is used to optimize the resolution until the end condition of the optimization is met, the optimal resolution is obtained, and the video stream is adjusted based on this resolution.
It achieves rapid and accurate finding of the best resolution suitable for specific devices and scenarios, significantly improving video quality and user experience, and is suitable for large-scale applications and promotions.
Smart Images

Figure CN119421039B_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the technical field of data processing, and in particular relates to a method, a device and a computer program product for dynamically adjusting the optimal resolution of a WebCam. Background Art
[0002] Webcam is a new generation of camera that combines traditional cameras with network technology. Its images can be monitored through a standard web browser (such as Microsoft IE or Netscape). In addition to all the image capture functions of traditional cameras, it also has a built-in digital compression controller and a web-based operating system, so that the video data can be compressed and encrypted and sent to the terminal user through a local area network, the Internet or a wireless network. The remote user can use a standard web browser on a PC and access the web camera according to the IP address of the web camera to monitor the situation of the target site in real time. At the same time, the user can also edit and store image data in real time, and control the camera's pan / tilt and lens for all-round monitoring; therefore, webcams have been widely used.
[0003] At present, the existing WebCam video capture solutions have obvious deficiencies in dealing with device diversity, scene complexity and user demand diversity. Among them, its limitations are mainly reflected in the following aspects: (1) Different users have different requirements for video quality. Some users prefer high resolution, while others pay more attention to smoothness. In this case, it is necessary to configure the resolution separately according to different requirements, which has poor versatility and takes a lot of time when there are many devices; (2) High-end devices may support higher frame rates and resolutions, while low-end devices may not be able to run stably under high settings; (3) The drivers of different devices have different support for resolution and frame rates, resulting in As a result, it is difficult to achieve the desired settings on some devices (for example, the device can only support a resolution of 720, but if it is set to 1280, an error will occur. For example, if the resolution is set to 1280, then when transmitting a video with a resolution higher than this, it can only be played at a resolution of 1280, which reduces the video quality); therefore, the existing WebCam video resolution adopts static configuration and the configuration lacks intelligence, which makes it difficult to find a universal optimal setting, thereby affecting the user experience and application effect; therefore, based on the aforementioned shortcomings, how to provide a dynamic adjustment method for the optimal resolution of a WebCam has become a problem to be solved urgently. Summary of the invention
[0004] The purpose of the present invention is to provide a method, device and computer program product for dynamically adjusting the optimal resolution of a WebCam, so as to solve the problem that the prior art cannot find a universal optimal resolution for a webcam, thereby reducing the user experience and application effect.
[0005] In order to achieve the above object, the present invention adopts the following technical solutions:
[0006] In a first aspect, a method for dynamically adjusting an optimal resolution of a WebCam is provided, comprising:
[0007] Obtaining the expected resolution of the network camera, the video stream corresponding to the network camera, and resolution adjustment parameters, wherein the resolution adjustment parameters include a maximum resolution and a number of resolution reduction steps;
[0008] Based on the expected resolution, generating a resolution constraint function of the network camera, wherein the resolution constraint function is used to return a support response result of the network camera for the real-time resolution;
[0009] Taking the maximum resolution in the resolution adjustment parameter as the initial value, and using the resolution constraint function and the plurality of resolution decrement step lengths, performing resolution decrement optimization processing on the network camera until the optimal resolution is obtained when the optimization end condition is met, wherein the optimization end condition is that the support response result returned by the resolution constraint function is successful, and the current resolution decrement step length is less than or equal to the minimum resolution decrement step length among the plurality of resolution decrement step lengths;
[0010] Based on the optimal resolution, the video stream corresponding to the network camera is adjusted, and the adjusted video stream is output.
[0011] Based on the above disclosed content, the present invention first obtains the expected resolution and resolution adjustment parameters of the network camera; then, according to the expected resolution, a resolution constraint function is established, wherein the resolution constraint function is used to return the device's support response result for the real-time resolution; therefore, during the resolution adjustment process, by running the function, it can be determined whether the device supports the current real-time resolution; based on this, the present invention proposes a progressive resolution adjustment mechanism based on the resolution constraint function, and its process is: using the set maximum resolution as the initial value, and then using each resolution reduction step in the resolution adjustment parameter to perform a resolution reduction adjustment, and during the adjustment process, using the resolution constraint function to determine whether the device supports the adjusted resolution; in this way, when the optimization is optimized to meet the end condition, the optimal resolution can be obtained; finally, the video stream corresponding to the network camera can be adjusted based on the optimal resolution, so as to obtain the best video that meets the specific device and scene.
[0012] Through the above design, the present invention generates a resolution constraint function for returning the device's support response result for the real-time resolution through the expected resolution, and proposes a progressive resolution adjustment mechanism to optimize the resolution, that is, taking the set maximum resolution as the initial value, and then using each resolution decreasing step to perform a decreasing adjustment of the resolution, and in the adjustment process, based on the aforementioned resolution constraint function, to determine whether the device supports the adjusted resolution; in this way, the resolution is continuously adjusted in this way until it is adjusted to meet the optimization end condition, and the optimal resolution can be obtained; therefore, the present invention can quickly and accurately find the optimal resolution suitable for specific devices and scenarios, thereby significantly improving video quality and user experience, and therefore, is very suitable for large-scale application and promotion.
[0013] In a possible design, the plurality of resolution decreasing step sizes are arranged in descending order, wherein the maximum resolution in the resolution adjustment parameter is used as the initial value, and the resolution constraint function and the plurality of resolution decreasing step sizes are used to perform resolution decreasing optimization processing on the network camera, including:
[0014] For an i-th resolution decreasing step among the plurality of resolution decreasing step lengths, based on the i-th resolution decreasing step length and the resolution constraint function, performing a k-th resolution decreasing optimization process on the initial value, and obtaining a k-th initial optimal resolution after the k-th resolution decreasing optimization process, wherein the initial values of i and k are both 1;
[0015] Taking the i-th resolution decreasing step length as the current resolution decreasing step length, and judging whether the optimization end condition is satisfied based on the k-th initial optimal resolution and the current resolution decreasing step length;
[0016] If not, the kth initial optimal resolution and the ith resolution decreasing step are summed to obtain the target resolution after the summing process;
[0017] Based on the i-th resolution decreasing step length, determining a target step length from the plurality of resolution decreasing step lengths;
[0018] The initial value is updated to the target resolution, the i-th resolution decreasing step is updated to the target step, k is incremented by 1, and the initial value is subjected to the k-th resolution decreasing optimization process based on the i-th resolution decreasing step and the resolution constraint function again until the optimization end condition is met. The k-th initial optimal resolution when the optimization end condition is met is used as the optimal resolution.
[0019] In a possible design, based on the i-th resolution decreasing step and the resolution constraint function, performing a k-th resolution decreasing optimization process on the initial value includes:
[0020] Calculate the difference between the initial value and the i-th resolution decreasing step, and use the difference as the real-time resolution;
[0021] Based on the real-time resolution, running the resolution constraint function to obtain a support response result of the resolution constraint function;
[0022] Determining whether the support response result is successful;
[0023] If not, the initial value is updated to the real-time resolution, and the difference between the initial value and the i-th resolution reduction step is recalculated until the support response result is successful, and the real-time resolution corresponding to the support response result is successful is used as the k-th initial optimal resolution.
[0024] In one possible design, based on the i-th resolution decreasing step length, determining a target step length from the plurality of resolution decreasing step lengths includes:
[0025] Determine whether the i-th resolution decreasing step is greater than the n-th resolution decreasing step, where the initial value of n is i+1;
[0026] If not, n is incremented by 1, and whether the i-th resolution decreasing step is greater than the n-th resolution decreasing step is re-determined, until the i-th resolution decreasing step is greater than the n-th resolution decreasing step, the n-th resolution decreasing step is used as the target step.
[0027] In a possible design, obtaining the expected resolution of the network camera and the video stream corresponding to the network camera includes:
[0028] Get the API access function of the streaming device;
[0029] Run the API access function to obtain the expected resolution of the network camera and obtain a stream object containing a media stream;
[0030] According to the stream object, the video stream corresponding to the network camera is determined.
[0031] In a possible design, determining the video stream corresponding to the network camera according to the stream object includes:
[0032] Calling a track parsing function to parse the stream object and obtain a video track list of the stream object, wherein each video track in the video track list represents a video data stream;
[0033] The first video track is screened out from the video track list, and the video data stream corresponding to the first video track is used as the video stream corresponding to the network camera.
[0034] In a possible design, based on the desired resolution, a resolution constraint function of the network camera is generated, including:
[0035] Acquire a track constraint function, wherein the track constraint function is used to establish constraint attributes for a video track, the constraint attributes include resolution, and the video track is used to characterize a video data stream;
[0036] The desired resolution is filled into the trajectory constraint function to obtain the resolution constraint function after filling.
[0037] In a second aspect, a device for dynamically adjusting an optimal resolution of a WebCam is provided, comprising:
[0038] An acquisition unit, used to acquire an expected resolution of the network camera, a video stream corresponding to the network camera, and a resolution adjustment parameter, wherein the resolution adjustment parameter includes a maximum resolution and a number of resolution decrement steps;
[0039] A resolution constraint unit, used for generating a resolution constraint function of the network camera based on the expected resolution, wherein the resolution constraint function is used for returning a support response result of the network camera for the real-time resolution;
[0040] A resolution optimization unit, used to use the maximum resolution in the resolution adjustment parameter as an initial value, and use the resolution constraint function and the plurality of resolution decrement step lengths to perform resolution decrement optimization processing on the network camera until an optimization end condition is met to obtain an optimal resolution, wherein the optimization end condition is that the support response result returned by the resolution constraint function is successful, and the current resolution decrement step length is less than or equal to the minimum resolution decrement step length among the plurality of resolution decrement step lengths;
[0041] The resolution adjustment unit is used to adjust the video stream corresponding to the network camera based on the optimal resolution and output the adjusted video stream.
[0042] In a third aspect, another device for dynamically adjusting the optimal resolution of a WebCam is provided. Taking the device as an electronic device as an example, the device includes a memory, a processor, and a transceiver that are communicatively connected in sequence, wherein the memory is used to store a computer program, the transceiver is used to send and receive messages, and the processor is used to read the computer program to execute a method for dynamically adjusting the optimal resolution of the WebCam as in the first aspect or any possible design in the first aspect.
[0043] In a fourth aspect, a storage medium is provided, on which instructions are stored. When the instructions are executed on a computer, a method for dynamically adjusting the optimal resolution of the WebCam as in the first aspect or any possible design of the first aspect is executed.
[0044] In a fifth aspect, a computer program product is provided, wherein the computer program product includes instructions, which, when executed on a computer, cause the computer to execute a method for dynamically adjusting the optimal resolution of the WebCam as in the first aspect or any possible design of the first aspect.
[0045] Beneficial effects:
[0046] (1) The present invention generates a resolution constraint function for returning a response result of the device's support for the real-time resolution through the expected resolution, and proposes a progressive resolution adjustment mechanism to optimize the resolution, that is, taking the set maximum resolution as the initial value, and then using each resolution reduction step to perform a resolution reduction adjustment, and in the adjustment process, based on the aforementioned resolution constraint function, to determine whether the device supports the adjusted resolution; in this way, the resolution is continuously adjusted until the optimization end condition is met, and the optimal resolution can be obtained; therefore, the present invention can quickly and accurately find the optimal resolution suitable for a specific device and scene, thereby significantly improving the video quality and user experience, and is therefore very suitable for large-scale application and promotion. BRIEF DESCRIPTION OF THE DRAWINGS
[0047] Figure 1 A schematic flow chart of the steps of a method for dynamically adjusting the optimal resolution of a WebCam provided by an embodiment of the present invention;
[0048] Figure 2 A schematic diagram of the structure of a device for dynamically adjusting the optimal resolution of a WebCam provided by an embodiment of the present invention;
[0049] Figure 3 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0050] In order to more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the present invention will be briefly introduced below in combination with the drawings and the description of the embodiments or the prior art. Obviously, the following description of the structure of the drawings is only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without creative work. It should be noted that the description of these embodiments is used to help understand the present invention, but does not constitute a limitation of the present invention.
[0051] It should be understood that although the terms first, second, etc. may be used herein to describe various units, these units should not be limited by these terms. These terms are only used to distinguish one unit from another unit. For example, a first unit can be referred to as a second unit, and similarly, a second unit can be referred to as a first unit without departing from the scope of the exemplary embodiments of the present invention.
[0052] It should be understood that the term "and / or" that may appear in this article is merely a description of the association relationship between associated objects, indicating that three relationships may exist. For example, A and / or B can represent three situations: A exists alone, B exists alone, and A and B exist at the same time. The term " / and" that may appear in this article describes another type of association object relationship, indicating that two relationships may exist. For example, A / and B can represent two situations: A exists alone, and A and B exist alone. In addition, the character " / " that may appear in this article generally indicates that the previous and next associated objects are in an "or" relationship.
[0053] Example:
[0054] See also Figure 1 As shown, the method for dynamically adjusting the optimal resolution of WebCam provided in this embodiment constructs a resolution constraint function through the expected resolution and the applyConstraints API method, and based on this, proposes a progressive resolution adjustment mechanism to adjust the resolution, that is, taking the set maximum resolution as the initial value, and then using each resolution decreasing step to adjust the resolution in a decreasing manner, and in the adjustment process, based on the aforementioned resolution constraint function, to determine whether the device supports the adjusted resolution; in this way, the resolution is continuously adjusted in this way until the optimal resolution is obtained when the optimization end condition is met; thus, the method can quickly and accurately find the optimal resolution suitable for a specific device and scene, thereby significantly improving the video quality and user experience, and therefore, is very suitable for large-scale application and promotion; wherein, the method can be but not limited to running on the webcam side, it can be understood that the aforementioned execution subject does not constitute a limitation on the embodiments of the present application, and accordingly, the running steps of the method can be but not limited to the following steps S1 to S4.
[0055] S1. Obtain the expected resolution of the network camera, the video stream corresponding to the network camera, and the resolution adjustment parameters, wherein the resolution adjustment parameters include the maximum resolution and a number of resolution reduction steps; in specific implementation, the expected resolution may be but is not limited to the upper limit resolution supported by the network camera, and may also be the resolution set by the user for the network camera; at the same time, for example, the aforementioned maximum resolution may be but is not limited to being set to 10000, and the several resolution reduction steps may be arranged in order from large to small, such as being set to 1000, 100, 10 and 1 in sequence; of course, the aforementioned resolution adjustment parameters may be specifically set according to actual use, and are not limited to the aforementioned examples.
[0056] Further, for example, but not limited to, the following steps S11 to S13 may be used to obtain the aforementioned desired resolution and video stream.
[0057] S11. Obtaining the API access function of the streaming media device; in the specific implementation, the aforementioned API access function may be, but is not limited to, for example: navigator.mediaDevices.getUserMedia(), which is an API access function in Vue (a JavaScript framework for building user interfaces) for accessing streaming media devices (such as cameras or microphones), which allows web pages to access cameras and / or microphones and returns a MediaStream object, which can be further used to capture video and audio; in this way, after obtaining the aforementioned API access function, the desired resolution and the aforementioned video stream can be obtained based on the access function, and the process may be, but is not limited to, as shown in the following step S12.
[0058] S12. Run the API access function to obtain the expected resolution of the network camera and obtain a stream object containing a media stream. In this embodiment, the API access function can be used to obtain the permissions of the network camera, so that its configured resolution can be found, and the resolution is the expected resolution. At the same time, the stream object refers to a streaming object, which contains the captured video and audio of the network camera. Based on this, the video stream corresponding to the network camera can be determined through the streaming object. The specific determination process of the video stream can be but is not limited to the following step S13.
[0059] S13. Determine the video stream corresponding to the network camera according to the stream object; in specific applications, for example, but not limited to, first call the track parsing function to parse the stream object to obtain a video track list of the stream object; wherein each video track in the video track list represents a video data stream, and the track parsing function may be, but not limited to, use the "stream.getVideoTracks()" function; of course, the aforementioned function is a commonly used parsing function of the stream object, and its principle will not be repeated here.
[0060] After obtaining the video track list of the stream object, usually only the first video track is needed. Therefore, this embodiment filters out the first video track from the video track list, and uses the video data stream corresponding to the first video track as the video stream corresponding to the network camera.
[0061] In this way, after obtaining the expected resolution and the video stream corresponding to the network camera through the aforementioned steps S11 to S13, the resolution can be adjusted; in specific applications, this embodiment first uses the expected resolution to construct a resolution constraint function, and then combines the resolution adjustment parameters to perform resolution adjustment; wherein, the resolution constraint function is used to determine whether the current real-time resolution can be supported by the device, so the resolution can be adjusted based on the result returned by the function; optionally, the construction process of the resolution constraint function can be but is not limited to as shown in the following step S2.
[0062] S2. Based on the expected resolution, generate a resolution constraint function of the network camera, wherein the resolution constraint function is used to return a response result of the network camera's support for real-time resolution; in specific implementation, for example, but not limited to, first obtain a track constraint function (the track constraint function is used to establish constraint attributes for a video track, the constraint attributes include resolution, and the video track is used to characterize a video data stream); then, fill the expected resolution into the track constraint function to obtain the resolution constraint function after filling.
[0063] In this embodiment, the resolution constraint function may be, but is not limited to, "applyConstraints(constraints)". This function accepts an object constraints containing constraints, which are used to set parameters such as the expected video resolution. Therefore, when the device obtains a resolution, if the newly obtained resolution does not meet the constraints (such as the expected resolution is 1280, and the obtained resolution is 1980), then the function will return an exception, that is, the returned support response result is failure; conversely, if the obtained resolution meets the constraints, the returned support response result is success.
[0064] In this way, by calling the applyConstraints(constraints) method and combining it with the desired resolution to generate a resolution constraint function, the resolution can be optimized based on this. Among them, this embodiment proposes a decreasing resolution adjustment mechanism based on the aforementioned constraint function, and its adjustment process can be but is not limited to the following step S3.
[0065] S3. Taking the maximum resolution in the resolution adjustment parameters as the initial value, and using the resolution constraint function and the several resolution reduction steps, the network camera is subjected to resolution reduction optimization processing until the optimization end condition is met and the best resolution is obtained, wherein the optimization end condition is that the support response result returned by the resolution constraint function is successful, and the current resolution reduction step is less than or equal to the smallest resolution reduction step among the several resolution reduction step; in specific applications, the core of the resolution adjustment algorithm is: setting a resolution upper limit (i.e., maximum resolution) and several reduction values (i.e., resolution reduction step), and then, according to the resolution reduction step, reducing the maximum resolution in turn, and applying the aforementioned resolution constraint function to verify whether the obtained resolution is supported by the device, until the best resolution that the device can support is found.
[0066] Optionally, the above-mentioned resolution optimization process may be, but is not limited to, as shown in the following steps S31 to S35.
[0067] S31. For the i-th resolution reduction step among several resolution reduction steps, based on the i-th resolution reduction step and the resolution constraint function, the initial value is subjected to the k-th resolution reduction optimization process, and after the k-th resolution reduction optimization process, the k-th initial optimal resolution is obtained, wherein the initial values of i and k are both 1; in this embodiment, the maximum resolution is decreased at each resolution reduction step until the resolution obtained by the decrease makes the support response result returned by the resolution constraint function successful, and the decrease operation of the current resolution reduction step is completed.
[0068] The kth initial optimal resolution may be obtained by, for example but not limited to, the following steps S31a to S31d.
[0069] S31a. Calculate the difference between the initial value and the i-th resolution reduction step, and use the difference as the real-time resolution. In this embodiment, an example is used to illustrate this step. Assuming that the maximum resolution is 10000, the initial value is 100, and the first resolution reduction step is 1000, then the real-time resolution is 9000. At this time, it is necessary to use the resolution constraint function to determine whether the current real-time resolution is supported by the device. The process is shown in the following step S31b.
[0070] S31b. Based on the real-time resolution, the resolution constraint function is run to obtain a support response result of the resolution constraint function; in a specific implementation, the support response result is success or failure, wherein success means that the device supports the current real-time resolution, and vice versa; therefore, whether the resolution needs to be further adjusted can be determined based on the support response result, and the process can be but is not limited to as shown in the following step S31c.
[0071] S31c. Determine whether the support response result is successful; in this embodiment, assuming that the aforementioned expected resolution is 1280, and the current real-time resolution is 9000, it is obviously beyond the expected resolution. At this time, running the resolution constraint function will result in an exception, that is, the support response result is a failure. Therefore, it is necessary to continue to reduce the resolution, and the process is shown in the following step S31d.
[0072] S31d. If not, the initial value is updated to the real-time resolution, and the difference between the initial value and the i-th resolution decrement step is recalculated, until the support response result is successful, and the real-time resolution corresponding to the support response result is successful is used as the k-th initial optimal resolution; in specific applications, it is equivalent to continuously updating the initial value, and then subtracting the current resolution decrement step again, and then re-running the resolution constraint function, and judging whether it is necessary to continue to adjust, until the reduced resolution is supported by the device (that is, the returned support response result is successful), the resolution adjustment process corresponding to the current resolution decrement step can be completed.
[0073] In this way, through the aforementioned steps S31a~S31b, the resolution adjustment corresponding to the i-th resolution reduction step can be completed, that is, the first round of reduction is completed. At this time, it can be judged whether the optimization end condition is met based on the first initial optimal resolution obtained; wherein, the judgment process is shown in the following step S32.
[0074] S32. Take the i-th resolution decrease step as the current resolution decrease step, and determine whether the optimization end condition is met based on the k-th initial optimal resolution and the current resolution decrease step. In this embodiment, the k-th initial optimal resolution must be supported by the device, because only when the aforementioned step S31c is met can the k-th initial optimal resolution be obtained. At the same time, the current resolution decrease step is the first resolution decrease step, that is, 1000, which is not less than or equal to the minimum resolution decrease step. Therefore, it is necessary to update the initial value and the resolution decrease step in order to perform the next round of decrease. The updating process of the initial value and the resolution decrease step may be, but is not limited to, as shown in the following steps S33 and S34.
[0075] S33. If not, the kth initial optimal resolution and the ith resolution decreasing step are summed to obtain the target resolution after the summation. In this embodiment, based on the above example, it is assumed that the first initial optimal resolution is 1000 and the first resolution decreasing step is 1000, then the target resolution is: 1000+1000=2000. Of course, when the first initial optimal resolution and the first resolution decreasing step are different, the calculation process of the target resolution is the same as the above example and will not be repeated here.
[0076] After the target resolution is obtained, it is necessary to determine the update value of the i-th resolution decreasing step, and the process may be but is not limited to the following step S34.
[0077] S34. Based on the i-th resolution decreasing step, determine the target step from the several resolution decreasing step; in the present embodiment, first determine whether the i-th resolution decreasing step is greater than the n-th resolution decreasing step (the initial value of n is i+1); if not, n is incremented by 1, and re-determined whether the i-th resolution decreasing step is greater than the n-th resolution decreasing step, until the i-th resolution decreasing step is greater than the n-th resolution decreasing step, then the n-th resolution decreasing step is used as the target step.
[0078] The following is an example to illustrate this step: the first resolution decrease step is 1000. At this time, the nth resolution decrease step is the first resolution decrease step, that is, 100. At this time, 1000 is greater than 100, so 100 can be directly used as the target step. Therefore, the update value of the i-th resolution decrease step is 100; of course, if the first resolution decrease step is less than or equal to the second resolution decrease step, continue to judge, that is, judge whether the first resolution decrease step is greater than the third resolution decrease step (that is, n=2+1), until the i-th resolution decrease step is greater than the n-th resolution decrease step, then the n-th resolution decrease step can be used as the target step.
[0079] In this way, after obtaining the target resolution and target step size, the initial value and the i-th resolution reduction step size can be updated, and then the next round of reduction can be performed, and the process is shown in the following step S35.
[0080] S35. Update the initial value to the target resolution, update the i-th resolution decrement step to the target step, increment k by 1, and re-perform the k-th resolution decrement optimization process on the initial value based on the i-th resolution decrement step and the resolution constraint function until the optimization end condition is met, and take the k-th initial optimal resolution when the optimization end condition is met as the optimal resolution; in the present embodiment, it is equivalent to updating the initial value to the target resolution, updating the i-th resolution decrement step to the target step, at this time, re-execute the aforementioned steps S31a~S31d for the next round of decrement, and then, judge again whether the optimization end condition is met, and if not, update the initial value and the i-th resolution decrement step again; in this way, the cycle is repeated until the optimization end condition is met, and the optimal resolution can be obtained.
[0081] The following is an example to illustrate the above steps S31 to S35:
[0082] Assuming that the expected resolution is 1280, the maximum resolution is 10000, and the resolution decreasing steps are 1000, 100, 10, and 1, the resolution optimization process is:
[0083] First, the first round of decrement is performed: the initial value is 10000, and the i-th resolution decrement step is 1000, that is, i=1; at this time, using 10000-1000, the real-time resolution is 9000; then, the resolution constraint function is run to obtain the corresponding support response result; among them, 9000 is greater than the expected resolution, and the device does not support this resolution, so the support response result is failure; based on this, the initial value is updated to the real-time resolution, and the initial value becomes 9000.
[0084] Next, continue to calculate the difference between 9000 and 1000 to get the real-time resolution of 8000, and then run the resolution constraint function. At this time, if the support response result is still failure, then the initial value is updated to 8000; thus, the above process is repeated continuously. When the real-time resolution obtained by multiple reductions is 1000, its corresponding support response result is success, then the first initial optimal resolution is 1000.
[0085] Furthermore, the first resolution decreasing step is used as the current resolution decreasing step. At this time, 1000 is not less than or equal to 1 (i.e., the minimum resolution decreasing step). Therefore, it is necessary to update the initial value and the i-th resolution decreasing step. The process is as follows:
[0086] Use 1000 (i.e. the first initial optimal resolution) plus the i-th resolution decrease step (value is 1000) to get the target resolution of 2000; then, determine whether the i-th resolution decrease step is greater than the n-th resolution decrease step (i is 1 at this time, so n=2); among them, the second resolution decrease step is 100, which meets the conditions, so the target step is 200; based on this, the initial value is updated to 2000, and the i-th resolution decrease step is updated to the second resolution decrease step, that is, 100.
[0087] Then, a second round of decrement is performed, that is: subtract 100 from 2000 to obtain a real-time resolution of 1900; then, the resolution constraint function is run to obtain the corresponding support response result; if it fails, the initial value is updated to 1900, and 100 is subtracted again to obtain a real-time resolution of 1800; in this way, the above principle is used to continuously decrement until the support response result is successful. Assuming that the support response result is successful when it is decremented to 1200, then the second initial optimal resolution is 1200.
[0088] Similarly, we continue to judge whether the optimization end condition is met, that is, the current resolution decrease step is 100, which is not less than or equal to 1. Therefore, we still need to update the initial value and the i-th resolution decrease step, that is, the target resolution is: 1200+100=1300, and the target step is 10 (that is, the second resolution decrease step is greater than the third resolution decrease step, so the third resolution decrease step is used as the target step); at this time, the initial value is updated to 1300, and the i-th resolution decrease step is updated to 10.
[0089] Next, the third round of reduction is carried out, that is: use 1300 minus 10 to get the real-time resolution of 1290, and run the resolution constraint function, and then judge with the same principle as mentioned above, and reduce it until the support response result corresponding to the reduced resolution is successful. At this time, assuming that the real-time resolution is 1280 and the corresponding support response result is successful, then the third initial optimal resolution is 1280.
[0090] Next, we continue to determine whether the optimization end condition is met, that is, the current decreasing resolution is 10, not less than or equal to 1. Therefore, the target resolution is calculated as: 1280+10=1290, and the target step size is 1; based on this, the initial value is 1290, and the i-th resolution decreasing step size is 1.
[0091] At this time, the fourth round of decrement is performed, that is, 1290 minus 1 is used to obtain a real-time resolution of 1289; then, the deceleration step is repeated until the support response result corresponding to the real-time resolution is successful. At this time, assuming that the fourth initial optimal resolution is 1280, and the current resolution decrement step is 1; then, the optimization end condition is met; at this time, 1280 is used as the optimal resolution.
[0092] At present, the above examples are for illustration only. When the maximum resolution and the resolution reduction step are different, the resolution adjustment process is also the same, and no further details will be given here.
[0093] In this way, through the aforementioned steps S31 to S35, the resolution optimization can be completed and the best resolution can be obtained; then, the video stream can be adjusted based on the best resolution, and the process is shown in the following step S4.
[0094] S4. Based on the optimal resolution, the video stream corresponding to the network camera is adjusted, and the adjusted video stream is output; in the present embodiment, this is equivalent to adjusting the resolution of the video stream corresponding to the network camera to the optimal resolution to achieve the best video playback effect; thus, the present embodiment provides a universal resolution adjustment method, which enables many devices to adaptively adjust the actual resolution according to their desired resolution, thereby eliminating the need for separate configuration, and enables high-end and low-end devices to adjust the resolution accordingly according to their hardware resources, thereby achieving the best video experience.
[0095] Thus, the method for dynamically adjusting the optimal resolution of WebCam described in detail in the aforementioned steps S1 to S4 has the following advantages:
[0096] (1) Strong adaptability and wide versatility. The method provided by the present invention is applicable to a variety of devices and application scenarios, has wide applicability, and can adapt to different scenarios and conditions.
[0097] (2) Improved user experience, that is, users can get the best video experience under different conditions.
[0098] (3) Efficient resource utilization, that is, the present invention can adjust the resolution according to actual needs and maximize the utilization of hardware resources.
[0099] like Figure 2 As shown, the second aspect of this embodiment provides a hardware device for implementing the method for dynamically adjusting the optimal resolution of the WebCam described in the first aspect of the embodiment, including:
[0100] The acquisition unit is used to acquire the expected resolution of the network camera, the video stream corresponding to the network camera, and the resolution adjustment parameters, wherein the resolution adjustment parameters include the maximum resolution and a number of resolution reduction steps.
[0101] A resolution constraint unit is used to generate a resolution constraint function of the network camera based on the expected resolution, wherein the resolution constraint function is used to return a response result of the network camera's support for the real-time resolution.
[0102] The resolution optimization unit is used to use the maximum resolution in the resolution adjustment parameters as the initial value, and use the resolution constraint function and the several resolution reduction steps to perform resolution reduction optimization processing on the network camera until the optimal resolution is obtained when the optimization end condition is met, wherein the optimization end condition is that the support response result returned by the resolution constraint function is successful, and the current resolution reduction step is less than or equal to the smallest resolution reduction step among the several resolution reduction step.
[0103] The resolution adjustment unit is used to adjust the video stream corresponding to the network camera based on the optimal resolution and output the adjusted video stream.
[0104] The working process, working details and technical effects of the device provided in this embodiment can be found in the first aspect of the embodiment and will not be described in detail here.
[0105] like Figure 3 As shown, the third aspect of this embodiment provides another device for dynamically adjusting the optimal resolution of a WebCam. Taking the device as an electronic device as an example, the device includes: a memory, a processor, and a transceiver that are communicatively connected in sequence, wherein the memory is used to store a computer program, the transceiver is used to send and receive messages, and the processor is used to read the computer program to execute the method for dynamically adjusting the optimal resolution of the WebCam as described in the first aspect of the embodiment.
[0106] For example, the memory may include, but is not limited to, random access memory (RAM), read only memory (ROM), flash memory, first input first output (FIFO) and / or first in last out (FILO), etc. Specifically, the processor may include one or more processing cores, such as a 4-core processor, an 8-core processor, etc. The processor may be implemented in at least one hardware form of DSP (Digital Signal Processing), FPGA (Field-Programmable Gate Array), and PLA (Programmable Logic Array). At the same time, the processor may also include a main processor and a coprocessor. The main processor is a processor for processing data in the awake state, also known as a CPU (Central Processing Unit); the coprocessor is a low-power processor for processing data in the standby state.
[0107] In some embodiments, the processor may be integrated with a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content to be displayed on the display screen. For example, the processor may not be limited to a microprocessor of the STM32F105 series, a reduced instruction set computer (RISC) microprocessor, an X86 architecture processor, or a processor with an integrated embedded neural network processing unit (NPU); the transceiver may be, but is not limited to, a wireless fidelity (WIFI) wireless transceiver, a Bluetooth wireless transceiver, a General Packet Radio Service (GPRS) wireless transceiver, a ZigBee protocol (a low-power LAN protocol based on the IEEE802.15.4 standard, ZigBee) wireless transceiver, a 3G transceiver, a 4G transceiver, and / or a 5G transceiver. In addition, the device may also include, but is not limited to, a power module, a display screen, and other necessary components.
[0108] The working process, working details and technical effects of the electronic device provided in this embodiment can be found in the first aspect of the embodiment and will not be described in detail here.
[0109] The fourth aspect of this embodiment provides a storage medium storing instructions for the method for dynamically adjusting the optimal resolution of the WebCam described in the first aspect of the embodiment, that is, the storage medium stores instructions, and when the instructions are executed on a computer, the method for dynamically adjusting the optimal resolution of the WebCam described in the first aspect of the embodiment is executed.
[0110] The storage medium refers to a carrier for storing data, which may include but is not limited to a floppy disk, a CD, a hard disk, a flash memory, a USB flash drive and / or a memory stick, and the computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices.
[0111] The working process, working details and technical effects of the storage medium provided in this embodiment can be found in the first aspect of the embodiment and will not be described in detail here.
[0112] A fifth aspect of this embodiment provides a computer program product, wherein the computer program product includes instructions, which, when executed on a computer, enable the computer to execute the method for dynamically adjusting the optimal resolution of the WebCam as described in the first aspect of the embodiment, wherein the computer may be a general-purpose computer, a special-purpose computer, a computer network, or other programmable devices.
[0113] Finally, it should be noted that the above description is only a preferred embodiment of the present invention and is not intended to limit the protection scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention shall be included in the protection scope of the present invention.
Claims
1. A method for dynamically adjusting the optimal resolution of a WebCam, characterized in that: include: Obtaining the expected resolution of the network camera, the video stream corresponding to the network camera, and resolution adjustment parameters, wherein the resolution adjustment parameters include a maximum resolution and a number of resolution reduction steps; Based on the expected resolution, generating a resolution constraint function of the network camera, wherein the resolution constraint function is used to return a support response result of the network camera for the real-time resolution; Taking the maximum resolution in the resolution adjustment parameter as the initial value, and using the resolution constraint function and the plurality of resolution decrement step lengths, performing resolution decrement optimization processing on the network camera until the optimal resolution is obtained when the optimization end condition is met, wherein the optimization end condition is that the support response result returned by the resolution constraint function is successful, and the current resolution decrement step length is less than or equal to the minimum resolution decrement step length among the plurality of resolution decrement step lengths; Based on the optimal resolution, adjusting the video stream corresponding to the network camera, and outputting the adjusted video stream; The plurality of resolution decreasing step sizes are arranged in descending order, wherein the maximum resolution in the resolution adjustment parameter is used as the initial value, and the resolution constraint function and the plurality of resolution decreasing step sizes are used to perform resolution decreasing optimization processing on the network camera, including: For an i-th resolution decreasing step among the plurality of resolution decreasing step lengths, based on the i-th resolution decreasing step length and the resolution constraint function, performing a k-th resolution decreasing optimization process on the initial value, and obtaining a k-th initial optimal resolution after the k-th resolution decreasing optimization process, wherein the initial values of i and k are both 1; Taking the i-th resolution decreasing step length as the current resolution decreasing step length, and judging whether the optimization end condition is satisfied based on the k-th initial optimal resolution and the current resolution decreasing step length; If not, the kth initial optimal resolution and the ith resolution decreasing step are summed to obtain the target resolution after the summing process; Based on the i-th resolution decreasing step length, determining a target step length from the plurality of resolution decreasing step lengths; The initial value is updated to the target resolution, the i-th resolution decreasing step is updated to the target step, k is incremented by 1, and the initial value is subjected to a k-th resolution decreasing optimization process based on the i-th resolution decreasing step and the resolution constraint function again, until the optimization end condition is met, and the k-th initial optimal resolution when the optimization end condition is met is used as the optimal resolution; Based on the i-th resolution decreasing step and the resolution constraint function, performing a k-th resolution decreasing optimization process on the initial value, comprising: Calculate the difference between the initial value and the i-th resolution decreasing step, and use the difference as the real-time resolution; Based on the real-time resolution, running the resolution constraint function to obtain a support response result of the resolution constraint function; Determining whether the support response result is successful; If not, the initial value is updated to the real-time resolution, and the difference between the initial value and the i-th resolution decreasing step is recalculated, until the support response result is successful, and the real-time resolution corresponding to the support response result being successful is used as the k-th initial optimal resolution; Based on the i-th resolution decreasing step length, determining a target step length from the plurality of resolution decreasing step lengths comprises: Determine whether the i-th resolution decreasing step is greater than the n-th resolution decreasing step, where the initial value of n is i+1; If not, n is incremented by 1, and whether the i-th resolution decreasing step is greater than the n-th resolution decreasing step is re-determined, until the i-th resolution decreasing step is greater than the n-th resolution decreasing step, the n-th resolution decreasing step is used as the target step.
2. The method according to claim 1, characterized in that Get the expected resolution of the webcam and the corresponding video stream of the webcam, including: Get the API access function of the streaming device; Run the API access function to obtain the expected resolution of the network camera and obtain a stream object containing a media stream; According to the stream object, the video stream corresponding to the network camera is determined.
3. The method according to claim 2, characterized in that According to the stream object, determining the video stream corresponding to the network camera includes: Calling a track parsing function to parse the stream object and obtain a video track list of the stream object, wherein each video track in the video track list represents a video data stream; The first video track is screened out from the video track list, and the video data stream corresponding to the first video track is used as the video stream corresponding to the network camera.
4. The method according to claim 1, characterized in that: Based on the expected resolution, generating a resolution constraint function of the network camera includes: Acquire a track constraint function, wherein the track constraint function is used to establish constraint attributes for a video track, the constraint attributes include resolution, and the video track is used to characterize a video data stream; The desired resolution is filled into the trajectory constraint function to obtain the resolution constraint function after filling.
5. A device for dynamically adjusting the optimal resolution of a WebCam, characterized in that: include: An acquisition unit, used to acquire an expected resolution of the network camera, a video stream corresponding to the network camera, and a resolution adjustment parameter, wherein the resolution adjustment parameter includes a maximum resolution and a number of resolution decrement steps; A resolution constraint unit, used for generating a resolution constraint function of the network camera based on the expected resolution, wherein the resolution constraint function is used for returning a support response result of the network camera for the real-time resolution; A resolution optimization unit, used to use the maximum resolution in the resolution adjustment parameter as an initial value, and use the resolution constraint function and the plurality of resolution decrement step lengths to perform resolution decrement optimization processing on the network camera until an optimization end condition is met to obtain an optimal resolution, wherein the optimization end condition is that the support response result returned by the resolution constraint function is successful, and the current resolution decrement step length is less than or equal to the minimum resolution decrement step length among the plurality of resolution decrement step lengths; A resolution adjustment unit, configured to adjust the video stream corresponding to the network camera based on the optimal resolution, and output the adjusted video stream; The plurality of resolution decreasing step sizes are arranged in descending order, wherein the maximum resolution in the resolution adjustment parameter is used as the initial value, and the resolution constraint function and the plurality of resolution decreasing step sizes are used to perform resolution decreasing optimization processing on the network camera, including: For an i-th resolution decreasing step among the plurality of resolution decreasing step lengths, based on the i-th resolution decreasing step length and the resolution constraint function, performing a k-th resolution decreasing optimization process on the initial value, and obtaining a k-th initial optimal resolution after the k-th resolution decreasing optimization process, wherein the initial values of i and k are both 1; Taking the i-th resolution decreasing step length as the current resolution decreasing step length, and judging whether the optimization end condition is satisfied based on the k-th initial optimal resolution and the current resolution decreasing step length; If not, the kth initial optimal resolution and the ith resolution decreasing step are summed to obtain the target resolution after the summing process; Based on the i-th resolution decreasing step length, determining a target step length from the plurality of resolution decreasing step lengths; The initial value is updated to the target resolution, the i-th resolution decreasing step is updated to the target step, k is incremented by 1, and the initial value is subjected to a k-th resolution decreasing optimization process based on the i-th resolution decreasing step and the resolution constraint function again, until the optimization end condition is met, and the k-th initial optimal resolution when the optimization end condition is met is used as the optimal resolution; Based on the i-th resolution decreasing step and the resolution constraint function, performing a k-th resolution decreasing optimization process on the initial value, comprising: Calculate the difference between the initial value and the i-th resolution decreasing step, and use the difference as the real-time resolution; Based on the real-time resolution, running the resolution constraint function to obtain a support response result of the resolution constraint function; Determining whether the support response result is successful; If not, the initial value is updated to the real-time resolution, and the difference between the initial value and the i-th resolution decreasing step is recalculated, until the support response result is successful, and the real-time resolution corresponding to the support response result being successful is used as the k-th initial optimal resolution; Based on the i-th resolution decreasing step length, determining a target step length from the plurality of resolution decreasing step lengths comprises: Determine whether the i-th resolution decreasing step is greater than the n-th resolution decreasing step, where the initial value of n is i+1; If not, n is incremented by 1, and whether the i-th resolution decreasing step is greater than the n-th resolution decreasing step is re-determined, until the i-th resolution decreasing step is greater than the n-th resolution decreasing step, the n-th resolution decreasing step is used as the target step.
6. A device for dynamically adjusting the optimal resolution of a WebCam, characterized in that: include: A memory, a processor and a transceiver which are sequentially connected in communication, wherein the memory is used to store a computer program, the transceiver is used to send and receive messages, and the processor is used to read the computer program, and execute the method for dynamically adjusting the optimal resolution of a WebCam as described in any one of claims 1 to 4.
7. A computer program product, characterized in that The computer program product includes instructions, and when the instructions are executed on a computer, the computer is caused to execute the method for dynamically adjusting the optimal resolution of a WebCam as claimed in any one of claims 1 to 4.
Citation Information
Patent Citations
High dynamic range (HDR) photography with in-sensor zoom
US20230199337A1
Encoding resolution control
US20240340446A1