How can I add the following HDR options to a video encoder written in C , using av_opt_set or similar ?
ffmpeg -i GlassBlowingUHD.mp4 -map 0 -c:v libx265 -x265-params hdr-opt=1:repeat-headers=1:colorprim=bt2020:transfer=smpte2084:colormatrix=bt2020nc:master-display=G(8500,39850)B(6550,2300)R(35400,14600)WP(15635,16450)L(40000000,50):max-cll=0,0 -crf 20 -preset veryfast -pix_fmt yuv420p10le GlassBlowingConverted.mkv
Currently I have successfully used av_opt_set to set the "crf" option, so it works, but I'm not sure how to add these ones:
-x265-params hdr-opt=1:repeat-headers=1:colorprim=bt2020:transfer=smpte2084:colormatrix=bt2020nc:master-display=G(8500,39850)B(6550,2300)R(35400,14600)WP(15635,16450)L(40000000,50):max-cll=0,0
This is a snippet of my code and how I use it:
AVCodecContext* cctx;
cctx = avcodec_alloc_context3(vcodec);
cctx->width = dst_width;
cctx->height = dst_height;
cctx->pix_fmt = output_scaler_pixel_format;
cctx->time_base = av_inv_q(dst_fps);
cctx->framerate = dst_fps;
av_opt_set(cctx->priv_data, "crf", "20", AV_OPT_SEARCH_CHILDREN);
It is worth mentioning that I did add some of the options with visible succes, such as the color-space, directly through the CodecContext properties.
cctx->colorspace = AVCOL_SPC_BT2020_NCL;
cctx->color_trc = AVCOL_TRC_SMPTE2084;
cctx->color_primaries = AVCOL_PRI_BT2020;
I have also tried using av_set_options_string, but no luck.
av_set_options_string(cctx->priv_data, "hdr-opt=1:repeat-headers=1:colorprim=bt2020:transfer=smpte2084:colormatrix=bt2020nc:master-display=G(8500,39850)B(6550,2300)R(35400,14600)WP(15635,16450)L(40000000,50):max-cll=0,0", "=", ":");
CodePudding user response:
The option name is x265_params, and its value is its arg.
av_opt_set(cctx->priv_data, "x265-params", "hdr-opt=1:repeat-headers=1:colorprim=bt2020:transfer=smpte2084:colormatrix=bt2020nc:master-display=G(8500,39850)B(6550,2300)R(35400,14600)WP(15635,16450)L(40000000,50):max-cll=0,0", AV_OPT_SEARCH_CHILDREN);