#include "libavutil/avstring.h"
#include "libavutil/opt.h"
#include "libavutil/imgutils.h"
+
+#include "libavcodec/avcodec.h"
+
#include "libavformat/avformat.h"
+
#include "avfilter.h"
#include "formats.h"
#include "internal.h"
{
MovieContext *movie = ctx->priv;
AVInputFormat *iformat = NULL;
+ AVStream *st;
AVCodec *codec;
int ret;
int64_t timestamp;
return ret;
}
movie->stream_index = ret;
- movie->codec_ctx = movie->format_ctx->streams[movie->stream_index]->codec;
+ st = movie->format_ctx->streams[movie->stream_index];
/*
* So now we've got a pointer to the so-called codec context for our video
* stream, but we still have to find the actual codec and open it.
*/
- codec = avcodec_find_decoder(movie->codec_ctx->codec_id);
+ codec = avcodec_find_decoder(st->codecpar->codec_id);
if (!codec) {
av_log(ctx, AV_LOG_ERROR, "Failed to find any codec\n");
return AVERROR(EINVAL);
}
+ movie->codec_ctx = avcodec_alloc_context3(codec);
+ if (!movie->codec_ctx)
+ return AVERROR(ENOMEM);
+
+ ret = avcodec_parameters_to_context(movie->codec_ctx, st->codecpar);
+ if (ret < 0)
+ return ret;
+
movie->codec_ctx->refcounted_frames = 1;
if ((ret = avcodec_open2(movie->codec_ctx, codec, NULL)) < 0) {
{
MovieContext *movie = ctx->priv;
- if (movie->codec_ctx)
- avcodec_close(movie->codec_ctx);
+ avcodec_free_context(&movie->codec_ctx);
if (movie->format_ctx)
avformat_close_input(&movie->format_ctx);
av_frame_free(&movie->frame);
avcodec_decode_video2(movie->codec_ctx, movie->frame, &frame_decoded, &pkt);
if (frame_decoded) {
- if (movie->frame->pkt_pts != AV_NOPTS_VALUE)
- movie->frame->pts = movie->frame->pkt_pts;
av_log(outlink->src, AV_LOG_TRACE,
"movie_get_frame(): file:'%s' pts:%"PRId64" time:%f aspect:%d/%d\n",
movie->file_name, movie->frame->pts,
movie->frame->sample_aspect_ratio.num,
movie->frame->sample_aspect_ratio.den);
// We got it. Free the packet since we are returning
- av_free_packet(&pkt);
+ av_packet_unref(&pkt);
return 0;
}
}
// Free the packet that was allocated by av_read_frame
- av_free_packet(&pkt);
+ av_packet_unref(&pkt);
}
// On multi-frame source we should stop the mixing process when