summaryrefslogtreecommitdiffstats
path: root/contrib/ffmpeg/A04-pgs-pts.patch
blob: fe6a6dc9352ee7dc2c9f08e1e1e427e8693ca245 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
diff --git a/libavcodec/avcodec.h b/libavcodec/avcodec.h
index 102df3a..aa40c78 100644
--- a/libavcodec/avcodec.h
+++ b/libavcodec/avcodec.h
@@ -3093,6 +3093,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 3335412..3f14a2d 100644
--- a/libavcodec/pgssubdec.c
+++ b/libavcodec/pgssubdec.c
@@ -45,6 +45,8 @@ typedef struct PGSSubPresentation {
     int y;
     int id_number;
     int object_number;
+    uint8_t composition_flag;
+    int64_t pts;
 } PGSSubPresentation;
 
 typedef struct PGSSubPicture {
@@ -271,7 +273,8 @@ static void parse_palette_segment(AVCodecContext *avctx,
  * @todo TODO: Implement forcing of subtitles
  */
 static void parse_presentation_segment(AVCodecContext *avctx,
-                                       const uint8_t *buf, int buf_size)
+                                       const uint8_t *buf, int buf_size,
+                                       int64_t pts)
 {
     PGSSubContext *ctx = avctx->priv_data;
 
@@ -280,6 +283,8 @@ static void parse_presentation_segment(AVCodecContext *avctx,
     int w = bytestream_get_be16(&buf);
     int h = bytestream_get_be16(&buf);
 
+    ctx->presentation.pts = pts;
+
     av_dlog(avctx, "Video Dimensions %dx%d\n",
             w, h);
     if (av_image_check_size(w, h, 0, avctx) >= 0)
@@ -299,16 +304,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 +362,9 @@ static int display_end_segment(AVCodecContext *avctx, void *data,
      */
 
     memset(sub, 0, sizeof(*sub));
+    sub->pts = ctx->presentation.pts;
+    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)
@@ -441,7 +450,7 @@ static int decode(AVCodecContext *avctx, void *data, int *data_size,
             parse_picture_segment(avctx, buf, segment_length);
             break;
         case PRESENTATION_SEGMENT:
-            parse_presentation_segment(avctx, buf, segment_length);
+            parse_presentation_segment(avctx, buf, segment_length, avpkt->pts);
             break;
         case WINDOW_SEGMENT:
             /*