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

Nicolas George git at videolan.org
Wed Dec 5 10:49:38 CET 2012


ffmpeg | branch: master | Nicolas George <nicolas.george at normalesup.org> | Sat Dec  1 14:47:14 2012 +0100| [217b10de3f30325961d45af3827d4d097e8af5ec] | committer: Nicolas George

lavc/dvdsubdec: accept palette from options.

On DVDs, the palette is part of the IFO file and therefore
not available when reading from a dumped VOB file.

> http://git.videolan.org/gitweb.cgi/ffmpeg.git/?a=commit;h=217b10de3f30325961d45af3827d4d097e8af5ec
---

 doc/decoders.texi      |   26 +++++++++++++++++++++++
 libavcodec/dvdsubdec.c |   55 +++++++++++++++++++++++++++++++++++++++---------
 2 files changed, 71 insertions(+), 10 deletions(-)

diff --git a/doc/decoders.texi b/doc/decoders.texi
index 87ad4ee..c5b79b3 100644
--- a/doc/decoders.texi
+++ b/doc/decoders.texi
@@ -61,3 +61,29 @@ 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, for example @code{0d00ee,
+ee450d, 101010, eaeaea, 0ce60b, ec14ed, ebff0b, 0d617a, 7b7b7b, d1d1d1,
+7b2a0e, 0d950c, 0f007b, cf0dec, cfa80c, 7c127b}.
+ 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 }
+};
+static const AVClass class = {
+    .class_name = "dvdsubdec",
+    .item_name  = av_default_item_name,
+    .option     = options,
+    .version    = LIBAVUTIL_VERSION_INT,
+};
+
 AVCodec ff_dvdsub_decoder = {
     .name           = "dvdsub",
     .type           = AVMEDIA_TYPE_SUBTITLE,
@@ -572,4 +606,5 @@ AVCodec ff_dvdsub_decoder = {
     .init           = dvdsub_init,
     .decode         = dvdsub_decode,
     .long_name      = NULL_IF_CONFIG_SMALL("DVD subtitles"),
+    .priv_class     = &class,
 };



More information about the ffmpeg-cvslog mailing list