History

avcodec/amfenc: add 10 bit encoding in av1_amf

v2: refactored after review

Evgeny Pavlov committed 2 years ago

Commit 9f024081 parent 62876202 files · +29 −1Browse files

Showing the changes to libavcodec (2 of 2 files). Show all

Unified · Split

2 files
  1. libavcodec/amfenc.c +2 −0
  2. libavcodec/amfenc_av1.c +27 −1
libavcodec/amfenc.c+2−0
@@ -746,6 +746,8 @@ int ff_amf_receive_packet(AVCodecContext *avctx, AVPacket *avpkt) · 745 unmodified lines
746746 AMF_ASSIGN_PROPERTY_INTERFACE(res, ctx->encoder, AMF_VIDEO_ENCODER_INPUT_HDR_METADATA, hdrmeta_buffer); break;
747747 case AV_CODEC_ID_HEVC:
748748 AMF_ASSIGN_PROPERTY_INTERFACE(res, ctx->encoder, AMF_VIDEO_ENCODER_HEVC_INPUT_HDR_METADATA, hdrmeta_buffer); break;
749+ case AV_CODEC_ID_AV1:
750+ AMF_ASSIGN_PROPERTY_INTERFACE(res, ctx->encoder, AMF_VIDEO_ENCODER_AV1_INPUT_HDR_METADATA, hdrmeta_buffer); break;
749751 }
750752 res = amf_set_property_buffer(surface, L"av_frame_hdrmeta", hdrmeta_buffer);
751753 AMF_RETURN_IF_FALSE(avctx, res == AMF_OK, AVERROR_UNKNOWN, "SetProperty failed for \"av_frame_hdrmeta\" with error %d\n", res);
libavcodec/amfenc_av1.c+27−1
@@ -185,7 +185,9 @@ static av_cold int amf_encode_init_av1(AVCodecContext* avctx) · 184 unmodified lines
185185 AMFGuid guid;
186186 AMFRate framerate;
187187 AMFSize framesize = AMFConstructSize(avctx->width, avctx->height);
188−
188+ amf_int64 color_depth;
189+ amf_int64 color_profile;
190+ enum AVPixelFormat pix_fmt;
189191
190192 //for av1 alignment and crop
191193 uint32_t crop_right = 0;
@@ -235,6 +237,30 @@ FF_ENABLE_DEPRECATION_WARNINGS · 43 unmodified lines
235237 AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, AMF_VIDEO_ENCODER_AV1_PROFILE, profile);
236238 }
237239
240+ /// Color profile
241+ color_profile = ff_amf_get_color_profile(avctx);
242+ AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, AMF_VIDEO_ENCODER_AV1_OUTPUT_COLOR_PROFILE, color_profile);
243+
244+ /// Color Depth
245+ pix_fmt = avctx->hw_frames_ctx ? ((AVHWFramesContext*)avctx->hw_frames_ctx->data)->sw_format
246+ : avctx->pix_fmt;
247+ color_depth = AMF_COLOR_BIT_DEPTH_8;
248+ if (pix_fmt == AV_PIX_FMT_P010) {
249+ color_depth = AMF_COLOR_BIT_DEPTH_10;
250+ }
251+
252+ AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, AMF_VIDEO_ENCODER_AV1_COLOR_BIT_DEPTH, color_depth);
253+ AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, AMF_VIDEO_ENCODER_AV1_OUTPUT_COLOR_PROFILE, color_profile);
254+ if (color_depth == AMF_COLOR_BIT_DEPTH_8) {
255+ /// Color Transfer Characteristics (AMF matches ISO/IEC)
256+ AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, AMF_VIDEO_ENCODER_AV1_OUTPUT_TRANSFER_CHARACTERISTIC, AMF_COLOR_TRANSFER_CHARACTERISTIC_BT709);
257+ /// Color Primaries (AMF matches ISO/IEC)
258+ AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, AMF_VIDEO_ENCODER_AV1_OUTPUT_COLOR_PRIMARIES, AMF_COLOR_PRIMARIES_BT709);
259+ } else {
260+ AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, AMF_VIDEO_ENCODER_AV1_OUTPUT_TRANSFER_CHARACTERISTIC, AMF_COLOR_TRANSFER_CHARACTERISTIC_SMPTE2084);
261+ AMF_ASSIGN_PROPERTY_INT64(res, ctx->encoder, AMF_VIDEO_ENCODER_AV1_OUTPUT_COLOR_PRIMARIES, AMF_COLOR_PRIMARIES_BT2020);
262+ }
263+
238264 profile_level = avctx->level;
239265 if (profile_level == AV_LEVEL_UNKNOWN) {
240266 profile_level = ctx->level;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t