[FFmpeg-devel] avcodec/mpeg4videodec: Add support for parsing and exporting video_range

Submitted by Michael Niedermayer on Dec. 10, 2017, 3:20 p.m.

Details

Message ID 20171210152014.30802-1-michael@niedermayer.cc
State New
Headers show

Commit Message

Michael Niedermayer Dec. 10, 2017, 3:20 p.m.
Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
---
 libavcodec/mpeg4video.h    |  3 +++
 libavcodec/mpeg4videodec.c | 32 ++++++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+)

Comments

Mark Thompson Dec. 10, 2017, 7:56 p.m.
On 10/12/17 15:20, Michael Niedermayer wrote:
> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> ---
>  libavcodec/mpeg4video.h    |  3 +++
>  libavcodec/mpeg4videodec.c | 32 ++++++++++++++++++++++++++++++++
>  2 files changed, 35 insertions(+)
> 
> diff --git a/libavcodec/mpeg4video.h b/libavcodec/mpeg4video.h
> index 515b008ae4..0ba502d50b 100644
> --- a/libavcodec/mpeg4video.h
> +++ b/libavcodec/mpeg4video.h
> @@ -43,6 +43,9 @@
>  #define ACE_VO_TYPE             12
>  #define ADV_SIMPLE_VO_TYPE      17
>  
> +#define VOT_VIDEO_ID 1
> +#define VOT_STILL_TEXTURE_ID 2
> +
>  // aspect_ratio_info
>  #define EXTENDED_PAR 15
>  
> diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
> index cdd7077f01..852f73f02c 100644
> --- a/libavcodec/mpeg4videodec.c
> +++ b/libavcodec/mpeg4videodec.c
> @@ -1751,6 +1751,36 @@ static int mpeg4_decode_profile_level(MpegEncContext *s, GetBitContext *gb)
>          s->avctx->level = 0;
>      }
>  
> +    return 0;
> +

Stray newline.

> +}
> +
> +static int mpeg4_decode_visual_object(MpegEncContext *s, GetBitContext *gb)
> +{
> +    int visual_object_type;
> +    int is_visual_object_identifier = get_bits1(gb);
> +
> +    if (is_visual_object_identifier) {
> +        skip_bits(gb, 4+3);
> +    }
> +    visual_object_type = get_bits(gb, 4);
> +
> +    if (visual_object_type == VOT_VIDEO_ID ||
> +        visual_object_type == VOT_STILL_TEXTURE_ID) {
> +        int video_signal_type = get_bits1(gb);
> +        if (video_signal_type) {
> +            int video_format = get_bits(gb, 3);
> +            int video_range = get_bits1(gb);
> +            int color_description = get_bits1(gb);
> +
> +            s->avctx->color_range = video_range ? AVCOL_RANGE_JPEG : AVCOL_RANGE_MPEG;
> +
> +            if (color_description) {
> +                skip_bits(gb, 8+8+8);

Might be nice to extract the colour information as well?  (Should be able to set color_primaries/color_trc/colorspace directly, I think.)

> +            }
> +        }
> +    }
> +
>      return 0;
>  }
>  
> @@ -2684,6 +2714,8 @@ int ff_mpeg4_decode_picture_header(Mpeg4DecContext *ctx, GetBitContext *gb)
>              mpeg4_decode_gop_header(s, gb);
>          } else if (startcode == VOS_STARTCODE) {
>              mpeg4_decode_profile_level(s, gb);
> +        } else if (startcode == VISUAL_OBJ_STARTCODE) {
> +            mpeg4_decode_visual_object(s, gb);
>          } else if (startcode == VOP_STARTCODE) {
>              break;
>          }
> 

LGTM.

Thanks,

