static void decode(struct sd *sd, struct demux_packet *packet) { struct sd_lavc_priv *priv = sd->priv; AVCodecContext *avctx = priv->avctx; double ts = av_q2d(av_inv_q(avctx->time_base)); AVSubtitle sub = {0}; AVPacket pkt; int ret, got_sub; mp_set_av_packet(&pkt, packet); pkt.pts = packet->pts == MP_NOPTS_VALUE ? AV_NOPTS_VALUE : packet->pts * ts; pkt.duration = packet->duration * ts; ret = avcodec_decode_subtitle2(avctx, &sub, &got_sub, &pkt); if (ret < 0) { mp_msg(MSGT_OSD, MSGL_ERR, "Error decoding subtitle\n"); } else if (got_sub) { for (int i = 0; i < sub.num_rects; i++) { char *ass_line = sub.rects[i]->ass; if (!ass_line) break; // This might contain embedded timestamps, using the "old" ffmpeg // ASS packet format, in which case pts/duration might be ignored // at a later point. sd_conv_add_packet(sd, ass_line, strlen(ass_line), packet->pts, packet->duration); } } avsubtitle_free(&sub); }
static void decode(struct sd *sd, struct demux_packet *packet) { struct sd_lavc_priv *priv = sd->priv; AVCodecContext *avctx = priv->avctx; AVSubtitle sub = {0}; AVPacket pkt; AVPacket parsed_pkt = {0}; int ret, got_sub; mp_set_av_packet(&pkt, packet, &avctx->time_base); if (sd->codec && strcmp(sd->codec, "webvtt-webm") == 0) { if (parse_webvtt(&pkt, &parsed_pkt) < 0) { MP_ERR(sd, "Error parsing subtitle\n"); goto done; } pkt = parsed_pkt; } ret = avcodec_decode_subtitle2(avctx, &sub, &got_sub, &pkt); if (ret < 0) { MP_ERR(sd, "Error decoding subtitle\n"); } else if (got_sub) { for (int i = 0; i < sub.num_rects; i++) { char *ass_line = sub.rects[i]->ass; if (!ass_line) break; // This might contain embedded timestamps, using the "old" ffmpeg // ASS packet format, in which case pts/duration might be ignored // at a later point. sd_conv_add_packet(sd, ass_line, strlen(ass_line), packet->pts, packet->duration); } } done: avsubtitle_free(&sub); av_free_packet(&parsed_pkt); }