[FFmpeg-devel] [PATCH 4/4] avidec: demux ASS and SRT tracks

Michael Niedermayer michaelni
Sun Jul 11 14:46:46 CEST 2010


On Thu, Jul 08, 2010 at 05:28:40PM +0200, Aurelien Jacobs wrote:
> On Thu, Jul 08, 2010 at 12:52:54AM +0200, Michael Niedermayer wrote:
> > On Thu, Jul 08, 2010 at 12:12:00AM +0200, Aurelien Jacobs wrote:
> > > On Wed, Jul 07, 2010 at 09:27:30PM +0200, Michael Niedermayer wrote:
> > > > On Tue, Jul 06, 2010 at 10:55:04PM +0200, Aurelien Jacobs wrote:
> > > > > 
> > > > > ---
> > > > >  libavformat/avidec.c |   42 ++++++++++++++++++++++++++++++++++++++++--
> > > > >  libavformat/utils.c  |    2 ++
> > > > >  2 files changed, 42 insertions(+), 2 deletions(-)
> > > > 
> > > > >  avidec.c |   42 ++++++++++++++++++++++++++++++++++++++++--
> > > > >  utils.c  |    2 ++
> > > > >  2 files changed, 42 insertions(+), 2 deletions(-)
> > > > > e528c97d940b4d16e1a96f56dd4686a3b8f3b83e  avidec-demux-ass-and-srt-track.patch
> > > > > diff --git a/libavformat/avidec.c b/libavformat/avidec.c
> > > > > index cdf8307..ac1e3b6 100644
> > > > > --- a/libavformat/avidec.c
> > > > > +++ b/libavformat/avidec.c
> > > > > @@ -1138,6 +1170,12 @@ static int avi_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp
> > > > >          ast2->packet_size=
> > > > >          ast2->remaining= 0;
> > > > >  
> > > > > +        if (st2->codec->codec_type == AVMEDIA_TYPE_SUBTITLE
> > > > > +            && !st2->codec->codec_tag) {
> > > > > +            ast2->frame_offset = 0;
> > > > > +            continue;
> > > > > +        }
> > > > 
> > > > this doesnt feel correct, all sees go to point 0 ?
> > > 
> > > Well, actually gab2 subtitles are composed of one and only one
> > > packet. After seeking, subtitles contained in this packet may be needed
> > > (or not, but the avi demuxer has no way to know). So the only thing the
> > > avi demuxer can do after a seek is to output this single packet.
> > > Did I missed anything ?
> > 
> > this design is sick
> 
> Sure it is ! Definitely !
> 
> > > @@ -598,6 +598,13 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
> > >                          ast->dshow_block_align = 0;
> > >                      }
> > >                      break;
> > > +                case AVMEDIA_TYPE_SUBTITLE:
> > > +                    st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE;
> > > +                    st->codec->codec_id   = CODEC_ID_PROBE;
> > > +                    st->need_parsing      = AVSTREAM_PARSE_FULL;
> > > +                    av_set_pts_info(st, 64, 1, 1000);
> > 
> > > +                    url_fskip(pb, size);
> > 
> > what is in this data we skip?
> 
> Actually nothing !
> I've checked it and there is never any data to skip at this point.
> It seems to be a remainder of a copy/paste from the default case...
> Yes, again... Fixed.
> Now I've double checked and I'm pretty sure that there is no such dead
> code left anymore.
> 
> Aurel
>  avidec.c |   44 ++++++++++++++++++++++++++++++++++++++++++--
>  utils.c  |    2 ++
>  2 files changed, 44 insertions(+), 2 deletions(-)
> d0cbe5699eec9a1a99680231ed5597b871e21f2d  avidec-demux-ass-and-srt-track.diff
> avidec: demux ASS and SRT tracks
> 
> From: Aurelien Jacobs <aurel at gnuage.org>
> 
> 
> ---
>  libavformat/avidec.c |   44 ++++++++++++++++++++++++++++++++++++++++++--
>  libavformat/utils.c  |    2 ++
>  2 files changed, 44 insertions(+), 2 deletions(-)
> 
> diff --git a/libavformat/avidec.c b/libavformat/avidec.c
> index cdf8307..2fbaad5 100644
> --- a/libavformat/avidec.c
> +++ b/libavformat/avidec.c
> @@ -24,6 +24,7 @@
>  
>  #include "libavutil/intreadwrite.h"
>  #include "libavutil/bswap.h"
> +#include "libavcodec/bytestream.h"
>  #include "avformat.h"
>  #include "avi.h"
>  #include "dv.h"
> @@ -466,8 +467,7 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
>                  codec_type = AVMEDIA_TYPE_AUDIO;
>                  break;
>              case MKTAG('t', 'x', 't', 's'):
> -                //FIXME
> -                codec_type = AVMEDIA_TYPE_DATA; //AVMEDIA_TYPE_SUB ?  FIXME
> +                codec_type = AVMEDIA_TYPE_SUBTITLE;
>                  break;
>              case MKTAG('d', 'a', 't', 's'):
>                  codec_type = AVMEDIA_TYPE_DATA;
> @@ -598,6 +598,12 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
>                          ast->dshow_block_align = 0;
>                      }
>                      break;
> +                case AVMEDIA_TYPE_SUBTITLE:
> +                    st->codec->codec_type = AVMEDIA_TYPE_SUBTITLE;
> +                    st->codec->codec_id   = CODEC_ID_PROBE;
> +                    st->need_parsing      = AVSTREAM_PARSE_FULL;
> +                    av_set_pts_info(st, 64, 1, 1000);
> +                    break;
>                  default:
>                      st->codec->codec_type = AVMEDIA_TYPE_DATA;
>                      st->codec->codec_id= CODEC_ID_NONE;
> @@ -687,6 +693,30 @@ static int avi_read_header(AVFormatContext *s, AVFormatParameters *ap)
>      return 0;
>  }
>  
> +static void read_gab2_sub(AVStream *st, AVPacket *pkt) {
> +    if(!strcmp(pkt->data, "GAB2") && AV_RL16(pkt->data+5) == 2) {
> +        uint8_t tmp, desc[256], *d = desc;
> +        const uint8_t *ptr = pkt->data+7;
> +        unsigned int i, size, name_size = bytestream_get_le32(&ptr);
> +
> +        if (name_size > pkt->size-17)
> +            return;
> +
> +        for(i=0; i<name_size; i+=2)
> +            PUT_UTF8(bytestream_get_le16(&ptr), tmp,
> +                     if(d < desc+sizeof(desc)-1)  *d++ = tmp;);
> +        *d = 0;
> +        if (*desc)
> +            av_metadata_set2(&st->metadata, "title", desc, 0);
> +
> +        ptr += 2;
> +        size = bytestream_get_le32(&ptr);
> +        size = FFMIN(size, pkt->size+pkt->data-ptr);
> +        memmove(pkt->data, ptr, size);
> +        pkt->size = size;
> +    }
> +}
> +
>  static int get_stream_idx(int *d){
>      if(    d[0] >= '0' && d[0] <= '9'
>          && d[1] >= '0' && d[1] <= '9'){
> @@ -801,6 +831,10 @@ resync:
>                  av_log(s, AV_LOG_ERROR, "Failed to append palette\n");
>          }
>  
> +        if (st->codec->codec_type == AVMEDIA_TYPE_SUBTITLE
> +            && !st->codec->codec_tag)
> +            read_gab2_sub(st, pkt);
> +
>          if (CONFIG_DV_DEMUXER && avi->dv_demux) {
>              dstr = pkt->destruct;
>              size = dv_produce_packet(avi->dv_demux, pkt,

above hunks look like they can be commited


> @@ -1138,6 +1172,12 @@ static int avi_read_seek(AVFormatContext *s, int stream_index, int64_t timestamp
>          ast2->packet_size=
>          ast2->remaining= 0;
>  
> +        if (st2->codec->codec_type == AVMEDIA_TYPE_SUBTITLE
> +            && !st2->codec->codec_tag) {
> +            ast2->frame_offset = 0;
> +            continue;
> +        }
> +
>          if (st2->nb_index_entries <= 0)
>              continue;
>  

that needs a redesign as discussed


> diff --git a/libavformat/utils.c b/libavformat/utils.c
> index 6fa4dff..68a72fa 100644
> --- a/libavformat/utils.c
> +++ b/libavformat/utils.c
> @@ -379,12 +379,14 @@ static int set_codec_from_probe_data(AVFormatContext *s, AVStream *st, AVProbeDa
>      } fmt_id_type[] = {
>          { "aac"      , CODEC_ID_AAC       , AVMEDIA_TYPE_AUDIO },
>          { "ac3"      , CODEC_ID_AC3       , AVMEDIA_TYPE_AUDIO },
> +        { "ass"      , CODEC_ID_SSA       , AVMEDIA_TYPE_SUBTITLE },
>          { "dts"      , CODEC_ID_DTS       , AVMEDIA_TYPE_AUDIO },
>          { "eac3"     , CODEC_ID_EAC3      , AVMEDIA_TYPE_AUDIO },
>          { "h264"     , CODEC_ID_H264      , AVMEDIA_TYPE_VIDEO },
>          { "m4v"      , CODEC_ID_MPEG4     , AVMEDIA_TYPE_VIDEO },
>          { "mp3"      , CODEC_ID_MP3       , AVMEDIA_TYPE_AUDIO },
>          { "mpegvideo", CODEC_ID_MPEG2VIDEO, AVMEDIA_TYPE_VIDEO },
> +        { "srt"      , CODEC_ID_SRT       , AVMEDIA_TYPE_SUBTITLE },
>          { 0 }
>      };
>      AVInputFormat *fmt = av_probe_input_format2(pd, 1, &score);

that looks ok

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

Many that live deserve death. And some that die deserve life. Can you give
it to them? Then do not be too eager to deal out death in judgement. For
even the very wise cannot see all ends. -- Gandalf
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20100711/24043293/attachment.pgp>



More information about the ffmpeg-devel mailing list