• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Video Variable Frame Rate
2
3With the CAPIs related to the video variable refresh rate feature, you can dynamically adjust the screen refresh rate based on the video content during playback. This helps save display power while maintaining smooth video playback.
4
5## When to Use
6
7The video variable refresh rate feature is ideal for video sources with high frame rates (>30 fps). For video sources with frame rates at or below 30 fps, a refresh rate of 30 Hz is recommended.
8
9The figure below demonstrates the playback of a 60 fps video. The algorithm adjusts the screen refresh rate in real-time based on the video content. If the refresh rate drops below the video frame rate, some frames will be discarded to save power.
10
11![Video variable refreshrate](figures/video-variable-refreshrate.png)
12
13## Constraints
14
151. This feature is available only for the scenario where the video is directly sent for display after hardware decoding.
162. The overall screen refresh rate will change. It is recommended that you use this feature in full-screen playback scenarios without bullet comments or animations, as the feature may affect their smoothness.
173. This feature depends on the decoding frame rate configuration. The **OH_MD_KEY_FRAME_RATE** property must be correctly set before use.
184. This feature is platform-dependent. If the platform does not support this feature, the API calls do not report an error, but the feature does not take effect. Normal decoding and playback still function.
19
20## How to Develop
21
22This section describes only the steps that are different from the basic decoding process. You can learn the basic decoding process in [Video Decoding](video-decoding.md).
23
241. Enable the video variable frame rate feature during decoder configuration.
25
26   In the code snippet below, the following variables are used:
27
28   **videoDec**: pointer to the video decoder instance. For details, see [Creating a Decoder Instance in Surface Mode](video-decoding.md#surface-output).
29
30    ```cpp
31    OH_AVFormat *format = OH_AVFormat_Create();
32    int32_t width = 1280; // Video frame width.
33    int32_t height = 720; // Video frame height.
34    int32_t fps = 60; // Video frame rate.
35    OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, width);
36    OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, height);
37    OH_AVFormat_SetIntValue(format, OH_MD_KEY_FRAME_RATE, fps);
38    OH_AVFormat_SetIntValue(format, OH_MD_KEY_VIDEO_DECODER_OUTPUT_ENABLE_VRR, 1);
39    int32_t ret = OH_VideoDecoder_Configure(videoDec, format);
40    if (ret != AV_ERR_OK) {
41        // Handle exceptions.
42    }
43    OH_AVFormat_Destroy(format);
44    ```
45
462. (Optional) Dynamically enable or disable the variable frame rate feature during video playback.
47
48    If bullet comments are enabled during playback, you can disable the variable frame rate feature to avoid wasting resources, since the refresh rate adjustments are not applied.
49
50    The following code snippet is used to dynamically disable the feature:
51
52    ```cpp
53    OH_AVFormat *format = OH_AVFormat_Create();
54    OH_AVFormat_SetIntValue(format, OH_MD_KEY_VIDEO_DECODER_OUTPUT_ENABLE_VRR, 0);
55    OH_VideoDecoder_SetParameter(videoDec, format);
56    OH_AVFormat_Destroy(format);
57    ```
58
59    The following code snippet is used to dynamically enable the feature:
60
61    ```cpp
62    OH_AVFormat *format = OH_AVFormat_Create();
63    OH_AVFormat_SetIntValue(format, OH_MD_KEY_FRAME_RATE, fps);
64    OH_AVFormat_SetIntValue(format, OH_MD_KEY_VIDEO_DECODER_OUTPUT_ENABLE_VRR, 1);
65    OH_VideoDecoder_SetParameter(videoDec, format);
66    OH_AVFormat_Destroy(format);
67    ```
68