X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=libavfilter%2Fvf_subtitles.c;h=0f22644cc6fd8bd882705d61c3c16f14319bc43f;hb=7fe7cdca3665b8ab1863f8f79e6881c1c4d1b630;hp=916db65b48e5eccd0aa4f1aa68c6b5a6bc09b4d0;hpb=9c4af99583a11354c005f10d095232ff1a4276c4;p=ffmpeg diff --git a/libavfilter/vf_subtitles.c b/libavfilter/vf_subtitles.c index 916db65b48e..0f22644cc6f 100644 --- a/libavfilter/vf_subtitles.c +++ b/libavfilter/vf_subtitles.c @@ -333,7 +333,7 @@ static av_cold int init_subtitles(AVFilterContext *ctx) ret = -1; if (ass->stream_index < fmt->nb_streams) { for (j = 0; j < fmt->nb_streams; j++) { - if (fmt->streams[j]->codec->codec_type == AVMEDIA_TYPE_SUBTITLE) { + if (fmt->streams[j]->codecpar->codec_type == AVMEDIA_TYPE_SUBTITLE) { if (ass->stream_index == k) { ret = j; break; @@ -355,7 +355,7 @@ static av_cold int init_subtitles(AVFilterContext *ctx) /* Load attached fonts */ for (j = 0; j < fmt->nb_streams; j++) { AVStream *st = fmt->streams[j]; - if (st->codec->codec_type == AVMEDIA_TYPE_ATTACHMENT && + if (st->codecpar->codec_type == AVMEDIA_TYPE_ATTACHMENT && attachment_is_font(st)) { const AVDictionaryEntry *tag = NULL; tag = av_dict_get(st->metadata, "filename", NULL, @@ -365,8 +365,8 @@ static av_cold int init_subtitles(AVFilterContext *ctx) av_log(ctx, AV_LOG_DEBUG, "Loading attached font: %s\n", tag->value); ass_add_font(ass->library, tag->value, - st->codec->extradata, - st->codec->extradata_size); + st->codecpar->extradata, + st->codecpar->extradata_size); } else { av_log(ctx, AV_LOG_WARNING, "Font attachment has no filename, ignored.\n"); @@ -378,14 +378,13 @@ static av_cold int init_subtitles(AVFilterContext *ctx) ass_set_fonts(ass->renderer, NULL, NULL, 1, NULL, 1); /* Open decoder */ - dec_ctx = st->codec; - dec = avcodec_find_decoder(dec_ctx->codec_id); + dec = avcodec_find_decoder(st->codecpar->codec_id); if (!dec) { av_log(ctx, AV_LOG_ERROR, "Failed to find subtitle codec %s\n", - avcodec_get_name(dec_ctx->codec_id)); + avcodec_get_name(st->codecpar->codec_id)); return AVERROR(EINVAL); } - dec_desc = avcodec_descriptor_get(dec_ctx->codec_id); + dec_desc = avcodec_descriptor_get(st->codecpar->codec_id); if (dec_desc && !(dec_desc->props & AV_CODEC_PROP_TEXT_SUB)) { av_log(ctx, AV_LOG_ERROR, "Only text based subtitles are currently supported\n"); @@ -395,7 +394,26 @@ static av_cold int init_subtitles(AVFilterContext *ctx) av_dict_set(&codec_opts, "sub_charenc", ass->charenc, 0); if (LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57,26,100)) av_dict_set(&codec_opts, "sub_text_format", "ass", 0); - ret = avcodec_open2(dec_ctx, dec, &codec_opts); + + dec_ctx = avcodec_alloc_context3(dec); + if (!dec_ctx) + return AVERROR(ENOMEM); + + ret = avcodec_parameters_to_context(dec_ctx, st->codecpar); + if (ret < 0) + goto end; + + /* + * This is required by the decoding process in order to rescale the + * timestamps: in the current API the decoded subtitles have their pts + * expressed in AV_TIME_BASE, and thus the lavc internals need to know the + * stream time base in order to achieve the rescaling. + * + * That API is old and needs to be reworked to match behaviour with A/V. + */ + av_codec_set_pkt_timebase(dec_ctx, st->time_base); + + ret = avcodec_open2(dec_ctx, NULL, &codec_opts); if (ret < 0) goto end; @@ -458,10 +476,9 @@ static av_cold int init_subtitles(AVFilterContext *ctx) end: av_dict_free(&codec_opts); - if (dec_ctx) - avcodec_close(dec_ctx); - if (fmt) - avformat_close_input(&fmt); + avcodec_close(dec_ctx); + avcodec_free_context(&dec_ctx); + avformat_close_input(&fmt); return ret; }