[FFmpeg-devel] [PATCH] avcodec/videotoolboxenc: add CBP/CHP profile

Rick Kern kernrj at gmail.com
Sun May 21 16:07:12 EEST 2023


On Sun, May 21, 2023 at 7:22 AM xufuji456 <839789740 at qq.com> wrote:

> The CBP/CHP profile has available with H264 in iOS 15.0.
> Official Doc:
> https://developer.apple.com/documentation/videotoolbox/kvtprofilelevel_h264_constrainedbaseline_autolevel
>
> Signed-off-by: xufuji456 <839789740 at qq.com>
> ---
>  libavcodec/videotoolboxenc.c | 24 ++++++++++++++++++++++--
>  1 file changed, 22 insertions(+), 2 deletions(-)
>
> diff --git a/libavcodec/videotoolboxenc.c b/libavcodec/videotoolboxenc.c
> index b017c90c36..6a9b19831b 100644
> --- a/libavcodec/videotoolboxenc.c
> +++ b/libavcodec/videotoolboxenc.c
> @@ -108,6 +108,8 @@ static struct{
>      CFStringRef kVTProfileLevel_H264_High_AutoLevel;
>      CFStringRef kVTProfileLevel_H264_Extended_5_0;
>      CFStringRef kVTProfileLevel_H264_Extended_AutoLevel;
> +    CFStringRef kVTProfileLevel_H264_ConstrainedBaseline_AutoLevel;
> +    CFStringRef kVTProfileLevel_H264_ConstrainedHigh_AutoLevel;
>
>      CFStringRef kVTProfileLevel_HEVC_Main_AutoLevel;
>      CFStringRef kVTProfileLevel_HEVC_Main10_AutoLevel;
> @@ -171,6 +173,8 @@ static void loadVTEncSymbols(void){
>      GET_SYM(kVTProfileLevel_H264_High_AutoLevel,
>  "H264_High_AutoLevel");
>      GET_SYM(kVTProfileLevel_H264_Extended_5_0,       "H264_Extended_5_0");
>      GET_SYM(kVTProfileLevel_H264_Extended_AutoLevel,
> "H264_Extended_AutoLevel");
> +    GET_SYM(kVTProfileLevel_H264_ConstrainedBaseline_AutoLevel,
> "H264_ConstrainedBaseline_AutoLevel");
> +    GET_SYM(kVTProfileLevel_H264_ConstrainedHigh_AutoLevel,
>  "H264_ConstrainedHigh_AutoLevel");
>
>      GET_SYM(kVTProfileLevel_HEVC_Main_AutoLevel,
>  "HEVC_Main_AutoLevel");
>      GET_SYM(kVTProfileLevel_HEVC_Main10_AutoLevel,
>  "HEVC_Main10_AutoLevel");
> @@ -743,8 +747,15 @@ static bool get_vt_h264_profile_level(AVCodecContext
> *avctx,
>
>          case H264_PROF_BASELINE:
>              switch (vtctx->level) {
> -                case  0: *profile_level_val =
> -
> compat_keys.kVTProfileLevel_H264_Baseline_AutoLevel; break;
> +                case  0: {
> +                    // check avctx->profile has been set
> constrained_baseline
> +                    if (avctx->profile ==
> FF_PROFILE_H264_CONSTRAINED_BASELINE) {
>
The profiles need to be added to the list of usable profiles in
h264_options so they can be used on the command line.

Using the FF_PROFILE_ constants doesn't follow the pattern of using the
profile constants defined in this file, but I like your approach better. To
keep things consistent, either remove the constants in VT_H264Profile and
VT_HEVCProfile and replace them with global constants, or I can follow up
with a patch.


> +                        *profile_level_val =
> compat_keys.kVTProfileLevel_H264_ConstrainedBaseline_AutoLevel;
> +                    } else {
> +                        *profile_level_val =
> compat_keys.kVTProfileLevel_H264_Baseline_AutoLevel;
> +                    }
> +                    break;
> +                }
>                  case 13: *profile_level_val =
> kVTProfileLevel_H264_Baseline_1_3;       break;
>                  case 30: *profile_level_val =
> kVTProfileLevel_H264_Baseline_3_0;       break;
>                  case 31: *profile_level_val =
> kVTProfileLevel_H264_Baseline_3_1;       break;
> @@ -784,6 +795,15 @@ static bool get_vt_h264_profile_level(AVCodecContext
> *avctx,
>
>          case H264_PROF_HIGH:
>              switch (vtctx->level) {
> +                case  0: {
> +                    // check avctx->profile has been set constrained_high
> +                    if (avctx->profile == (FF_PROFILE_H264_HIGH |
> FF_PROFILE_H264_CONSTRAINED)) {
> +                        *profile_level_val =
> compat_keys.kVTProfileLevel_H264_ConstrainedHigh_AutoLevel;
> +                    } else {
> +                        *profile_level_val =
> compat_keys.kVTProfileLevel_H264_High_AutoLevel;
> +                    }
> +                    break;
> +                }
>                  case  0: *profile_level_val =
>
>  compat_keys.kVTProfileLevel_H264_High_AutoLevel; break;
>
This duplicate case 0 can be removed.

                 case 30: *profile_level_val =
> --
> 2.32.0 (Apple Git-132)
>
>


More information about the ffmpeg-devel mailing list