[FFmpeg-devel] [PATCH] lavc/dvdsubdec: accept palette from options.

Clément Bœsch ubitux at gmail.com
Sat Dec 1 18:18:23 CET 2012


On Sat, Dec 01, 2012 at 03:05:59PM +0100, Nicolas George wrote:
> On DVDs, the palette is part of the IFO file and therefore
> not available when reading from a dumped VOB file.
> 
> Signed-off-by: Nicolas George <nicolas.george at normalesup.org>
> ---
>  doc/decoders.texi      |   22 +++++++++++++++++++
>  libavcodec/dvdsubdec.c |   55 +++++++++++++++++++++++++++++++++++++++---------
>  2 files changed, 67 insertions(+), 10 deletions(-)
> 
> 
> I believe there is no maintainer for this file.
> 
> 
> diff --git a/doc/decoders.texi b/doc/decoders.texi
> index 87ad4ee..1373858 100644
> --- a/doc/decoders.texi
> +++ b/doc/decoders.texi
> @@ -61,3 +61,25 @@ use is purely internal and the format of the data it accepts is not publicly
>  documented.
>  
>  @c man end AUDIO DECODERS
> +
> + at chapter Subtitles Decoders
> + at c man begin SUBTILES DECODERS
> +
> + at section dvdsub
> +
> +This codec decodes the bitmap subtitles used in DVDs; the same subtitles can
> +also be found in VobSub file pairs and in some Matroska files.
> +
> + at subsection @Options
> +
> + at table @option
> + at item palette
> +Specify the global palette used by the bitmaps. When stored in VobSub, the
> +palette is normally specified in the index file; in Matroska, the palette is
> +stored in the codec extra-data in the same format as in VobSub. In DVDs, the
> +palette is stored in the IFO file, and therefore not available when reading
> +from dumped VOB files. The format for this option is a string containing 16
> +24-bits hexadecimal numbers (without 0x prefix) separated by comas.
> + at end table
> +
> + at c man end SUBTILES DECODERS
> diff --git a/libavcodec/dvdsubdec.c b/libavcodec/dvdsubdec.c
> index 9c2dd8c..cc9e11b 100644
> --- a/libavcodec/dvdsubdec.c
> +++ b/libavcodec/dvdsubdec.c
> @@ -22,13 +22,16 @@
>  #include "get_bits.h"
>  #include "dsputil.h"
>  #include "libavutil/colorspace.h"
> +#include "libavutil/opt.h"
>  #include "libavutil/imgutils.h"
>  
>  //#define DEBUG
>  
>  typedef struct DVDSubContext
>  {
> +  AVClass *class;
>    uint32_t palette[16];
> +  char    *palette_str;
>    int      has_palette;
>    uint8_t  colormap[4];
>    uint8_t  alpha[256];
> @@ -513,7 +516,19 @@ static int dvdsub_decode(AVCodecContext *avctx,
>      return buf_size;
>  }
>  
> -static int dvdsub_init(AVCodecContext *avctx)
> +static void parse_palette(DVDSubContext *ctx, char *p)
> +{
> +    int i;
> +
> +    ctx->has_palette = 1;
> +    for(i=0;i<16;i++) {
> +        ctx->palette[i] = strtoul(p, &p, 16);
> +        while(*p == ',' || isspace(*p))
> +            p++;
> +    }
> +}
> +
> +static int dvdsub_parse_extradata(AVCodecContext *avctx)
>  {
>      DVDSubContext *ctx = (DVDSubContext*) avctx->priv_data;
>      char *dataorig, *data;
> @@ -533,14 +548,7 @@ static int dvdsub_init(AVCodecContext *avctx)
>              break;
>  
>          if (strncmp("palette:", data, 8) == 0) {
> -            int i;
> -            char *p = data+8;
> -            ctx->has_palette = 1;
> -            for(i=0;i<16;i++) {
> -                ctx->palette[i] = strtoul(p, &p, 16);
> -                while(*p == ',' || isspace(*p))
> -                    p++;
> -            }
> +            parse_palette(ctx, data + 8);
>          } else if (strncmp("size:", data, 5) == 0) {
>              int w, h;
>              if (sscanf(data + 5, "%dx%d", &w, &h) == 2 &&
> @@ -552,6 +560,20 @@ static int dvdsub_init(AVCodecContext *avctx)
>          data += strspn(data, "\n\r");
>      }
>  
> +    av_free(dataorig);
> +    return 1;
> +}
> +
> +static int dvdsub_init(AVCodecContext *avctx)
> +{
> +    DVDSubContext *ctx = (DVDSubContext*) avctx->priv_data;
> +    int ret;
> +
> +    if ((ret = dvdsub_parse_extradata(avctx)) < 0)
> +        return ret;
> +
> +    if (ctx->palette_str)
> +        parse_palette(ctx, ctx->palette_str);
>      if (ctx->has_palette) {
>          int i;
>          av_log(avctx, AV_LOG_DEBUG, "palette:");
> @@ -560,10 +582,22 @@ static int dvdsub_init(AVCodecContext *avctx)
>          av_log(avctx, AV_LOG_DEBUG, "\n");
>      }
>  
> -    av_free(dataorig);
>      return 1;
>  }
>  
> +#define OFFSET(field) offsetof(DVDSubContext, field)
> +#define VD AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_DECODING_PARAM
> +static const AVOption options[] = {
> +    { "palette", "set the global palette", OFFSET(palette_str), AV_OPT_TYPE_STRING, { .str = NULL }, 0, 0, VD },
> +    { NULL }
> +};

What about changing the "custom colors" instead/also?

    # Custom colors (transp idxs and the four colors)
    custom colors: OFF, tridx: 0000, colors: 000008, 300030, 000030, 9532c8

-- 
Clément B.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 490 bytes
Desc: not available
URL: <http://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20121201/d3e4251a/attachment.asc>


More information about the ffmpeg-devel mailing list