[FFmpeg-devel] [PATCH] lavc/hevc Parse SEI_TYPE_MASTERING_DISPLAY_INFO and propagate contents into the AVMasteringDisplayMetadata side data.

Neil Birkbeck neil.birkbeck at gmail.com
Fri Jan 22 00:57:38 CET 2016


Thanks for the quick review, Michael.

The display primaries are encoded as integers (rational with fixed
denominator, I guess) in h265 and HDMI InfoFrames (but in mkv extensions,
they will be floats). Float is sufficient to represent the 16-bit integer
encoding from hevc, so suspect there is not much gain in going more precise
(this info is used as hints when tone mapping from a wider color gamut to a
narrower one).

Regarding the ints, you're correct, we should just use unsigned.

On Thu, Jan 21, 2016 at 3:39 PM, Michael Niedermayer <michael at niedermayer.cc
> wrote:

> On Thu, Jan 21, 2016 at 02:26:39PM -0800, Neil Birkbeck wrote:
> > Add support for parsing SEI_TYPE_MASTERING_DISPLAY_INFO and propagate
> contents into
> > the AVMasteringDisplayMetadata side data. Primaries are ordered in RGB
> order and
> > the values are converted to the natural ranges ([0,1] for CEI 1931
> Chroma coords,
> > and cd/m^2 for luma).
> >
> > Signed-off-by: Neil Birkbeck <neil.birkbeck at gmail.com>
> > ---
> >  libavcodec/hevc.c     | 38 ++++++++++++++++++++++++++++++++++++++
> >  libavcodec/hevc.h     |  7 +++++++
> >  libavcodec/hevc_sei.c | 22 ++++++++++++++++++++++
> >  3 files changed, 67 insertions(+)
> >
> > diff --git a/libavcodec/hevc.c b/libavcodec/hevc.c
> > index c245d3b..98cc6f7 100644
> > --- a/libavcodec/hevc.c
> > +++ b/libavcodec/hevc.c
> > @@ -28,6 +28,7 @@
> >  #include "libavutil/common.h"
> >  #include "libavutil/display.h"
> >  #include "libavutil/internal.h"
> > +#include "libavutil/mastering_display_metadata.h"
> >  #include "libavutil/md5.h"
> >  #include "libavutil/opt.h"
> >  #include "libavutil/pixdesc.h"
> > @@ -2580,6 +2581,43 @@ static int set_side_data(HEVCContext *s)
> >                                 s->sei_hflip, s->sei_vflip);
> >      }
> >
> > +    if (s->sei_mastering_display_info_present) {
> > +        // HEVC uses a g,b,r ordering, which we convert to a more
> natural r,g,b
> > +        const int mapping[3] = {2, 0, 1};
> > +        const float chroma_scale = 50000.f;
> > +        const float luma_scale = 10000.f;
> > +        int i;
> > +        AVMasteringDisplayMetadata *metadata =
> > +            av_mastering_display_metadata_create_side_data(out);
> > +        if (!metadata)
> > +            return AVERROR(ENOMEM);
> > +
> > +        for (i = 0; i < 3; i++) {
> > +            const int j = mapping[i];
> > +            metadata->display_primaries[i][0] =
> > +                s->display_primaries[j][0] / chroma_scale;
> > +            metadata->display_primaries[i][1] =
> > +                s->display_primaries[j][1] / chroma_scale;
> > +        }
>
> Are display_primaries always rational numbers ?
> if so maybe they should be changed to use AVRational
>
> avoiding floats would also make things bit exact across architectures
> (without the need for luck)
>
> the same applies to other rational fields
>
> [...]
>
> >      uint8_t* a53_caption;
> > diff --git a/libavcodec/hevc_sei.c b/libavcodec/hevc_sei.c
> > index 07856f2..095c658 100644
> > --- a/libavcodec/hevc_sei.c
> > +++ b/libavcodec/hevc_sei.c
> > @@ -78,6 +78,26 @@ static int
> decode_nal_sei_decoded_picture_hash(HEVCContext *s)
> >      return 0;
> >  }
> >
> > +static int decode_nal_sei_mastering_display_info(HEVCContext *s)
> > +{
> > +    GetBitContext *gb = &s->HEVClc->gb;
> > +    int i;
> > +    // Mastering primaries
> > +    for (i = 0; i < 3; i++) {
> > +        s->display_primaries[i][0] = get_bits(gb, 16);
> > +        s->display_primaries[i][1] = get_bits(gb, 16);
> > +    }
> > +    // White point (x, y)
> > +    s->white_point[0] = get_bits(gb, 16);
> > +    s->white_point[1] = get_bits(gb, 16);
> > +
> > +    // Max and min luminance of mastering display
>
> > +    s->max_mastering_luminance = get_bits(gb, 32);
> > +    s->min_mastering_luminance = get_bits(gb, 32);
>
> 32 needs get_bits_long()
>
> also the variables are signed int, is that intended
>
> [...]
> --
> Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
>
> I have often repented speaking, but never of holding my tongue.
> -- Xenocrates
>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
>
>


More information about the ffmpeg-devel mailing list