[FFmpeg-devel] [PATCH] Exposing forced flag for DVD and PGS subtitles

Erik Miranda erikmiranda at gmail.com
Mon Apr 16 07:43:32 CEST 2012


Some subtitle formats have a notion of a "forced" subtitle, a subtitle 
which should be decoded and displayed even when subtitles are not 
specifically enabled by the user. These are often used as video captions 
or as translations to languages which are different than the audio 
stream's primary language (for example the Na'vi dialogue in the movie 
Avatar). I think it would be useful to expose this flag so that a player 
may be able to implement forced subtitle display.

I realize that a forced_subs_only option has been added to the PGS 
decoder, but I think exposing this flag is more natural. For example, it 
could be used in transcoding between two subtitle formats that support 
forced subtitle display. Furthermore, it seems the forced_subs_only 
switch is not implemented in the DVD subtitle decoder.

This patch adds a "forced" member to the AVSubtitleRect structure and 
implements setting this flag in the DVD and PGS subtitle decoders, since 
these are the formats I'm aware of that include such a function. Since 
this patch changes AVSubtitleRect, it leads to a public API change. As 
far as I can tell, this is the best method to allow access to this 
information. Please advise me if otherwise, or if further changes are 
required as part of changing AVSubtitleRect. I think the libavcodec 
version would need a bump, correct?

Cheers,
-- Erik Miranda
-------------- next part --------------
>From 211fad45d26c7af563c0ac0ef472e33c479b4bd2 Mon Sep 17 00:00:00 2001
From: hakuya <erikmiranda at gmail.com>
Date: Sun, 15 Apr 2012 21:58:40 -0400
Subject: [PATCH] Exposing forced flag for DVD and PGS subtitles

---
 libavcodec/avcodec.h   |    6 ++++++
 libavcodec/dvdsubdec.c |    1 +
 libavcodec/pgssubdec.c |    3 +++
 3 files changed, 10 insertions(+), 0 deletions(-)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index d905a01..187dba0 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -3141,6 +3141,12 @@ typedef struct AVSubtitleRect {
      * struct.
      */
     char *ass;
+
+    /**
+     * 1 indicates this subtitle is a forced subtitle.
+     * A forced subtitle should be displayed even when subtitles are hidden.
+     */
+    int forced;
 } AVSubtitleRect;
 
 typedef struct AVSubtitle {
diff --git a/libavcodec/dvdsubdec.c b/libavcodec/dvdsubdec.c
index 08d1db9..ec86b25 100644
--- a/libavcodec/dvdsubdec.c
+++ b/libavcodec/dvdsubdec.c
@@ -356,6 +356,7 @@ static int decode_dvd_subtitles(DVDSubContext *ctx, AVSubtitle *sub_header,
                 sub_header->rects[0]->h = h;
                 sub_header->rects[0]->type = SUBTITLE_BITMAP;
                 sub_header->rects[0]->pict.linesize[0] = w;
+                sub_header->rects[0]->forced = is_menu;
             }
         }
         if (next_cmd_pos < cmd_pos) {
diff --git a/libavcodec/pgssubdec.c b/libavcodec/pgssubdec.c
index be0981d..4fb1e7d 100644
--- a/libavcodec/pgssubdec.c
+++ b/libavcodec/pgssubdec.c
@@ -423,6 +423,9 @@ static int display_end_segment(AVCodecContext *avctx, void *data,
         sub->rects[rect]->nb_colors    = 256;
         sub->rects[rect]->pict.data[1] = av_mallocz(AVPALETTE_SIZE);
 
+        /* Copy the forced flag */
+        sub->rects[rect]->forced = (ctx->presentation.objects[rect].composition & 0x40) != 0;
+
         if (!ctx->forced_subs_only || ctx->presentation.objects[rect].composition & 0x40)
         memcpy(sub->rects[rect]->pict.data[1], ctx->clut, sub->rects[rect]->nb_colors * sizeof(uint32_t));
     }
-- 
1.7.3.4



More information about the ffmpeg-devel mailing list