lavfi/subtitles: switch to codecpar

This commit is contained in:
Clément Bœsch 2016-06-25 16:41:38 +02:00
parent 0296b4b8d8
commit 6bcb1e1aff

View File

@ -333,7 +333,7 @@ static av_cold int init_subtitles(AVFilterContext *ctx)
ret = -1; ret = -1;
if (ass->stream_index < fmt->nb_streams) { if (ass->stream_index < fmt->nb_streams) {
for (j = 0; j < fmt->nb_streams; j++) { 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) { if (ass->stream_index == k) {
ret = j; ret = j;
break; break;
@ -355,7 +355,7 @@ static av_cold int init_subtitles(AVFilterContext *ctx)
/* Load attached fonts */ /* Load attached fonts */
for (j = 0; j < fmt->nb_streams; j++) { for (j = 0; j < fmt->nb_streams; j++) {
AVStream *st = fmt->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)) { attachment_is_font(st)) {
const AVDictionaryEntry *tag = NULL; const AVDictionaryEntry *tag = NULL;
tag = av_dict_get(st->metadata, "filename", 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", av_log(ctx, AV_LOG_DEBUG, "Loading attached font: %s\n",
tag->value); tag->value);
ass_add_font(ass->library, tag->value, ass_add_font(ass->library, tag->value,
st->codec->extradata, st->codecpar->extradata,
st->codec->extradata_size); st->codecpar->extradata_size);
} else { } else {
av_log(ctx, AV_LOG_WARNING, av_log(ctx, AV_LOG_WARNING,
"Font attachment has no filename, ignored.\n"); "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); ass_set_fonts(ass->renderer, NULL, NULL, 1, NULL, 1);
/* Open decoder */ /* Open decoder */
dec_ctx = st->codec; dec = avcodec_find_decoder(st->codecpar->codec_id);
dec = avcodec_find_decoder(dec_ctx->codec_id);
if (!dec) { if (!dec) {
av_log(ctx, AV_LOG_ERROR, "Failed to find subtitle codec %s\n", 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); 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)) { if (dec_desc && !(dec_desc->props & AV_CODEC_PROP_TEXT_SUB)) {
av_log(ctx, AV_LOG_ERROR, av_log(ctx, AV_LOG_ERROR,
"Only text based subtitles are currently supported\n"); "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); av_dict_set(&codec_opts, "sub_charenc", ass->charenc, 0);
if (LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57,26,100)) if (LIBAVCODEC_VERSION_INT >= AV_VERSION_INT(57,26,100))
av_dict_set(&codec_opts, "sub_text_format", "ass", 0); 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) if (ret < 0)
goto end; goto end;