]> git.sesse.net Git - ffmpeg/blobdiff - libavfilter/vsrc_movie.c
dca: Move the downmix request check outside the loop
[ffmpeg] / libavfilter / vsrc_movie.c
index a99be3975880734bd4cdde96aea369ba15a081be..7fc99258488b53142cf17aea49d6b51debbfb3b7 100644 (file)
 #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"
@@ -86,6 +90,7 @@ static av_cold int movie_init(AVFilterContext *ctx)
 {
     MovieContext *movie = ctx->priv;
     AVInputFormat *iformat = NULL;
+    AVStream *st;
     AVCodec *codec;
     int ret;
     int64_t timestamp;
@@ -132,18 +137,26 @@ static av_cold int movie_init(AVFilterContext *ctx)
         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) {
@@ -174,8 +187,7 @@ static av_cold void uninit(AVFilterContext *ctx)
 {
     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);
@@ -220,8 +232,6 @@ static int movie_get_frame(AVFilterLink *outlink)
             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,
@@ -230,13 +240,13 @@ static int movie_get_frame(AVFilterLink *outlink)
                         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