Allow setting the mode explicitly, and try to make a sensible choice given the available parameters if not.
Showing the changes to libavcodec/vaapi_encode.h (1 of 3 files). Show all
Unified · Split
| @@ -129,6 +129,36 @@ typedef struct VAAPIEncodeProfile { · 128 unmodified lines | |||
| 129 | VAProfile va_profile; | 129 | VAProfile va_profile; |
| 130 | } VAAPIEncodeProfile; | 130 | } VAAPIEncodeProfile; |
| 131 | 131 | ||
| 132 | enum { | ||
| 133 | RC_MODE_AUTO, | ||
| 134 | RC_MODE_CQP, | ||
| 135 | RC_MODE_CBR, | ||
| 136 | RC_MODE_VBR, | ||
| 137 | RC_MODE_ICQ, | ||
| 138 | RC_MODE_QVBR, | ||
| 139 | RC_MODE_AVBR, | ||
| 140 | RC_MODE_MAX = RC_MODE_AVBR, | ||
| 141 | }; | ||
| 142 | |||
| 143 | typedef struct VAAPIEncodeRCMode { | ||
| 144 | // Mode from above enum (RC_MODE_*). | ||
| 145 | int mode; | ||
| 146 | // Name. | ||
| 147 | const char *name; | ||
| 148 | // Supported in the compile-time VAAPI version. | ||
| 149 | int supported; | ||
| 150 | // VA mode value (VA_RC_*). | ||
| 151 | uint32_t va_mode; | ||
| 152 | // Uses bitrate parameters. | ||
| 153 | int bitrate; | ||
| 154 | // Supports maxrate distinct from bitrate. | ||
| 155 | int maxrate; | ||
| 156 | // Uses quality value. | ||
| 157 | int quality; | ||
| 158 | // Supports HRD/VBV parameters. | ||
| 159 | int hrd; | ||
| 160 | } VAAPIEncodeRCMode; | ||
| 161 | |||
| 132 | typedef struct VAAPIEncodeContext { | 162 | typedef struct VAAPIEncodeContext { |
| 133 | const AVClass *class; | 163 | const AVClass *class; |
| 134 | 164 | ||
| @@ -146,6 +176,14 @@ typedef struct VAAPIEncodeContext { · 11 unmodified lines | |||
| 146 | // Desired B frame reference depth. | 176 | // Desired B frame reference depth. |
| 147 | int desired_b_depth; | 177 | int desired_b_depth; |
| 148 | 178 | ||
| 179 | // Explicitly set RC mode (otherwise attempt to pick from | ||
| 180 | // available modes). | ||
| 181 | int explicit_rc_mode; | ||
| 182 | |||
| 183 | // Explicitly-set QP, for use with the "qp" options. | ||
| 184 | // (Forces CQP mode when set, overriding everything else.) | ||
| 185 | int explicit_qp; | ||
| 186 | |||
| 149 | // Desired packed headers. | 187 | // Desired packed headers. |
| 150 | unsigned int desired_packed_headers; | 188 | unsigned int desired_packed_headers; |
| 151 | 189 | ||
| @@ -165,6 +203,12 @@ typedef struct VAAPIEncodeContext { · 13 unmodified lines | |||
| 165 | // Chosen encoding profile details. | 203 | // Chosen encoding profile details. |
| 166 | const VAAPIEncodeProfile *profile; | 204 | const VAAPIEncodeProfile *profile; |
| 167 | 205 | ||
| 206 | // Chosen rate control mode details. | ||
| 207 | const VAAPIEncodeRCMode *rc_mode; | ||
| 208 | // RC quality level - meaning depends on codec and RC mode. | ||
| 209 | // In CQP mode this sets the fixed quantiser value. | ||
| 210 | int rc_quality; | ||
| 211 | |||
| 168 | // Encoding profile (VAProfile*). | 212 | // Encoding profile (VAProfile*). |
| 169 | VAProfile va_profile; | 213 | VAProfile va_profile; |
| 170 | // Encoding entrypoint (VAEntryoint*). | 214 | // Encoding entrypoint (VAEntryoint*). |
| @@ -296,6 +340,10 @@ typedef struct VAAPIEncodeType { · 125 unmodified lines | |||
| 296 | // Codec feature flags. | 340 | // Codec feature flags. |
| 297 | int flags; | 341 | int flags; |
| 298 | 342 | ||
| 343 | // Default quality for this codec - used as quantiser or RC quality | ||
| 344 | // factor depending on RC mode. | ||
| 345 | int default_quality; | ||
| 346 | |||
| 299 | // Perform any extra codec-specific configuration after the | 347 | // Perform any extra codec-specific configuration after the |
| 300 | // codec context is initialised (set up the private data and | 348 | // codec context is initialised (set up the private data and |
| 301 | // add any necessary global parameters). | 349 | // add any necessary global parameters). |
| @@ -382,5 +430,22 @@ int ff_vaapi_encode_close(AVCodecContext *avctx); · 80 unmodified lines | |||
| 382 | OFFSET(common.desired_b_depth), AV_OPT_TYPE_INT, \ | 430 | OFFSET(common.desired_b_depth), AV_OPT_TYPE_INT, \ |
| 383 | { .i64 = 1 }, 1, INT_MAX, FLAGS } | 431 | { .i64 = 1 }, 1, INT_MAX, FLAGS } |
| 384 | 432 | ||
| 433 | #define VAAPI_ENCODE_RC_MODE(name, desc) \ | ||
| 434 | { #name, desc, 0, AV_OPT_TYPE_CONST, { .i64 = RC_MODE_ ## name }, \ | ||
| 435 | 0, 0, FLAGS, "rc_mode" } | ||
| 436 | #define VAAPI_ENCODE_RC_OPTIONS \ | ||
| 437 | { "rc_mode",\ | ||
| 438 | "Set rate control mode", \ | ||
| 439 | OFFSET(common.explicit_rc_mode), AV_OPT_TYPE_INT, \ | ||
| 440 | { .i64 = RC_MODE_AUTO }, RC_MODE_AUTO, RC_MODE_MAX, FLAGS, "rc_mode" }, \ | ||
| 441 | { "auto", "Choose mode automatically based on other parameters", \ | ||
| 442 | 0, AV_OPT_TYPE_CONST, { .i64 = RC_MODE_AUTO }, 0, 0, FLAGS, "rc_mode" }, \ | ||
| 443 | VAAPI_ENCODE_RC_MODE(CQP, "Constant-quality"), \ | ||
| 444 | VAAPI_ENCODE_RC_MODE(CBR, "Constant-bitrate"), \ | ||
| 445 | VAAPI_ENCODE_RC_MODE(VBR, "Variable-bitrate"), \ | ||
| 446 | VAAPI_ENCODE_RC_MODE(ICQ, "Intelligent constant-quality"), \ | ||
| 447 | VAAPI_ENCODE_RC_MODE(QVBR, "Quality-defined variable-bitrate"), \ | ||
| 448 | VAAPI_ENCODE_RC_MODE(AVBR, "Average variable-bitrate") | ||
| 449 | |||
| 385 | 450 | ||
| 386 | #endif /* AVCODEC_VAAPI_ENCODE_H */ | 451 | #endif /* AVCODEC_VAAPI_ENCODE_H */ |