Re: [FFmpeg-devel] [PATCH v6] fftools/ffplay: add hwaccel decoding support
Regarding to build error target Windows gpl-shared https://github.com/BtbN/FFmpeg-Builds/actions/runs/6877007331/job/18704121033#step:5:11349 I have sent an MR to libplacebo https://github.com/haasn/libplacebo/pull/222 ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH v6] fftools/ffplay: add hwaccel decoding support
On 2023/11/12 23:25, Zhao Zhili wrote: -Original Message- From: Zhao Zhili Sent: 2023年11月9日 21:06 To: FFmpeg development discussions and patches Subject: Re: [FFmpeg-devel] [PATCH v6] fftools/ffplay: add hwaccel decoding support Ping. v6 didn’t changed much compare to v5. I'm planning to push this week if no objection. Pushed. ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH v6] fftools/ffplay: add hwaccel decoding support
> -Original Message- > From: Zhao Zhili > Sent: 2023年11月9日 21:06 > To: FFmpeg development discussions and patches > Subject: Re: [FFmpeg-devel] [PATCH v6] fftools/ffplay: add hwaccel decoding > support > > Ping. v6 didn’t changed much compare to v5. > > > On Nov 8, 2023, at 00:45, Zhao Zhili wrote: > > > > From: Zhao Zhili > > > > Add vulkan renderer via libplacebo. > > > > Simple usage: > > $ ffplay -hwaccel vulkan foo.mp4 > > > > Use cuda to vulkan map: > > $ ffplay -hwaccel cuda foo.mp4 > > > > Create vulkan instance by libplacebo, and enable debug: > > $ ffplay -hwaccel vulkan \ > > -vulkan_params create_by_placebo=1:debug=1 foo.mp4 > > --- > > v6: > >1. check PL_API_VER >= 278 > >2. check hwctx->get_proc_addr against > > SDL_Vulkan_GetVkGetInstanceProcAddr() > > > > v5: > >1. add vulkan_params option. > >2. vulkan instance can be create by hwcontext or libplacebo. > > > > v4: add more optional extensions > > v3: shared vulkan instance between libplacebo and hwcontext > > > > configure | 2 +- > > doc/ffplay.texi | 12 + > > fftools/Makefile | 2 + > > fftools/ffplay.c | 96 - > > fftools/ffplay_renderer.c | 824 ++ > > fftools/ffplay_renderer.h | 41 ++ > > 6 files changed, 971 insertions(+), 6 deletions(-) > > create mode 100644 fftools/ffplay_renderer.c > > create mode 100644 fftools/ffplay_renderer.h I'm planning to push this week if no objection. ___ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-requ...@ffmpeg.org with subject "unsubscribe".
Re: [FFmpeg-devel] [PATCH v6] fftools/ffplay: add hwaccel decoding support
Ping. v6 didn’t changed much compare to v5. > On Nov 8, 2023, at 00:45, Zhao Zhili wrote: > > From: Zhao Zhili > > Add vulkan renderer via libplacebo. > > Simple usage: > $ ffplay -hwaccel vulkan foo.mp4 > > Use cuda to vulkan map: > $ ffplay -hwaccel cuda foo.mp4 > > Create vulkan instance by libplacebo, and enable debug: > $ ffplay -hwaccel vulkan \ > -vulkan_params create_by_placebo=1:debug=1 foo.mp4 > --- > v6: >1. check PL_API_VER >= 278 >2. check hwctx->get_proc_addr against SDL_Vulkan_GetVkGetInstanceProcAddr() > > v5: >1. add vulkan_params option. >2. vulkan instance can be create by hwcontext or libplacebo. > > v4: add more optional extensions > v3: shared vulkan instance between libplacebo and hwcontext > > configure | 2 +- > doc/ffplay.texi | 12 + > fftools/Makefile | 2 + > fftools/ffplay.c | 96 - > fftools/ffplay_renderer.c | 824 ++ > fftools/ffplay_renderer.h | 41 ++ > 6 files changed, 971 insertions(+), 6 deletions(-) > create mode 100644 fftools/ffplay_renderer.c > create mode 100644 fftools/ffplay_renderer.h > > diff --git a/configure b/configure > index 8ab658f730..80bfa8557c 100755 > --- a/configure > +++ b/configure > @@ -3903,7 +3903,7 @@ ffmpeg_select="aformat_filter anull_filter atrim_filter > format_filter > ffmpeg_suggest="ole32 psapi shell32" > ffplay_deps="avcodec avformat avfilter swscale swresample sdl2" > ffplay_select="crop_filter transpose_filter hflip_filter vflip_filter > rotate_filter" > -ffplay_suggest="shell32" > +ffplay_suggest="shell32 libplacebo vulkan" > ffprobe_deps="avcodec avformat" > ffprobe_suggest="shell32" > > diff --git a/doc/ffplay.texi b/doc/ffplay.texi > index 5dd860b846..93f77eeece 100644 > --- a/doc/ffplay.texi > +++ b/doc/ffplay.texi > @@ -196,6 +196,18 @@ will produce a thread pool with this many threads > available for parallel > processing. The default is 0 which means that the thread count will be > determined by the number of available CPUs. > > +@item -enable_vulkan > +Use vulkan renderer rather than SDL builtin renderer. Depends on libplacebo. > + > +@item -vulkan_params > + > +Vulkan configuration using a list of @var{key}=@var{value} pairs separated by > +":". > + > +@item -hwaccel > +Use HW accelerated decoding. Enable this option will enable vulkan renderer > +automatically. > + > @end table > > @section While playing > diff --git a/fftools/Makefile b/fftools/Makefile > index 56820e6bc8..3c763e3db9 100644 > --- a/fftools/Makefile > +++ b/fftools/Makefile > @@ -22,6 +22,8 @@ OBJS-ffmpeg += \ > fftools/sync_queue.o\ > fftools/thread_queue.o \ > > +OBJS-ffplay += fftools/ffplay_renderer.o > + > define DOFFTOOL > OBJS-$(1) += fftools/cmdutils.o fftools/opt_common.o fftools/$(1).o > $(OBJS-$(1)-yes) > ifdef HAVE_GNU_WINDRES > diff --git a/fftools/ffplay.c b/fftools/ffplay.c > index d8c69e10bc..873ee8cc74 100644 > --- a/fftools/ffplay.c > +++ b/fftools/ffplay.c > @@ -58,6 +58,7 @@ > #include > > #include "cmdutils.h" > +#include "ffplay_renderer.h" > #include "opt_common.h" > > const char program_name[] = "ffplay"; > @@ -350,6 +351,9 @@ static char *afilters = NULL; > static int autorotate = 1; > static int find_stream_info = 1; > static int filter_nbthreads = 0; > +static int enable_vulkan = 0; > +static char *vulkan_params = NULL; > +static const char *hwaccel = NULL; > > /* current context */ > static int is_full_screen; > @@ -362,6 +366,8 @@ static SDL_Renderer *renderer; > static SDL_RendererInfo renderer_info = {0}; > static SDL_AudioDeviceID audio_dev; > > +static VkRenderer *vk_renderer; > + > static const struct TextureFormatEntry { > enum AVPixelFormat format; > int texture_fmt; > @@ -954,6 +960,11 @@ static void video_image_display(VideoState *is) > SDL_Rect rect; > > vp = frame_queue_peek_last(&is->pictq); > +if (vk_renderer) { > +vk_renderer_display(vk_renderer, vp->frame); > +return; > +} > + > if (is->subtitle_st) { > if (frame_queue_nb_remaining(&is->subpq) > 0) { > sp = frame_queue_peek(&is->subpq); > @@ -1289,6 +1300,8 @@ static void do_exit(VideoState *is) > } > if (renderer) > SDL_DestroyRenderer(renderer); > +if (vk_renderer) > +vk_renderer_destroy(vk_renderer); > if (window) > SDL_DestroyWindow(window); > uninit_opts(); > @@ -2546,6 +2559,37 @@ static int audio_open(void *opaque, AVChannelLayout > *wanted_channel_layout, int > return spec.size; > } > > +static int create_hwaccel(AVBufferRef **device_ctx) > +{ > +enum AVHWDeviceType type; > +int ret; > +AVBufferRef *vk_dev; > + > +*device_ctx = NULL; > + > +if (!hwaccel) > +return 0; > + > +type = av_hwdevice_find_type_by_name(hwaccel); > +if (type == AV_HWDEVICE_TYPE_NONE) > +return AVERROR(ENOTSUP); > + > +ret = vk_renderer_get_hw_dev(vk_rende
[FFmpeg-devel] [PATCH v6] fftools/ffplay: add hwaccel decoding support
From: Zhao Zhili Add vulkan renderer via libplacebo. Simple usage: $ ffplay -hwaccel vulkan foo.mp4 Use cuda to vulkan map: $ ffplay -hwaccel cuda foo.mp4 Create vulkan instance by libplacebo, and enable debug: $ ffplay -hwaccel vulkan \ -vulkan_params create_by_placebo=1:debug=1 foo.mp4 --- v6: 1. check PL_API_VER >= 278 2. check hwctx->get_proc_addr against SDL_Vulkan_GetVkGetInstanceProcAddr() v5: 1. add vulkan_params option. 2. vulkan instance can be create by hwcontext or libplacebo. v4: add more optional extensions v3: shared vulkan instance between libplacebo and hwcontext configure | 2 +- doc/ffplay.texi | 12 + fftools/Makefile | 2 + fftools/ffplay.c | 96 - fftools/ffplay_renderer.c | 824 ++ fftools/ffplay_renderer.h | 41 ++ 6 files changed, 971 insertions(+), 6 deletions(-) create mode 100644 fftools/ffplay_renderer.c create mode 100644 fftools/ffplay_renderer.h diff --git a/configure b/configure index 8ab658f730..80bfa8557c 100755 --- a/configure +++ b/configure @@ -3903,7 +3903,7 @@ ffmpeg_select="aformat_filter anull_filter atrim_filter format_filter ffmpeg_suggest="ole32 psapi shell32" ffplay_deps="avcodec avformat avfilter swscale swresample sdl2" ffplay_select="crop_filter transpose_filter hflip_filter vflip_filter rotate_filter" -ffplay_suggest="shell32" +ffplay_suggest="shell32 libplacebo vulkan" ffprobe_deps="avcodec avformat" ffprobe_suggest="shell32" diff --git a/doc/ffplay.texi b/doc/ffplay.texi index 5dd860b846..93f77eeece 100644 --- a/doc/ffplay.texi +++ b/doc/ffplay.texi @@ -196,6 +196,18 @@ will produce a thread pool with this many threads available for parallel processing. The default is 0 which means that the thread count will be determined by the number of available CPUs. +@item -enable_vulkan +Use vulkan renderer rather than SDL builtin renderer. Depends on libplacebo. + +@item -vulkan_params + +Vulkan configuration using a list of @var{key}=@var{value} pairs separated by +":". + +@item -hwaccel +Use HW accelerated decoding. Enable this option will enable vulkan renderer +automatically. + @end table @section While playing diff --git a/fftools/Makefile b/fftools/Makefile index 56820e6bc8..3c763e3db9 100644 --- a/fftools/Makefile +++ b/fftools/Makefile @@ -22,6 +22,8 @@ OBJS-ffmpeg += \ fftools/sync_queue.o\ fftools/thread_queue.o \ +OBJS-ffplay += fftools/ffplay_renderer.o + define DOFFTOOL OBJS-$(1) += fftools/cmdutils.o fftools/opt_common.o fftools/$(1).o $(OBJS-$(1)-yes) ifdef HAVE_GNU_WINDRES diff --git a/fftools/ffplay.c b/fftools/ffplay.c index d8c69e10bc..873ee8cc74 100644 --- a/fftools/ffplay.c +++ b/fftools/ffplay.c @@ -58,6 +58,7 @@ #include #include "cmdutils.h" +#include "ffplay_renderer.h" #include "opt_common.h" const char program_name[] = "ffplay"; @@ -350,6 +351,9 @@ static char *afilters = NULL; static int autorotate = 1; static int find_stream_info = 1; static int filter_nbthreads = 0; +static int enable_vulkan = 0; +static char *vulkan_params = NULL; +static const char *hwaccel = NULL; /* current context */ static int is_full_screen; @@ -362,6 +366,8 @@ static SDL_Renderer *renderer; static SDL_RendererInfo renderer_info = {0}; static SDL_AudioDeviceID audio_dev; +static VkRenderer *vk_renderer; + static const struct TextureFormatEntry { enum AVPixelFormat format; int texture_fmt; @@ -954,6 +960,11 @@ static void video_image_display(VideoState *is) SDL_Rect rect; vp = frame_queue_peek_last(&is->pictq); +if (vk_renderer) { +vk_renderer_display(vk_renderer, vp->frame); +return; +} + if (is->subtitle_st) { if (frame_queue_nb_remaining(&is->subpq) > 0) { sp = frame_queue_peek(&is->subpq); @@ -1289,6 +1300,8 @@ static void do_exit(VideoState *is) } if (renderer) SDL_DestroyRenderer(renderer); +if (vk_renderer) +vk_renderer_destroy(vk_renderer); if (window) SDL_DestroyWindow(window); uninit_opts(); @@ -2546,6 +2559,37 @@ static int audio_open(void *opaque, AVChannelLayout *wanted_channel_layout, int return spec.size; } +static int create_hwaccel(AVBufferRef **device_ctx) +{ +enum AVHWDeviceType type; +int ret; +AVBufferRef *vk_dev; + +*device_ctx = NULL; + +if (!hwaccel) +return 0; + +type = av_hwdevice_find_type_by_name(hwaccel); +if (type == AV_HWDEVICE_TYPE_NONE) +return AVERROR(ENOTSUP); + +ret = vk_renderer_get_hw_dev(vk_renderer, &vk_dev); +if (ret < 0) +return ret; + +ret = av_hwdevice_ctx_create_derived(device_ctx, type, vk_dev, 0); +if (!ret) +return 0; + +if (ret != AVERROR(ENOSYS)) +return ret; + +av_log(NULL, AV_LOG_WARNING, "Derive %s from vulkan not supported.\n", hwaccel); +ret = av_hwdevice_ctx_create(device_ctx