[FFmpeg-devel] [PATCH v3 2/2] avfilter: add a bflip_vulkan filter

Wu Jianhua jianhua.wu at intel.com
Thu Nov 25 11:08:42 EET 2021


This filter flips the input video both horizontally and vertically
in one compute pipeline, and it's no need to use two pipelines for
hflip_vulkan,vflip_vulkan anymore.

Signed-off-by: Wu Jianhua <jianhua.wu at intel.com>
---
 configure                    |  1 +
 libavfilter/allfilters.c     |  1 +
 libavfilter/vf_flip_vulkan.c | 39 +++++++++++++++++++++++++++++++++++-
 3 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/configure b/configure
index d068b11073..a7562b53c3 100755
--- a/configure
+++ b/configure
@@ -3569,6 +3569,7 @@ atempo_filter_select="rdft"
 avgblur_opencl_filter_deps="opencl"
 avgblur_vulkan_filter_deps="vulkan spirv_compiler"
 azmq_filter_deps="libzmq"
+bflip_vulkan_filter_deps="vulkan spirv_compiler"
 blackframe_filter_deps="gpl"
 bm3d_filter_deps="avcodec"
 bm3d_filter_select="dct"
diff --git a/libavfilter/allfilters.c b/libavfilter/allfilters.c
index 4bf17ef292..041292853a 100644
--- a/libavfilter/allfilters.c
+++ b/libavfilter/allfilters.c
@@ -175,6 +175,7 @@ extern const AVFilter ff_vf_avgblur_opencl;
 extern const AVFilter ff_vf_avgblur_vulkan;
 extern const AVFilter ff_vf_bbox;
 extern const AVFilter ff_vf_bench;
+extern const AVFilter ff_vf_bflip_vulkan;
 extern const AVFilter ff_vf_bilateral;
 extern const AVFilter ff_vf_bitplanenoise;
 extern const AVFilter ff_vf_blackdetect;
diff --git a/libavfilter/vf_flip_vulkan.c b/libavfilter/vf_flip_vulkan.c
index e9e04db91b..e20766e9ed 100644
--- a/libavfilter/vf_flip_vulkan.c
+++ b/libavfilter/vf_flip_vulkan.c
@@ -26,7 +26,8 @@
 
 enum FlipType {
     FLIP_VERTICAL,
-    FLIP_HORIZONTAL
+    FLIP_HORIZONTAL,
+    FLIP_BOTH
 };
 
 typedef struct FlipVulkanContext {
@@ -104,6 +105,9 @@ static av_cold int init_filter(AVFilterContext *ctx, AVFrame *in, enum FlipType
             case FLIP_VERTICAL:
                 GLSLF(2, vec4 res = texture(input_image[%i], ivec2(pos.x, size.y - pos.y));   ,i);
                 break;
+            case FLIP_BOTH:
+                GLSLF(2, vec4 res = texture(input_image[%i], ivec2(size.xy - pos.xy));,         i);
+                break;
             default:
                 GLSLF(2, vec4 res = texture(input_image[%i], pos);                            ,i);
                 break;
@@ -267,6 +271,11 @@ static int vflip_vulkan_filter_frame(AVFilterLink *link, AVFrame *in)
     return flip_vulkan_filter_frame(link, in, FLIP_VERTICAL);
 }
 
+static int bflip_vulkan_filter_frame(AVFilterLink *link, AVFrame *in)
+{
+    return flip_vulkan_filter_frame(link, in, FLIP_BOTH);
+}
+
 static const AVOption hflip_vulkan_options[] = {
     { NULL },
 };
@@ -330,3 +339,31 @@ const AVFilter ff_vf_vflip_vulkan = {
     .priv_class     = &vflip_vulkan_class,
     .flags_internal = FF_FILTER_FLAG_HWFRAME_AWARE,
 };
+
+static const AVOption bflip_vulkan_options[] = {
+    { NULL },
+};
+
+AVFILTER_DEFINE_CLASS(bflip_vulkan);
+
+static const AVFilterPad bflip_vulkan_inputs[] = {
+    {
+        .name         = "default",
+        .type         = AVMEDIA_TYPE_VIDEO,
+        .filter_frame = &bflip_vulkan_filter_frame,
+        .config_props = &ff_vk_filter_config_input,
+    }
+};
+
+const AVFilter ff_vf_bflip_vulkan = {
+    .name           = "bflip_vulkan",
+    .description    = NULL_IF_CONFIG_SMALL("Flip both horizontally and vertically"),
+    .priv_size      = sizeof(FlipVulkanContext),
+    .init           = &ff_vk_filter_init,
+    .uninit         = &flip_vulkan_uninit,
+    FILTER_INPUTS(bflip_vulkan_inputs),
+    FILTER_OUTPUTS(flip_vulkan_outputs),
+    FILTER_SINGLE_PIXFMT(AV_PIX_FMT_VULKAN),
+    .priv_class     = &bflip_vulkan_class,
+    .flags_internal = FF_FILTER_FLAG_HWFRAME_AWARE,
+};
-- 
2.25.1



More information about the ffmpeg-devel mailing list