• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Video Variable Frame Rate
2
3<!--Kit: AVCodec Kit-->
4<!--Subsystem: Multimedia-->
5<!--Owner: @tianjian97861-->
6<!--Designer: @dpy2650--->
7<!--Tester: @cyakee-->
8<!--Adviser: @zengyawen-->
9
10With the C APIs 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.
11
12## When to Use
13
14The 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.
15
16The 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.
17
18![Video variable refreshrate](figures/video-variable-refreshrate.png)
19
20## Constraints
21
221. This feature is available only for the scenario where the video is directly sent for display after hardware decoding.
232. 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.
243. This feature depends on the decoding frame rate configuration. The **OH_MD_KEY_FRAME_RATE** property must be correctly set before use.
254. 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.
26
27## How to Develop
28
29This 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).
30
311. Enable the video variable frame rate feature during decoder configuration.
32
33   In the code snippet below, the following variables are used:
34
35   **videoDec**: pointer to the video decoder instance. For details, see [Creating a Decoder Instance in Surface Mode](video-decoding.md#surface-mode).
36
37    ```cpp
38    OH_AVFormat *format = OH_AVFormat_Create();
39    int32_t width = 1280; // Video frame width.
40    int32_t height = 720; // Video frame height.
41    int32_t fps = 60; // Video frame rate.
42    OH_AVFormat_SetIntValue(format, OH_MD_KEY_WIDTH, width);
43    OH_AVFormat_SetIntValue(format, OH_MD_KEY_HEIGHT, height);
44    OH_AVFormat_SetIntValue(format, OH_MD_KEY_FRAME_RATE, fps);
45    OH_AVFormat_SetIntValue(format, OH_MD_KEY_VIDEO_DECODER_OUTPUT_ENABLE_VRR, 1);
46    int32_t ret = OH_VideoDecoder_Configure(videoDec, format);
47    if (ret != AV_ERR_OK) {
48        // Handle exceptions.
49    }
50    OH_AVFormat_Destroy(format);
51    ```
52
532. (Optional) Dynamically enable or disable the variable frame rate feature during video playback.
54
55    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.
56
57    The following code snippet is used to dynamically disable the feature:
58
59    ```cpp
60    OH_AVFormat *format = OH_AVFormat_Create();
61    OH_AVFormat_SetIntValue(format, OH_MD_KEY_VIDEO_DECODER_OUTPUT_ENABLE_VRR, 0);
62    OH_VideoDecoder_SetParameter(videoDec, format);
63    OH_AVFormat_Destroy(format);
64    ```
65
66    The following code snippet is used to dynamically enable the feature:
67
68    ```cpp
69    OH_AVFormat *format = OH_AVFormat_Create();
70    OH_AVFormat_SetIntValue(format, OH_MD_KEY_FRAME_RATE, fps);
71    OH_AVFormat_SetIntValue(format, OH_MD_KEY_VIDEO_DECODER_OUTPUT_ENABLE_VRR, 1);
72    OH_VideoDecoder_SetParameter(videoDec, format);
73    OH_AVFormat_Destroy(format);
74    ```
75