Re: [FFmpeg-devel] [PATCH v5] fftools/ffplay: add hwaccel decoding support
> 在 2023年10月31日,下午4:40,Zhao Zhili 写道: > > >> >> On Oct 31, 2023, at 13:16, Lynne wrote: >> >> Oct 30, 2023, 18:35 by quinkbl...@foxmail.com: >> >>> On 2023/10/31 01:05, Lynne wrote: >>> Oct 30, 2023, 17:05 by quinkbl...@foxmail.com: > 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 > --- > 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 > You did it the other way. Instead of creating a device through libplacebo, just create a Vulkan device via the hwcontext, and use it for libplacebo. >>> >>> I have done both: >>> >>> 1. create vulkan device by hwcontext and import to placebo >>> >>> 2. create vulkan device by placebo and pass to hwcontext >>> >>> It's controlled by -vulkan_params create_by_placebo=1(0). Default is the >>> first behavior. I mean default is create_by_placebo=0. >>> >>> Did I miss something? >>> >> >> Thanks, I overlooked that. Is there a reason for having a setting, and >> having that as the default? > > There is no particular reason for which one be the default. Let hwcontext > create vulkan > device is easy, but the code path has been tested by fftools/ffmpeg. The > second choice > covers another code path (av_hwdevice_ctx_alloc + av_hwdevice_ctx_init) and > helps > finding bugs. > > The macOS compatibility issue was found by the first choice. The memleak > issue was found by > the second. > >> ___ >> 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". > > ___ > 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". ___ 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 v5] fftools/ffplay: add hwaccel decoding support
> On Oct 31, 2023, at 13:16, Lynne wrote: > > Oct 30, 2023, 18:35 by quinkbl...@foxmail.com: > >> >> On 2023/10/31 01:05, Lynne wrote: >> >>> Oct 30, 2023, 17:05 by quinkbl...@foxmail.com: >>> 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 --- 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 >>> You did it the other way. Instead of creating a device through libplacebo, >>> just create a Vulkan device via the hwcontext, and use it for libplacebo. >>> >> >> I have done both: >> >> 1. create vulkan device by hwcontext and import to placebo >> >> 2. create vulkan device by placebo and pass to hwcontext >> >> It's controlled by -vulkan_params create_by_placebo=1(0). Default is the >> first behavior. >> >> Did I miss something? >> > > Thanks, I overlooked that. Is there a reason for having a setting, and having > that as the default? There is no particular reason for which one be the default. Let hwcontext create vulkan device is easy, but the code path has been tested by fftools/ffmpeg. The second choice covers another code path (av_hwdevice_ctx_alloc + av_hwdevice_ctx_init) and helps finding bugs. The macOS compatibility issue was found by the first choice. The memleak issue was found by the second. > ___ > 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". ___ 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 v5] fftools/ffplay: add hwaccel decoding support
Oct 30, 2023, 18:35 by quinkbl...@foxmail.com: > > On 2023/10/31 01:05, Lynne wrote: > >> Oct 30, 2023, 17:05 by quinkbl...@foxmail.com: >> >>> 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 >>> --- >>> 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 >>> >> You did it the other way. Instead of creating a device through libplacebo, >> just create a Vulkan device via the hwcontext, and use it for libplacebo. >> > > I have done both: > > 1. create vulkan device by hwcontext and import to placebo > > 2. create vulkan device by placebo and pass to hwcontext > > It's controlled by -vulkan_params create_by_placebo=1(0). Default is the > first behavior. > > Did I miss something? > Thanks, I overlooked that. Is there a reason for having a setting, and having that as the default? ___ 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 v5] fftools/ffplay: add hwaccel decoding support
On 2023/10/31 01:05, Lynne wrote: Oct 30, 2023, 17:05 by quinkbl...@foxmail.com: 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 --- 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 You did it the other way. Instead of creating a device through libplacebo, just create a Vulkan device via the hwcontext, and use it for libplacebo. I have done both: 1. create vulkan device by hwcontext and import to placebo 2. create vulkan device by placebo and pass to hwcontext It's controlled by -vulkan_params create_by_placebo=1(0). Default is the first behavior. Did I miss something? ___ 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". ___ 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 v5] fftools/ffplay: add hwaccel decoding support
On 2023/10/31 00:04, 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 Some words about the patch. I work on this in my spare time (weekend and midnight) for fun, like most of my patches in FFmpeg and VLC. I learned a lot in this process from hwcontext_*, libplacebo, and mpv. I'm not meant to reinvent the wheel and duplicate the work of mpv or VLC, but enhance a simple test tool. I do my best to do the test. I have tested on 1. Linux with cuda and vulkan decoder, and the slow path with vdpau 2. Windows with cuda, vulkan, d3d11va (copy to CPU) 3. MacOS with videotoolbox (map to CPU). Depends on another avutil patch https://patchwork.ffmpeg.org/project/ffmpeg/patch/tencent_e37c7aac8a39cdc271b63069ae01f9692...@qq.com/ Or let libplacebo create the vulkan instance. I won't be surprised if it doesn't work on some hardware/software environment. Please review and test the patch if you are interested on it. ___ 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 v5] fftools/ffplay: add hwaccel decoding support
Oct 30, 2023, 17:05 by quinkbl...@foxmail.com: > 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 > --- > 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 > You did it the other way. Instead of creating a device through libplacebo, just create a Vulkan device via the hwcontext, and use it for libplacebo. ___ 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".
[FFmpeg-devel] [PATCH v5] 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 --- 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 | 809 ++ fftools/ffplay_renderer.h | 41 ++ 6 files changed, 956 insertions(+), 6 deletions(-) create mode 100644 fftools/ffplay_renderer.c create mode 100644 fftools/ffplay_renderer.h diff --git a/configure b/configure index 1f0b9497cb..e7628f870a 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(>pictq); +if (vk_renderer) { +vk_renderer_display(vk_renderer, vp->frame); +return; +} + if (is->subtitle_st) { if (frame_queue_nb_remaining(>subpq) > 0) { sp = frame_queue_peek(>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, _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, type, NULL, NULL, 0); +return ret; +} + /* open a given stream. Return 0 if OK */ static int