History

avcodec/libx265: implement dolby vision coding

libx265 supports these natively, we just need to attach the generated NALs to the x265picture, as well as setting the appropriate DV profile.

Niklas Haas committed 2 years ago

Commit 39ca87e1 parent 8dea94a2 files · +41 −1Browse files

Unified · Split

2 files
  1. configure +1 −1
  2. libavcodec/libx265.c +40 −0
configure+1−1
@@ -3553,7 +3553,7 @@ libx264_encoder_select="atsc_a53 golomb" · 3552 unmodified lines
3553libx264rgb_encoder_deps="libx264"3553libx264rgb_encoder_deps="libx264"
3554libx264rgb_encoder_select="libx264_encoder"3554libx264rgb_encoder_select="libx264_encoder"
3555libx265_encoder_deps="libx265"3555libx265_encoder_deps="libx265"
3556libx265_encoder_select="atsc_a53"3556libx265_encoder_select="atsc_a53 dovi_rpueenc"
3557libxavs_encoder_deps="libxavs"3557libxavs_encoder_deps="libxavs"
3558libxavs2_encoder_deps="libxavs2"3558libxavs2_encoder_deps="libxavs2"
3559libxevd_decoder_deps="libxevd"3559libxevd_decoder_deps="libxevd"
libavcodec/libx265.c+40−0
@@ -36,6 +36,7 @@ · 35 unmodified lines
36#include "libavutil/pixdesc.h"36#include "libavutil/pixdesc.h"
37#include "avcodec.h"37#include "avcodec.h"
38#include "codec_internal.h"38#include "codec_internal.h"
39#include "dovi_rpu.h"
39#include "encode.h"40#include "encode.h"
40#include "packet_internal.h"41#include "packet_internal.h"
41#include "atsc_a53.h"42#include "atsc_a53.h"
@@ -78,6 +79,8 @@ typedef struct libx265Context { · 36 unmodified lines
78 * encounter a frame with ROI side data.79 * encounter a frame with ROI side data.
79 */80 */
80 int roi_warned;81 int roi_warned;
82
83 DOVIContext dovi;
81} libx265Context;84} libx265Context;
82 85
83static int is_keyframe(NalUnitType naltype)86static int is_keyframe(NalUnitType naltype)
@@ -143,6 +146,8 @@ static av_cold int libx265_encode_close(AVCodecContext *avctx) · 59 unmodified lines
143 if (ctx->encoder)146 if (ctx->encoder)
144 ctx->api->encoder_close(ctx->encoder);147 ctx->api->encoder_close(ctx->encoder);
145 148
149 ff_dovi_ctx_unref(&ctx->dovi);
150
146 return 0;151 return 0;
147}152}
148 153
@@ -526,6 +531,14 @@ FF_ENABLE_DEPRECATION_WARNINGS · 377 unmodified lines
526 }531 }
527 }532 }
528 533
534#if X265_BUILD >= 167
535 ctx->dovi.logctx = avctx;
536 if ((ret = ff_dovi_configure(&ctx->dovi, avctx)) < 0)
537 return ret;
538 ctx->params->dolbyProfile = ctx->dovi.cfg.dv_profile * 10 +
539 ctx->dovi.cfg.dv_bl_signal_compatibility_id;
540#endif
541
529 ctx->encoder = ctx->api->encoder_open(ctx->params);542 ctx->encoder = ctx->api->encoder_open(ctx->params);
530 if (!ctx->encoder) {543 if (!ctx->encoder) {
531 av_log(avctx, AV_LOG_ERROR, "Cannot open libx265 encoder.\n");544 av_log(avctx, AV_LOG_ERROR, "Cannot open libx265 encoder.\n");
@@ -629,6 +642,10 @@ static void free_picture(libx265Context *ctx, x265_picture *pic) · 97 unmodified lines
629 for (int i = 0; i < sei->numPayloads; i++)642 for (int i = 0; i < sei->numPayloads; i++)
630 av_free(sei->payloads[i].payload);643 av_free(sei->payloads[i].payload);
631 644
645#if X265_BUILD >= 167
646 av_free(pic->rpu.payload);
647#endif
648
632 if (pic->userData) {649 if (pic->userData) {
633 int idx = (int)(intptr_t)pic->userData - 1;650 int idx = (int)(intptr_t)pic->userData - 1;
634 rd_release(ctx, idx);651 rd_release(ctx, idx);
@@ -660,6 +677,7 @@ static int libx265_encode_frame(AVCodecContext *avctx, AVPacket *pkt, · 25 unmodified lines
660 sei->numPayloads = 0;677 sei->numPayloads = 0;
661 678
662 if (pic) {679 if (pic) {
680 AVFrameSideData *sd;
663 ReorderedData *rd;681 ReorderedData *rd;
664 int rd_idx;682 int rd_idx;
665 683
@@ -760,6 +778,24 @@ static int libx265_encode_frame(AVCodecContext *avctx, AVPacket *pkt, · 94 unmodified lines
760 sei->numPayloads++;778 sei->numPayloads++;
761 }779 }
762 }780 }
781
782#if X265_BUILD >= 167
783 sd = av_frame_get_side_data(pic, AV_FRAME_DATA_DOVI_METADATA);
784 if (ctx->dovi.cfg.dv_profile && sd) {
785 const AVDOVIMetadata *metadata = (const AVDOVIMetadata *)sd->data;
786 ret = ff_dovi_rpu_generate(&ctx->dovi, metadata, &x265pic.rpu.payload,
787 &x265pic.rpu.payloadSize);
788 if (ret < 0) {
789 free_picture(ctx, &x265pic);
790 return ret;
791 }
792 } else if (ctx->dovi.cfg.dv_profile) {
793 av_log(avctx, AV_LOG_ERROR, "Dolby Vision enabled, but received frame "
794 "without AV_FRAME_DATA_DOVI_METADATA");
795 free_picture(ctx, &x265pic);
796 return AVERROR_INVALIDDATA;
797 }
798#endif
763 }799 }
764 800
765 ret = ctx->api->encoder_encode(ctx->encoder, &nal, &nnal,801 ret = ctx->api->encoder_encode(ctx->encoder, &nal, &nnal,
@@ -914,6 +950,10 @@ static const AVOption options[] = { · 148 unmodified lines
914 { "udu_sei", "Use user data unregistered SEI if available", OFFSET(udu_sei), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },950 { "udu_sei", "Use user data unregistered SEI if available", OFFSET(udu_sei), AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
915 { "a53cc", "Use A53 Closed Captions (if available)", OFFSET(a53_cc), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, VE },951 { "a53cc", "Use A53 Closed Captions (if available)", OFFSET(a53_cc), AV_OPT_TYPE_BOOL, { .i64 = 1 }, 0, 1, VE },
916 { "x265-params", "set the x265 configuration using a :-separated list of key=value parameters", OFFSET(x265_opts), AV_OPT_TYPE_DICT, { 0 }, 0, 0, VE },952 { "x265-params", "set the x265 configuration using a :-separated list of key=value parameters", OFFSET(x265_opts), AV_OPT_TYPE_DICT, { 0 }, 0, 0, VE },
953#if X265_BUILD >= 167
954 { "dolbyvision", "Enable Dolby Vision RPU coding", OFFSET(dovi.enable), AV_OPT_TYPE_BOOL, {.i64 = FF_DOVI_AUTOMATIC }, -1, 1, VE, .unit = "dovi" },
955 { "auto", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_DOVI_AUTOMATIC}, .flags = VE, .unit = "dovi" },
956#endif
917 { NULL }957 { NULL }
918};958};
919 959

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