Browse code

ffplay: add support for toggling between multiple video filters with the w key

Signed-off-by: Marton Balint <cus@passwd.hu>

Marton Balint authored on 2014/01/07 05:14:23
Showing 2 changed files
... ...
@@ -84,6 +84,9 @@ output. In the filtergraph, the input is associated to the label
84 84
 ffmpeg-filters manual for more information about the filtergraph
85 85
 syntax.
86 86
 
87
+You can specify this parameter multiple times and cycle through the specified
88
+filtergraphs along with the show modes by pressing the key @key{w}.
89
+
87 90
 @item -af @var{filtergraph}
88 91
 @var{filtergraph} is a description of the filtergraph to apply to
89 92
 the input audio.
... ...
@@ -186,7 +189,7 @@ Cycle subtitle channel in the current program.
186 186
 Cycle program.
187 187
 
188 188
 @item w
189
-Show audio waves.
189
+Cycle video filters or show modes.
190 190
 
191 191
 @item s
192 192
 Step to the next frame.
... ...
@@ -268,6 +268,7 @@ typedef struct VideoState {
268 268
     int step;
269 269
 
270 270
 #if CONFIG_AVFILTER
271
+    int vfilter_idx;
271 272
     AVFilterContext *in_video_filter;   // the first filter in the video chain
272 273
     AVFilterContext *out_video_filter;  // the last filter in the video chain
273 274
     AVFilterContext *in_audio_filter;   // the first filter in the audio chain
... ...
@@ -324,7 +325,8 @@ double rdftspeed = 0.02;
324 324
 static int64_t cursor_last_shown;
325 325
 static int cursor_hidden = 0;
326 326
 #if CONFIG_AVFILTER
327
-static char *vfilters = NULL;
327
+static const char **vfilters_list = NULL;
328
+static int nb_vfilters = 0;
328 329
 static char *afilters = NULL;
329 330
 #endif
330 331
 
... ...
@@ -339,6 +341,15 @@ static AVPacket flush_pkt;
339 339
 
340 340
 static SDL_Surface *screen;
341 341
 
342
+#if CONFIG_AVFILTER
343
+static int opt_add_vfilter(void *optctx, const char *opt, const char *arg)
344
+{
345
+    GROW_ARRAY(vfilters_list, nb_vfilters);
346
+    vfilters_list[nb_vfilters - 1] = arg;
347
+    return 0;
348
+}
349
+#endif
350
+
342 351
 static inline
343 352
 int cmp_audio_fmts(enum AVSampleFormat fmt1, int64_t channel_count1,
344 353
                    enum AVSampleFormat fmt2, int64_t channel_count2)
... ...
@@ -1051,7 +1062,7 @@ static void do_exit(VideoState *is)
1051 1051
     av_lockmgr_register(NULL);
1052 1052
     uninit_opts();
1053 1053
 #if CONFIG_AVFILTER
1054
-    av_freep(&vfilters);
1054
+    av_freep(&vfilters_list);
1055 1055
 #endif
1056 1056
     avformat_network_deinit();
1057 1057
     if (show_status)
... ...
@@ -1919,6 +1930,7 @@ static int video_thread(void *arg)
1919 1919
     int last_h = 0;
1920 1920
     enum AVPixelFormat last_format = -2;
1921 1921
     int last_serial = -1;
1922
+    int last_vfilter_idx = 0;
1922 1923
 #endif
1923 1924
 
1924 1925
     for (;;) {
... ...
@@ -1937,7 +1949,8 @@ static int video_thread(void *arg)
1937 1937
         if (   last_w != frame->width
1938 1938
             || last_h != frame->height
1939 1939
             || last_format != frame->format
1940
-            || last_serial != serial) {
1940
+            || last_serial != serial
1941
+            || last_vfilter_idx != is->vfilter_idx) {
1941 1942
             av_log(NULL, AV_LOG_DEBUG,
1942 1943
                    "Video frame changed from size:%dx%d format:%s serial:%d to size:%dx%d format:%s serial:%d\n",
1943 1944
                    last_w, last_h,
... ...
@@ -1946,7 +1959,7 @@ static int video_thread(void *arg)
1946 1946
                    (const char *)av_x_if_null(av_get_pix_fmt_name(frame->format), "none"), serial);
1947 1947
             avfilter_graph_free(&graph);
1948 1948
             graph = avfilter_graph_alloc();
1949
-            if ((ret = configure_video_filters(graph, is, vfilters, frame)) < 0) {
1949
+            if ((ret = configure_video_filters(graph, is, vfilters_list ? vfilters_list[is->vfilter_idx] : NULL, frame)) < 0) {
1950 1950
                 SDL_Event event;
1951 1951
                 event.type = FF_QUIT_EVENT;
1952 1952
                 event.user.data1 = is;
... ...
@@ -1959,6 +1972,7 @@ static int video_thread(void *arg)
1959 1959
             last_h = frame->height;
1960 1960
             last_format = frame->format;
1961 1961
             last_serial = serial;
1962
+            last_vfilter_idx = is->vfilter_idx;
1962 1963
             frame_rate = filt_out->inputs[0]->frame_rate;
1963 1964
         }
1964 1965
 
... ...
@@ -3263,7 +3277,17 @@ static void event_loop(VideoState *cur_stream)
3263 3263
                 stream_cycle_channel(cur_stream, AVMEDIA_TYPE_SUBTITLE);
3264 3264
                 break;
3265 3265
             case SDLK_w:
3266
+#if CONFIG_AVFILTER
3267
+                if (cur_stream->show_mode == SHOW_MODE_VIDEO && cur_stream->vfilter_idx < nb_vfilters - 1) {
3268
+                    if (++cur_stream->vfilter_idx >= nb_vfilters)
3269
+                        cur_stream->vfilter_idx = 0;
3270
+                } else {
3271
+                    cur_stream->vfilter_idx = 0;
3272
+                    toggle_audio_display(cur_stream);
3273
+                }
3274
+#else
3266 3275
                 toggle_audio_display(cur_stream);
3276
+#endif
3267 3277
                 break;
3268 3278
             case SDLK_PAGEUP:
3269 3279
                 if (cur_stream->ic->nb_chapters <= 1) {
... ...
@@ -3529,7 +3553,7 @@ static const OptionDef options[] = {
3529 3529
     { "infbuf", OPT_BOOL | OPT_EXPERT, { &infinite_buffer }, "don't limit the input buffer size (useful with realtime streams)", "" },
3530 3530
     { "window_title", OPT_STRING | HAS_ARG, { &window_title }, "set window title", "window title" },
3531 3531
 #if CONFIG_AVFILTER
3532
-    { "vf", OPT_STRING | HAS_ARG, { &vfilters }, "set video filters", "filter_graph" },
3532
+    { "vf", OPT_EXPERT | HAS_ARG, { .func_arg = opt_add_vfilter }, "set video filters", "filter_graph" },
3533 3533
     { "af", OPT_STRING | HAS_ARG, { &afilters }, "set audio filters", "filter_graph" },
3534 3534
 #endif
3535 3535
     { "rdftspeed", OPT_INT | HAS_ARG| OPT_AUDIO | OPT_EXPERT, { &rdftspeed }, "rdft speed", "msecs" },
... ...
@@ -3572,7 +3596,7 @@ void show_help_default(const char *opt, const char *arg)
3572 3572
            "v                   cycle video channel\n"
3573 3573
            "t                   cycle subtitle channel in the current program\n"
3574 3574
            "c                   cycle program\n"
3575
-           "w                   show audio waves\n"
3575
+           "w                   cycle video filters or show modes\n"
3576 3576
            "s                   activate frame-step mode\n"
3577 3577
            "left/right          seek backward/forward 10 seconds\n"
3578 3578
            "down/up             seek backward/forward 1 minute\n"