>From d8ffaee164efddddaf8d9bc97b4b63549cff5105 Mon Sep 17 00:00:00 2001
From: John Stebbins <[email protected]>
Date: Sun, 14 Oct 2012 16:28:48 +0200
Subject: [PATCH 1/2] PGS subtitles: Expose "forced" flag

Useful for detection of subtitles displayed during foreign language scenes.
---
 libavcodec/avcodec.h   |    1 +
 libavcodec/pgssubdec.c |   10 +++++++---
 2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 51270e6..bcf6f81 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -3168,6 +3168,7 @@ typedef struct AVSubtitle {
     unsigned num_rects;
     AVSubtitleRect **rects;
     int64_t pts;    ///< Same as packet pts, in AV_TIME_BASE
+    uint8_t forced;
 } AVSubtitle;
 
 /**
diff --git a/libavcodec/pgssubdec.c b/libavcodec/pgssubdec.c
index 9fd26d8..bc72643 100644
--- a/libavcodec/pgssubdec.c
+++ b/libavcodec/pgssubdec.c
@@ -45,6 +45,7 @@ typedef struct PGSSubPresentation {
     int y;
     int id_number;
     int object_number;
+    uint8_t composition_flag;
 } PGSSubPresentation;
 
 typedef struct PGSSubPicture {
@@ -299,16 +300,17 @@ static void parse_presentation_segment(AVCodecContext *avctx,
     buf += 3;
 
     ctx->presentation.object_number = bytestream_get_byte(&buf);
+    ctx->presentation.composition_flag = 0;
     if (!ctx->presentation.object_number)
         return;
 
     /*
-     * Skip 4 bytes of unknown:
+     * Skip 3 bytes of unknown:
      *     object_id_ref (2 bytes),
      *     window_id_ref,
-     *     composition_flag (0x80 - object cropped, 0x40 - object forced)
      */
-    buf += 4;
+    buf += 3;
+    ctx->presentation.composition_flag = bytestream_get_byte(&buf);
 
     x = bytestream_get_be16(&buf);
     y = bytestream_get_be16(&buf);
@@ -356,6 +358,8 @@ static int display_end_segment(AVCodecContext *avctx, void *data,
      */
 
     memset(sub, 0, sizeof(*sub));
+    sub->forced = (ctx->presentation.composition_flag & 0x40) != 0;
+
     // Blank if last object_number was 0.
     // Note that this may be wrong for more complex subtitles.
     if (!ctx->presentation.object_number)
-- 
1.7.9.5

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to