typedef struct MovieStream {
AVStream *st;
+ AVCodecContext *codec_ctx;
int done;
} MovieStream;
"did not match any stream");
return NULL;
}
- if (found->codec->codec_type != AVMEDIA_TYPE_VIDEO &&
- found->codec->codec_type != AVMEDIA_TYPE_AUDIO) {
+ if (found->codecpar->codec_type != AVMEDIA_TYPE_VIDEO &&
+ found->codecpar->codec_type != AVMEDIA_TYPE_AUDIO) {
av_log(log, AV_LOG_ERROR, "Stream specifier \"%s\" matched a %s stream,"
"currently unsupported by libavfilter\n", spec,
- av_get_media_type_string(found->codec->codec_type));
+ av_get_media_type_string(found->codecpar->codec_type));
return NULL;
}
return found;
AVCodec *codec;
int ret;
- codec = avcodec_find_decoder(st->st->codec->codec_id);
+ codec = avcodec_find_decoder(st->st->codecpar->codec_id);
if (!codec) {
av_log(log, AV_LOG_ERROR, "Failed to find any codec\n");
return AVERROR(EINVAL);
}
- st->st->codec->refcounted_frames = 1;
+ st->codec_ctx = avcodec_alloc_context3(codec);
+ if (!st->codec_ctx)
+ return AVERROR(ENOMEM);
+
+ ret = avcodec_parameters_to_context(st->codec_ctx, st->st->codecpar);
+ if (ret < 0)
+ return ret;
+
+ st->codec_ctx->refcounted_frames = 1;
- if ((ret = avcodec_open2(st->st->codec, codec, NULL)) < 0) {
+ if ((ret = avcodec_open2(st->codec_ctx, codec, NULL)) < 0) {
av_log(log, AV_LOG_ERROR, "Failed to open codec\n");
return ret;
}
static int guess_channel_layout(MovieStream *st, int st_index, void *log_ctx)
{
- AVCodecContext *dec_ctx = st->st->codec;
+ AVCodecParameters *dec_par = st->st->codecpar;
char buf[256];
- int64_t chl = av_get_default_channel_layout(dec_ctx->channels);
+ int64_t chl = av_get_default_channel_layout(dec_par->channels);
if (!chl) {
av_log(log_ctx, AV_LOG_ERROR,
"Channel layout is not set in stream %d, and could not "
"be guessed from the number of channels (%d)\n",
- st_index, dec_ctx->channels);
+ st_index, dec_par->channels);
return AVERROR(EINVAL);
}
- av_get_channel_layout_string(buf, sizeof(buf), dec_ctx->channels, chl);
+ av_get_channel_layout_string(buf, sizeof(buf), dec_par->channels, chl);
av_log(log_ctx, AV_LOG_WARNING,
"Channel layout is not set in output stream %d, "
"guessed channel layout is '%s'\n",
st_index, buf);
- dec_ctx->channel_layout = chl;
+ dec_par->channel_layout = chl;
return 0;
}
AVFilterPad pad = { 0 };
movie->out_index[movie->st[i].st->index] = i;
snprintf(name, sizeof(name), "out%d", i);
- pad.type = movie->st[i].st->codec->codec_type;
+ pad.type = movie->st[i].st->codecpar->codec_type;
pad.name = av_strdup(name);
if (!pad.name)
return AVERROR(ENOMEM);
ret = open_stream(ctx, &movie->st[i]);
if (ret < 0)
return ret;
- if ( movie->st[i].st->codec->codec->type == AVMEDIA_TYPE_AUDIO &&
- !movie->st[i].st->codec->channel_layout) {
+ if ( movie->st[i].st->codecpar->codec_type == AVMEDIA_TYPE_AUDIO &&
+ !movie->st[i].st->codecpar->channel_layout) {
ret = guess_channel_layout(&movie->st[i], i, ctx);
if (ret < 0)
return ret;
for (i = 0; i < ctx->nb_outputs; i++) {
av_freep(&ctx->output_pads[i].name);
if (movie->st[i].st)
- avcodec_close(movie->st[i].st->codec);
+ avcodec_free_context(&movie->st[i].codec_ctx);
}
av_freep(&movie->st);
av_freep(&movie->out_index);
for (i = 0; i < ctx->nb_outputs; i++) {
MovieStream *st = &movie->st[i];
- AVCodecContext *c = st->st->codec;
+ AVCodecParameters *c = st->st->codecpar;
AVFilterLink *outlink = ctx->outputs[i];
switch (c->codec_type) {
case AVMEDIA_TYPE_VIDEO:
- list[0] = c->pix_fmt;
+ list[0] = c->format;
if ((ret = ff_formats_ref(ff_make_format_list(list), &outlink->in_formats)) < 0)
return ret;
break;
case AVMEDIA_TYPE_AUDIO:
- list[0] = c->sample_fmt;
+ list[0] = c->format;
if ((ret = ff_formats_ref(ff_make_format_list(list), &outlink->in_formats)) < 0)
return ret;
list[0] = c->sample_rate;
MovieContext *movie = ctx->priv;
unsigned out_id = FF_OUTLINK_IDX(outlink);
MovieStream *st = &movie->st[out_id];
- AVCodecContext *c = st->st->codec;
+ AVCodecParameters *c = st->st->codecpar;
outlink->time_base = st->st->time_base;
}
for (i = 0; i < ctx->nb_outputs; i++) {
- avcodec_flush_buffers(movie->st[i].st->codec);
+ avcodec_flush_buffers(movie->st[i].codec_ctx);
movie->st[i].done = 0;
}
movie->eof = 0;
if (!frame)
return AVERROR(ENOMEM);
- frame_type = st->st->codec->codec_type;
+ frame_type = st->st->codecpar->codec_type;
switch (frame_type) {
case AVMEDIA_TYPE_VIDEO:
- ret = avcodec_decode_video2(st->st->codec, frame, &got_frame, pkt);
+ ret = avcodec_decode_video2(st->codec_ctx, frame, &got_frame, pkt);
break;
case AVMEDIA_TYPE_AUDIO:
- ret = avcodec_decode_audio4(st->st->codec, frame, &got_frame, pkt);
+ ret = avcodec_decode_audio4(st->codec_ctx, frame, &got_frame, pkt);
break;
default:
ret = AVERROR(ENOSYS);
movie->pkt.data = NULL;
return 0;
}
- if (!ret || st->st->codec->codec_type == AVMEDIA_TYPE_VIDEO)
+ if (!ret || st->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO)
ret = pkt->size;
pkt->data += ret;
ff_dlog(ctx, "movie_push_frame(): file:'%s' %s\n", movie->file_name,
describe_frame_to_str((char[1024]){0}, 1024, frame, frame_type, outlink));
- if (st->st->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
+ if (st->st->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
if (frame->format != outlink->format) {
av_log(ctx, AV_LOG_ERROR, "Format changed %s -> %s, discarding frame\n",
av_get_pix_fmt_name(outlink->format),