Skip to content

Commit

Permalink
[ffmpeg] - backport PGS subtitle fixes from ffmpeg (git revisions 37b…
Browse files Browse the repository at this point in the history
  • Loading branch information
Memphiz committed Sep 30, 2012
1 parent acdd442 commit e3b35ff
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/ffmpeg/libavcodec/pgssubdec.c
Expand Up @@ -64,6 +64,7 @@ typedef struct PGSSubContext {
PGSSubPresentation presentation;
uint32_t clut[256];
PGSSubPicture pictures[UINT16_MAX];
int64_t pts;
} PGSSubContext;

static av_cold int init_decoder(AVCodecContext *avctx)
Expand Down Expand Up @@ -377,6 +378,7 @@ static int display_end_segment(AVCodecContext *avctx, void *data,
{
AVSubtitle *sub = data;
PGSSubContext *ctx = avctx->priv_data;
int64_t pts;

uint16_t rect;

Expand All @@ -386,7 +388,10 @@ static int display_end_segment(AVCodecContext *avctx, void *data,
* not been cleared by a subsequent empty display command.
*/

pts = ctx->pts != AV_NOPTS_VALUE ? ctx->pts : sub->pts;
memset(sub, 0, sizeof(*sub));
sub->pts = pts;
ctx->pts = AV_NOPTS_VALUE;

// Blank if last object_count was 0.
if (!ctx->presentation.object_count)
Expand Down Expand Up @@ -431,8 +436,10 @@ static int display_end_segment(AVCodecContext *avctx, void *data,
static int decode(AVCodecContext *avctx, void *data, int *data_size,
AVPacket *avpkt)
{
PGSSubContext *ctx = avctx->priv_data;
const uint8_t *buf = avpkt->data;
int buf_size = avpkt->size;
AVSubtitle *sub = data;

const uint8_t *buf_end;
uint8_t segment_type;
Expand Down Expand Up @@ -477,6 +484,7 @@ static int decode(AVCodecContext *avctx, void *data, int *data_size,
break;
case PRESENTATION_SEGMENT:
parse_presentation_segment(avctx, buf, segment_length);
ctx->pts = sub->pts;
break;
case WINDOW_SEGMENT:
/*
Expand Down
3 changes: 3 additions & 0 deletions lib/ffmpeg/libavcodec/utils.c
Expand Up @@ -1396,6 +1396,9 @@ int avcodec_decode_subtitle2(AVCodecContext *avctx, AVSubtitle *sub,
avctx->pkt = avpkt;
*got_sub_ptr = 0;
avcodec_get_subtitle_defaults(sub);
if (avctx->time_base.den && avpkt->pts != AV_NOPTS_VALUE)
sub->pts = av_rescale_q(avpkt->pts,
avctx->time_base, AV_TIME_BASE_Q);
ret = avctx->codec->decode(avctx, sub, got_sub_ptr, avpkt);
if (*got_sub_ptr)
avctx->frame_number++;
Expand Down

0 comments on commit e3b35ff

Please sign in to comment.