diff --git a/plugins/obs-ffmpeg/obs-ffmpeg-vaapi.c b/plugins/obs-ffmpeg/obs-ffmpeg-vaapi.c index 420091d2d..ee0e5571f 100644 --- a/plugins/obs-ffmpeg/obs-ffmpeg-vaapi.c +++ b/plugins/obs-ffmpeg/obs-ffmpeg-vaapi.c @@ -145,8 +145,7 @@ static bool vaapi_init_codec(struct vaapi_encoder *enc, const char *path) enc->vframe->height = enc->context->height; enc->vframe->colorspace = enc->context->colorspace; enc->vframe->color_range = enc->context->color_range; - enc->vframe->chroma_location = determine_chroma_location( - enc->context->pix_fmt, enc->context->colorspace); + enc->vframe->chroma_location = enc->context->chroma_sample_location; ret = av_frame_get_buffer(enc->vframe, base_get_alignment()); if (ret < 0) { @@ -253,30 +252,37 @@ static bool vaapi_update(void *data, obs_data_t *settings) enc->context->height = obs_encoder_get_height(enc->encoder); enc->context->time_base = (AVRational){voi->fps_den, voi->fps_num}; - enc->context->pix_fmt = obs_to_ffmpeg_video_format(info.format); + const enum AVPixelFormat pix_fmt = + obs_to_ffmpeg_video_format(info.format); + enc->context->pix_fmt = pix_fmt; enc->context->color_range = info.range == VIDEO_RANGE_FULL ? AVCOL_RANGE_JPEG : AVCOL_RANGE_MPEG; + enum AVColorSpace colorspace = AVCOL_SPC_UNSPECIFIED; switch (info.colorspace) { case VIDEO_CS_601: enc->context->color_trc = AVCOL_TRC_SMPTE170M; enc->context->color_primaries = AVCOL_PRI_SMPTE170M; - enc->context->colorspace = AVCOL_SPC_SMPTE170M; + colorspace = AVCOL_SPC_SMPTE170M; break; case VIDEO_CS_DEFAULT: case VIDEO_CS_709: enc->context->color_trc = AVCOL_TRC_BT709; enc->context->color_primaries = AVCOL_PRI_BT709; - enc->context->colorspace = AVCOL_SPC_BT709; + colorspace = AVCOL_SPC_BT709; break; case VIDEO_CS_SRGB: enc->context->color_trc = AVCOL_TRC_IEC61966_2_1; enc->context->color_primaries = AVCOL_PRI_BT709; - enc->context->colorspace = AVCOL_SPC_BT709; + colorspace = AVCOL_SPC_BT709; break; } + enc->context->colorspace = colorspace; + enc->context->chroma_sample_location = + determine_chroma_location(pix_fmt, colorspace); + if (keyint_sec > 0) { enc->context->gop_size = keyint_sec * voi->fps_num / voi->fps_den;