According to the sample for trac ticket #1722, PGS subtitles
are decoded from several packets at the same DTS and varying PTS.
The PTS from the presentation segment seem to be the valid one;
in particular, clear subtitles are too early with the other PTS.
... | ... |
@@ -67,6 +67,7 @@ typedef struct PGSSubContext { |
67 | 67 |
PGSSubPresentation presentation; |
68 | 68 |
uint32_t clut[256]; |
69 | 69 |
PGSSubPicture pictures[UINT16_MAX]; |
70 |
+ int64_t pts; |
|
70 | 71 |
int forced_subs_only; |
71 | 72 |
} PGSSubContext; |
72 | 73 |
|
... | ... |
@@ -378,6 +379,7 @@ static int display_end_segment(AVCodecContext *avctx, void *data, |
378 | 378 |
{ |
379 | 379 |
AVSubtitle *sub = data; |
380 | 380 |
PGSSubContext *ctx = avctx->priv_data; |
381 |
+ int64_t pts; |
|
381 | 382 |
|
382 | 383 |
uint16_t rect; |
383 | 384 |
|
... | ... |
@@ -387,7 +389,10 @@ static int display_end_segment(AVCodecContext *avctx, void *data, |
387 | 387 |
* not been cleared by a subsequent empty display command. |
388 | 388 |
*/ |
389 | 389 |
|
390 |
+ pts = ctx->pts != AV_NOPTS_VALUE ? ctx->pts : sub->pts; |
|
390 | 391 |
memset(sub, 0, sizeof(*sub)); |
392 |
+ sub->pts = pts; |
|
393 |
+ ctx->pts = AV_NOPTS_VALUE; |
|
391 | 394 |
|
392 | 395 |
// Blank if last object_count was 0. |
393 | 396 |
if (!ctx->presentation.object_count) |
... | ... |
@@ -436,8 +441,10 @@ static int display_end_segment(AVCodecContext *avctx, void *data, |
436 | 436 |
static int decode(AVCodecContext *avctx, void *data, int *data_size, |
437 | 437 |
AVPacket *avpkt) |
438 | 438 |
{ |
439 |
+ PGSSubContext *ctx = avctx->priv_data; |
|
439 | 440 |
const uint8_t *buf = avpkt->data; |
440 | 441 |
int buf_size = avpkt->size; |
442 |
+ AVSubtitle *sub = data; |
|
441 | 443 |
|
442 | 444 |
const uint8_t *buf_end; |
443 | 445 |
uint8_t segment_type; |
... | ... |
@@ -482,6 +489,7 @@ static int decode(AVCodecContext *avctx, void *data, int *data_size, |
482 | 482 |
break; |
483 | 483 |
case PRESENTATION_SEGMENT: |
484 | 484 |
parse_presentation_segment(avctx, buf, segment_length); |
485 |
+ ctx->pts = sub->pts; |
|
485 | 486 |
break; |
486 | 487 |
case WINDOW_SEGMENT: |
487 | 488 |
/* |