- Mark
Michael Niedermayer Dec. 10, 2017, 9:49 p.m.
On Sun, Dec 10, 2017 at 07:56:49PM +0000, Mark Thompson wrote:
> On 10/12/17 15:20, Michael Niedermayer wrote:
> > Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> > ---
> >  libavcodec/mpeg4video.h    |  3 +++
> >  libavcodec/mpeg4videodec.c | 32 ++++++++++++++++++++++++++++++++
> >  2 files changed, 35 insertions(+)
> > 
> > diff --git a/libavcodec/mpeg4video.h b/libavcodec/mpeg4video.h
> > index 515b008ae4..0ba502d50b 100644
> > --- a/libavcodec/mpeg4video.h
> > +++ b/libavcodec/mpeg4video.h
> > @@ -43,6 +43,9 @@
> >  #define ACE_VO_TYPE             12
> >  #define ADV_SIMPLE_VO_TYPE      17
> >  
> > +#define VOT_VIDEO_ID 1
> > +#define VOT_STILL_TEXTURE_ID 2
> > +
> >  // aspect_ratio_info
> >  #define EXTENDED_PAR 15
> >  
> > diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
> > index cdd7077f01..852f73f02c 100644
> > --- a/libavcodec/mpeg4videodec.c
> > +++ b/libavcodec/mpeg4videodec.c
> > @@ -1751,6 +1751,36 @@ static int mpeg4_decode_profile_level(MpegEncContext *s, GetBitContext *gb)
> >          s->avctx->level = 0;
> >      }
> >  
> > +    return 0;
> > +
> 
> Stray newline.
> 
> > +}
> > +
> > +static int mpeg4_decode_visual_object(MpegEncContext *s, GetBitContext *gb)
> > +{
> > +    int visual_object_type;
> > +    int is_visual_object_identifier = get_bits1(gb);
> > +
> > +    if (is_visual_object_identifier) {
> > +        skip_bits(gb, 4+3);
> > +    }
> > +    visual_object_type = get_bits(gb, 4);
> > +
> > +    if (visual_object_type == VOT_VIDEO_ID ||
> > +        visual_object_type == VOT_STILL_TEXTURE_ID) {
> > +        int video_signal_type = get_bits1(gb);
> > +        if (video_signal_type) {
> > +            int video_format = get_bits(gb, 3);
> > +            int video_range = get_bits1(gb);
> > +            int color_description = get_bits1(gb);
> > +
> > +            s->avctx->color_range = video_range ? AVCOL_RANGE_JPEG : AVCOL_RANGE_MPEG;
> > +
> > +            if (color_description) {
> > +                skip_bits(gb, 8+8+8);
> 
> Might be nice to extract the colour information as well?  (Should be able to set color_primaries/color_trc/colorspace directly, I think.)

will look into this
btw, iam a bit short on samples that use this
i had found just one sample after a quick look
more samples would be welcome, if someone has some.


[...]

--
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

While the State exists there can be no freedom; when there is freedom there
will be no State. -- Vladimir Lenin
Mark Thompson Dec. 10, 2017, 10:19 p.m.
On 10/12/17 21:49, Michael Niedermayer wrote:
> On Sun, Dec 10, 2017 at 07:56:49PM +0000, Mark Thompson wrote:
>> On 10/12/17 15:20, Michael Niedermayer wrote:
>>> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
>>> ---
>>>  libavcodec/mpeg4video.h    |  3 +++
>>>  libavcodec/mpeg4videodec.c | 32 ++++++++++++++++++++++++++++++++
>>>  2 files changed, 35 insertions(+)
>>>
>>> diff --git a/libavcodec/mpeg4video.h b/libavcodec/mpeg4video.h
>>> index 515b008ae4..0ba502d50b 100644
>>> --- a/libavcodec/mpeg4video.h
>>> +++ b/libavcodec/mpeg4video.h
>>> @@ -43,6 +43,9 @@
>>>  #define ACE_VO_TYPE             12
>>>  #define ADV_SIMPLE_VO_TYPE      17
>>>  
>>> +#define VOT_VIDEO_ID 1
>>> +#define VOT_STILL_TEXTURE_ID 2
>>> +
>>>  // aspect_ratio_info
>>>  #define EXTENDED_PAR 15
>>>  
>>> diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
>>> index cdd7077f01..852f73f02c 100644
>>> --- a/libavcodec/mpeg4videodec.c
>>> +++ b/libavcodec/mpeg4videodec.c
>>> @@ -1751,6 +1751,36 @@ static int mpeg4_decode_profile_level(MpegEncContext *s, GetBitContext *gb)
>>>          s->avctx->level = 0;
>>>      }
>>>  
>>> +    return 0;
>>> +
>>
>> Stray newline.
>>
>>> +}
>>> +
>>> +static int mpeg4_decode_visual_object(MpegEncContext *s, GetBitContext *gb)
>>> +{
>>> +    int visual_object_type;
>>> +    int is_visual_object_identifier = get_bits1(gb);
>>> +
>>> +    if (is_visual_object_identifier) {
>>> +        skip_bits(gb, 4+3);
>>> +    }
>>> +    visual_object_type = get_bits(gb, 4);
>>> +
>>> +    if (visual_object_type == VOT_VIDEO_ID ||
>>> +        visual_object_type == VOT_STILL_TEXTURE_ID) {
>>> +        int video_signal_type = get_bits1(gb);
>>> +        if (video_signal_type) {
>>> +            int video_format = get_bits(gb, 3);
>>> +            int video_range = get_bits1(gb);
>>> +            int color_description = get_bits1(gb);
>>> +
>>> +            s->avctx->color_range = video_range ? AVCOL_RANGE_JPEG : AVCOL_RANGE_MPEG;
>>> +
>>> +            if (color_description) {
>>> +                skip_bits(gb, 8+8+8);
>>
>> Might be nice to extract the colour information as well?  (Should be able to set color_primaries/color_trc/colorspace directly, I think.)
> 
> will look into this
> btw, iam a bit short on samples that use this
> i had found just one sample after a quick look
> more samples would be welcome, if someone has some.

From a quick look around (run over some MPEG-4 samples with an abort in the above code) I can't find any examples of video_signal_type being set at all.  Minor thing I noticed in doing that - video_format is unused so you get a warning from the compiler: since it's not useful to anyone maybe replace it with skip_bits(3) and move the other stuff around to match that?

Don't block this because of the colour part if you don't have a sample of that - I just thought from reading the relevant part of the standard that it should be easy, but if noone has ever used it then whatever.

Thanks,

- Mark
Michael Niedermayer Dec. 21, 2017, 1:20 p.m.
On Sun, Dec 10, 2017 at 10:19:30PM +0000, Mark Thompson wrote:
> On 10/12/17 21:49, Michael Niedermayer wrote:
> > On Sun, Dec 10, 2017 at 07:56:49PM +0000, Mark Thompson wrote:
> >> On 10/12/17 15:20, Michael Niedermayer wrote:
> >>> Signed-off-by: Michael Niedermayer <michael@niedermayer.cc>
> >>> ---
> >>>  libavcodec/mpeg4video.h    |  3 +++
> >>>  libavcodec/mpeg4videodec.c | 32 ++++++++++++++++++++++++++++++++
> >>>  2 files changed, 35 insertions(+)
> >>>
> >>> diff --git a/libavcodec/mpeg4video.h b/libavcodec/mpeg4video.h
> >>> index 515b008ae4..0ba502d50b 100644
> >>> --- a/libavcodec/mpeg4video.h
> >>> +++ b/libavcodec/mpeg4video.h
> >>> @@ -43,6 +43,9 @@
> >>>  #define ACE_VO_TYPE             12
> >>>  #define ADV_SIMPLE_VO_TYPE      17
> >>>  
> >>> +#define VOT_VIDEO_ID 1
> >>> +#define VOT_STILL_TEXTURE_ID 2
> >>> +
> >>>  // aspect_ratio_info
> >>>  #define EXTENDED_PAR 15
> >>>  
> >>> diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
> >>> index cdd7077f01..852f73f02c 100644
> >>> --- a/libavcodec/mpeg4videodec.c
> >>> +++ b/libavcodec/mpeg4videodec.c
> >>> @@ -1751,6 +1751,36 @@ static int mpeg4_decode_profile_level(MpegEncContext *s, GetBitContext *gb)
> >>>          s->avctx->level = 0;
> >>>      }
> >>>  
> >>> +    return 0;
> >>> +
> >>
> >> Stray newline.
> >>
> >>> +}
> >>> +
> >>> +static int mpeg4_decode_visual_object(MpegEncContext *s, GetBitContext *gb)
> >>> +{
> >>> +    int visual_object_type;
> >>> +    int is_visual_object_identifier = get_bits1(gb);
> >>> +
> >>> +    if (is_visual_object_identifier) {
> >>> +        skip_bits(gb, 4+3);
> >>> +    }
> >>> +    visual_object_type = get_bits(gb, 4);
> >>> +
> >>> +    if (visual_object_type == VOT_VIDEO_ID ||
> >>> +        visual_object_type == VOT_STILL_TEXTURE_ID) {
> >>> +        int video_signal_type = get_bits1(gb);
> >>> +        if (video_signal_type) {
> >>> +            int video_format = get_bits(gb, 3);
> >>> +            int video_range = get_bits1(gb);
> >>> +            int color_description = get_bits1(gb);
> >>> +
> >>> +            s->avctx->color_range = video_range ? AVCOL_RANGE_JPEG : AVCOL_RANGE_MPEG;
> >>> +
> >>> +            if (color_description) {
> >>> +                skip_bits(gb, 8+8+8);
> >>
> >> Might be nice to extract the colour information as well?  (Should be able to set color_primaries/color_trc/colorspace directly, I think.)
> > 
> > will look into this
> > btw, iam a bit short on samples that use this
> > i had found just one sample after a quick look
> > more samples would be welcome, if someone has some.
> 
> From a quick look around (run over some MPEG-4 samples with an abort in the above code) I can't find any examples of video_signal_type being set at all.  Minor thing I noticed in doing that - video_format is unused so you get a warning from the compiler: since it's not useful to anyone maybe replace it with skip_bits(3) and move the other stuff around to match that?
> 
> Don't block this because of the colour part if you don't have a sample of that - I just thought from reading the relevant part of the standard that it should be easy, but if noone has ever used it then whatever.

will push with color part support.
I sadly have not found much to test it seems to be the same as mpeg2

thx

[...]

Patch hide | download patch | download mbox

diff --git a/libavcodec/mpeg4video.h b/libavcodec/mpeg4video.h
index 515b008ae4..0ba502d50b 100644
--- a/libavcodec/mpeg4video.h
+++ b/libavcodec/mpeg4video.h
@@ -43,6 +43,9 @@ 
 #define ACE_VO_TYPE             12
 #define ADV_SIMPLE_VO_TYPE      17
 
+#define VOT_VIDEO_ID 1
+#define VOT_STILL_TEXTURE_ID 2
+
 // aspect_ratio_info
 #define EXTENDED_PAR 15
 
diff --git a/libavcodec/mpeg4videodec.c b/libavcodec/mpeg4videodec.c
index cdd7077f01..852f73f02c 100644
--- a/libavcodec/mpeg4videodec.c
+++ b/libavcodec/mpeg4videodec.c
@@ -1751,6 +1751,36 @@  static int mpeg4_decode_profile_level(MpegEncContext *s, GetBitContext *gb)
         s->avctx->level = 0;
     }
 
+    return 0;
+
+}
+
+static int mpeg4_decode_visual_object(MpegEncContext *s, GetBitContext *gb)
+{
+    int visual_object_type;
+    int is_visual_object_identifier = get_bits1(gb);
+
+    if (is_visual_object_identifier) {
+        skip_bits(gb, 4+3);
+    }
+    visual_object_type = get_bits(gb, 4);
+
+    if (visual_object_type == VOT_VIDEO_ID ||
+        visual_object_type == VOT_STILL_TEXTURE_ID) {
+        int video_signal_type = get_bits1(gb);
+        if (video_signal_type) {
+            int video_format = get_bits(gb, 3);
+            int video_range = get_bits1(gb);
+            int color_description = get_bits1(gb);
+
+            s->avctx->color_range = video_range ? AVCOL_RANGE_JPEG : AVCOL_RANGE_MPEG;
+
+            if (color_description) {
+                skip_bits(gb, 8+8+8);
+            }
+        }
+    }
+
     return 0;
 }
 
@@ -2684,6 +2714,8 @@  int ff_mpeg4_decode_picture_header(Mpeg4DecContext *ctx, GetBitContext *gb)
             mpeg4_decode_gop_header(s, gb);
         } else if (startcode == VOS_STARTCODE) {
             mpeg4_decode_profile_level(s, gb);
+        } else if (startcode == VISUAL_OBJ_STARTCODE) {
+            mpeg4_decode_visual_object(s, gb);
         } else if (startcode == VOP_STARTCODE) {
             break;
         }