OSDN Git Service

avtools: reinitialise filter chain when input video stream changes dimensions
authorKostya <kostya.shishkov@gmail.com>
Sat, 13 Aug 2011 16:44:04 +0000 (16:44 +0000)
committerAnton Khirnov <anton@khirnov.net>
Mon, 15 Aug 2011 09:53:40 +0000 (11:53 +0200)
Signed-off-by: Anton Khirnov <anton@khirnov.net>
avconv.c
avplay.c

index 877079c..18c5f07 100644 (file)
--- a/avconv.c
+++ b/avconv.c
@@ -1211,7 +1211,20 @@ static void do_video_out(AVFormatContext *s,
         sws_scale(ost->img_resample_ctx, formatted_picture->data, formatted_picture->linesize,
               0, ost->resample_height, final_picture->data, final_picture->linesize);
     }
+#else
+    if (resample_changed) {
+        avfilter_graph_free(&ost->graph);
+        if (configure_video_filters(ist, ost)) {
+            fprintf(stderr, "Error reinitialising filters!\n");
+            exit_program(1);
+        }
+    }
 #endif
+    if (resample_changed) {
+        ost->resample_width   = dec->width;
+        ost->resample_height  = dec->height;
+        ost->resample_pix_fmt = dec->pix_fmt;
+    }
 
     /* duplicates frame if needed */
     for(i=0;i<nb_frames;i++) {
index e9b58a8..710c1b5 100644 (file)
--- a/avplay.c
+++ b/avplay.c
@@ -1755,6 +1755,8 @@ static int video_thread(void *arg)
     AVFilterGraph *graph = avfilter_graph_alloc();
     AVFilterContext *filt_out = NULL;
     int64_t pos;
+    int last_w = is->video_st->codec->width;
+    int last_h = is->video_st->codec->height;
 
     if ((ret = configure_video_filters(graph, is, vfilters)) < 0)
         goto the_end;
@@ -1771,6 +1773,18 @@ static int video_thread(void *arg)
         while (is->paused && !is->videoq.abort_request)
             SDL_Delay(10);
 #if CONFIG_AVFILTER
+        if (   last_w != is->video_st->codec->width
+            || last_h != is->video_st->codec->height) {
+            av_dlog(NULL, "Changing size %dx%d -> %dx%d\n", last_w, last_h,
+                    is->video_st->codec->width, is->video_st->codec->height);
+            avfilter_graph_free(&graph);
+            graph = avfilter_graph_alloc();
+            if ((ret = configure_video_filters(graph, is, vfilters)) < 0)
+                goto the_end;
+            filt_out = is->out_video_filter;
+            last_w = is->video_st->codec->width;
+            last_h = is->video_st->codec->height;
+        }
         ret = get_filtered_video_frame(filt_out, frame, &picref, &tb);
         if (picref) {
             pts_int = picref->pts;