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

Michael Niedermayer michaelni
Wed Jul 7 21:27:30 CEST 2010


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
> @@ -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;

ok


> @@ -598,6 +598,14 @@ 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->codec->codec_tag  = 0;

why ?


> +                    st->need_parsing      = AVSTREAM_PARSE_FULL;
> +                    av_set_pts_info(st, 64, 1, 1000);
> +                    url_fskip(pb, size);
> +                    break;
>                  default:
>                      st->codec->codec_type = AVMEDIA_TYPE_DATA;
>                      st->codec->codec_id= CODEC_ID_NONE;
> @@ -687,6 +695,26 @@ 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;
> +        int i, size, name_size = bytestream_get_le32(&ptr);
> +
> +        for(i=0; i<name_size; i+=2)
> +            PUT_UTF8(bytestream_get_le16(&ptr), tmp,
> +                     if(d < desc+sizeof(desc)-1)  *d++ = tmp;);

no end of array checks for the input


> +        *d = 0;
> +        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;

that could be negative


> +    }
> +}
> +
>  static int get_stream_idx(int *d){
>      if(    d[0] >= '0' && d[0] <= '9'
>          && d[1] >= '0' && d[1] <= '9'){

> @@ -801,6 +829,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);

does this really belong in the avi demuxer layer?


> +
>          if (CONFIG_DV_DEMUXER && avi->dv_demux) {
>              dstr = pkt->destruct;
>              size = dv_produce_packet(avi->dv_demux, pkt,
> @@ -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 ?


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

The worst form of inequality is to try to make unequal things equal.
-- Aristotle
-------------- 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/20100707/3096ead4/attachment.pgp>



More information about the ffmpeg-devel mailing list