diff mbox series

[FFmpeg-devel,04/23] lavfi/f_select: allow selection based on view ID

Message ID 20240914111036.17164-5-anton@khirnov.net
State New
Headers show
Series [FFmpeg-devel,01/23] compat: drop gcc, suncc, and pthreads stdatomic emulation | expand

Checks

Context Check Description
yinshiyou/make_loongarch64 success Make finished
yinshiyou/make_fate_loongarch64 success Make fate finished
andriy/make_x86 success Make finished
andriy/make_fate_x86 success Make fate finished

Commit Message

Anton Khirnov Sept. 14, 2024, 10:45 a.m. UTC
Can be used together with the split filter to decompose multiview video
into individual views.
---
 doc/filters.texi       | 3 +++
 libavfilter/f_select.c | 9 +++++++++
 2 files changed, 12 insertions(+)
diff mbox series

Patch

diff --git a/doc/filters.texi b/doc/filters.texi
index db2f4b7ea7..428986a1e9 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -31111,6 +31111,9 @@  Represents the width of the input video frame.
 @item ih @emph{(video only)}
 Represents the height of the input video frame.
 
+@item view @emph{(video only)}
+View ID for multi-view video.
+
 @end table
 
 The default value of the select expression is "1".
diff --git a/libavfilter/f_select.c b/libavfilter/f_select.c
index 6ba96bd7c5..ba0ae31f1b 100644
--- a/libavfilter/f_select.c
+++ b/libavfilter/f_select.c
@@ -93,6 +93,8 @@  static const char *const var_names[] = {
     "ih",                ///< ih: Represents the height of the input video frame.
     "iw",                ///< iw: Represents the width of the input video frame.
 
+    "view",
+
     NULL
 };
 
@@ -150,6 +152,8 @@  enum var_name {
     VAR_IH,
     VAR_IW,
 
+    VAR_VIEW,
+
     VAR_VARS_NB
 };
 
@@ -343,6 +347,7 @@  static void select_frame(AVFilterContext *ctx, AVFrame *frame)
     SelectContext *select = ctx->priv;
     AVFilterLink *inlink = ctx->inputs[0];
     FilterLink      *inl = ff_filter_link(inlink);
+    const AVFrameSideData *sd;
     double res;
 
     if (isnan(select->var_values[VAR_START_PTS]))
@@ -381,6 +386,10 @@  FF_ENABLE_DEPRECATION_WARNINGS
             snprintf(buf, sizeof(buf), "%f", select->var_values[VAR_SCENE]);
             av_dict_set(&frame->metadata, "lavfi.scene_score", buf, 0);
         }
+
+        sd = av_frame_side_data_get(frame->side_data, frame->nb_side_data,
+                                    AV_FRAME_DATA_VIEW_ID);
+        select->var_values[VAR_VIEW] = sd ? *(int*)sd->data : NAN;
         break;
     }