[FFmpeg-devel] lavc/mpeg12dec: Read Closed Captions from second field

Submitted by Carl Eugen Hoyos on Nov. 28, 2018, 9:48 p.m.

Details

Message ID CAB0OVGpZADDfcnZshDDw3hFqE3+6z448fnLFUtiiXp9ruJMvew@mail.gmail.com
State New
Headers show

Commit Message

Carl Eugen Hoyos Nov. 28, 2018, 9:48 p.m.
Hi!

Attached patch fixes reading Closed Captions from a field-encoded
mpeg2video sample from the libav-user mailing list.

Please review, Carl Eugen

Comments

Michael Niedermayer Nov. 29, 2018, 5:55 p.m.
On Wed, Nov 28, 2018 at 10:48:17PM +0100, Carl Eugen Hoyos wrote:
> Hi!
> 
> Attached patch fixes reading Closed Captions from a field-encoded
> mpeg2video sample from the libav-user mailing list.
> 
> Please review, Carl Eugen

>  mpeg12dec.c |   11 +++++++++++
>  1 file changed, 11 insertions(+)
> 777c30f845680de35a26279d23206baf4d4b4dfd  0001-lavc-mpeg12dec-Read-Closed-Captions-from-second-fiel.patch
> From 045a485ffedb3344560070a58a2def659be81700 Mon Sep 17 00:00:00 2001
> From: Carl Eugen Hoyos <ceffmpeg@gmail.com>
> Date: Wed, 28 Nov 2018 22:45:00 +0100
> Subject: [PATCH] lavc/mpeg12dec: Read Closed Captions from second field.
> 
> ---
>  libavcodec/mpeg12dec.c |   11 +++++++++++
>  1 file changed, 11 insertions(+)
> 
> diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c
> index 83e5378..c0a54a8 100644
> --- a/libavcodec/mpeg12dec.c
> +++ b/libavcodec/mpeg12dec.c
> @@ -1664,6 +1664,17 @@ static int mpeg_field_start(MpegEncContext *s, const uint8_t *buf, int buf_size)
>              return AVERROR_INVALIDDATA;
>          }
>  
> +        if (s1->a53_caption) {
> +            AVFrameSideData *sd;
> +            av_frame_remove_side_data(s->current_picture_ptr->f, AV_FRAME_DATA_A53_CC);
> +            sd = av_frame_new_side_data(
> +                s->current_picture_ptr->f, AV_FRAME_DATA_A53_CC,
> +                s1->a53_caption_size);
> +            if (sd)
> +                memcpy(sd->data, s1->a53_caption, s1->a53_caption_size);
> +            av_freep(&s1->a53_caption);
> +        }

This is probably ok if only one field has data Attached to it, but if both
have then both should be exported. Also the user should have some way to
find out which of 2 fields data came from


[...]
Devin Heitmueller Nov. 29, 2018, 5:59 p.m.
On Thu, Nov 29, 2018 at 12:55 PM Michael Niedermayer
<michael@niedermayer.cc> wrote:

> > +        if (s1->a53_caption) {
> > +            AVFrameSideData *sd;
> > +            av_frame_remove_side_data(s->current_picture_ptr->f, AV_FRAME_DATA_A53_CC);
> > +            sd = av_frame_new_side_data(
> > +                s->current_picture_ptr->f, AV_FRAME_DATA_A53_CC,
> > +                s1->a53_caption_size);
> > +            if (sd)
> > +                memcpy(sd->data, s1->a53_caption, s1->a53_caption_size);
> > +            av_freep(&s1->a53_caption);
> > +        }
>
> This is probably ok if only one field has data Attached to it, but if both
> have then both should be exported. Also the user should have some way to
> find out which of 2 fields data came from

Yeah, this will cause the captions from the first field to get lost.
It probably makes sense to look at the H.264 decoder, where this is
done properly (i.e. creating a side data that contains the captions
from both fields).

Devin
Carl Eugen Hoyos Nov. 30, 2018, 3:52 p.m.
2018-11-29 18:59 GMT+01:00, Devin Heitmueller <dheitmueller@kernellabs.com>:
> On Thu, Nov 29, 2018 at 12:55 PM Michael Niedermayer
> <michael@niedermayer.cc> wrote:
>
>> > +        if (s1->a53_caption) {
>> > +            AVFrameSideData *sd;
>> > +            av_frame_remove_side_data(s->current_picture_ptr->f,
>> > AV_FRAME_DATA_A53_CC);
>> > +            sd = av_frame_new_side_data(
>> > +                s->current_picture_ptr->f, AV_FRAME_DATA_A53_CC,
>> > +                s1->a53_caption_size);
>> > +            if (sd)
>> > +                memcpy(sd->data, s1->a53_caption,
>> > s1->a53_caption_size);
>> > +            av_freep(&s1->a53_caption);
>> > +        }
>>
>> This is probably ok if only one field has data Attached to it, but if both
>> have then both should be exported. Also the user should have some way to
>> find out which of 2 fields data came from
>
> Yeah, this will cause the captions from the first field to get lost.
> It probably makes sense to look at the H.264 decoder, where this is
> done properly (i.e. creating a side data that contains the captions
> from both fields).

Could you provide a sample for me for testing?

Thank you, Carl Eugen

Patch hide | download patch | download mbox

From 045a485ffedb3344560070a58a2def659be81700 Mon Sep 17 00:00:00 2001
From: Carl Eugen Hoyos <ceffmpeg@gmail.com>
Date: Wed, 28 Nov 2018 22:45:00 +0100
Subject: [PATCH] lavc/mpeg12dec: Read Closed Captions from second field.

---
 libavcodec/mpeg12dec.c |   11 +++++++++++
 1 file changed, 11 insertions(+)

diff --git a/libavcodec/mpeg12dec.c b/libavcodec/mpeg12dec.c
index 83e5378..c0a54a8 100644
--- a/libavcodec/mpeg12dec.c
+++ b/libavcodec/mpeg12dec.c
@@ -1664,6 +1664,17 @@  static int mpeg_field_start(MpegEncContext *s, const uint8_t *buf, int buf_size)
             return AVERROR_INVALIDDATA;
         }
 
+        if (s1->a53_caption) {
+            AVFrameSideData *sd;
+            av_frame_remove_side_data(s->current_picture_ptr->f, AV_FRAME_DATA_A53_CC);
+            sd = av_frame_new_side_data(
+                s->current_picture_ptr->f, AV_FRAME_DATA_A53_CC,
+                s1->a53_caption_size);
+            if (sd)
+                memcpy(sd->data, s1->a53_caption, s1->a53_caption_size);
+            av_freep(&s1->a53_caption);
+        }
+
         if (s->avctx->hwaccel &&
             (s->avctx->slice_flags & SLICE_FLAG_ALLOW_FIELD)) {
             if ((ret = s->avctx->hwaccel->end_frame(s->avctx)) < 0) {
-- 
1.7.10.4