[PATCH] avfilter: add vf_overlay_cuda
This patch adds 'vf_overlay_cuda' filter. It draws one picture on top of another on CUDA GPU. For the end-user, it's similar to 'vf_overlay_opencl' and other overlay filters. This filter would be especially useful for building video processing pipelines that execute fully on the CUDA GPU. For example, the following pipeline would be possible: decode -> scale -> overlay -> encode, without copying frames between CPU and GPU in between. Technical details. Supported sw input formats are NV12 and YUV420P for main input, and NV12, YUV420P and YUVA420P for overlay input. Main and overlay sw formats should match (i.e, overlaying YUVA420P on NV12 is not implemented). All pixel format conversions are needed to be done with 'format' or 'scale_npp' filters before 'overlay_cuda'. It was needed to slightly modify 'hwcontext_cuda.c' to allow overlays with alpha channel: - Allow AV_PIX_FMT_YUVA420P to enable hwuploading frames with alpha channel to GPU. - Do not shift Height of 4rd plane (alpha) when uploading to GPU. Examples. - Overlay picture on top of video (main: YUVJ420P->NV12, overlay: NV12) $ ffmpeg -y -init_hw_device cuda=cuda -filter_hw_device cuda -hwaccel cuvid \ -c:v h264_cuvid -i main.mp4 \ -i ~/overlay.jpg \ -filter_complex "[1:v]format=nv12, hwupload[overlay], [0:v][overlay]overlay_cuda=x=0:y=0:shortest=false" \ -an -c:v h264_nvenc -b:v 5M output.mp4 - Overlay one video on top of another (main: NV12, overlay: NV12) $ ffmpeg -y \ -hwaccel cuvid -c:v h264_cuvid -i main.mp4 \ -hwaccel cuvid -c:v h264_cuvid -i overlay.mp4 \ -filter_complex "[1:v]scale_npp=512:-1[o], [v:0][o]overlay_cuda=x=100:y=100:shortest=true" \ -an -c:v h264_nvenc -b:v 5M output.mp4 - Overlay picture with alpha channel on top of video (main: NV12->YUV420P, overlay: RGBA->YUVA420P) $ ffmpeg -y \ -init_hw_device cuda=cuda -filter_hw_device cuda -hwaccel cuvid \ -c:v h264_cuvid -i ~/main.mp4 \ -i ~/overlay.png \ -filter_complex "[1:v]format=yuva420p, hwupload[o], [v:0]scale_npp=format=yuv420p[m], [m][o]overlay_cuda=x=0:y=0:shortest=false" \ -an -c:v h264_nvenc -b:v 5M output.mp4 Patch attached. P.S. This is my first patch, I would be grateful for any feedback to know if I'm doing things correctly or not. Thanks! Signed-off-by: Yaroslav Pogrebnyak <yyyaroslav@gmail.com> --- configure | 2 + libavfilter/Makefile | 1 + libavfilter/allfilters.c | 1 + libavfilter/vf_overlay_cuda.c | 451 +++++++++++++++++++++++++++++++++ libavfilter/vf_overlay_cuda.cu | 54 ++++ libavutil/hwcontext_cuda.c | 3 +- 6 files changed, 511 insertions(+), 1 deletion(-) create mode 100644 libavfilter/vf_overlay_cuda.c create mode 100644 libavfilter/vf_overlay_cuda.cu
Am Mi., 18. März 2020 um 08:29 Uhr schrieb Yaroslav Pogrebnyak <yyyaroslav@gmail.com>:
P.S. This is my first patch, I would be grateful for any feedback to know if I'm doing things correctly or not.
We use a different indentation for switch() statements. I also wanted to remind you to keep the options in-sync with the overlay filter but from a quick look you have already done so;-) Carl Eugen
Please split the changes into two distinct patches. One for the hwcontex changes, one for the new filter.
Hi!Is it working? I try everything but constantly get error from overlay_cuda: ffmpeg -y -init_hw_device cuda=cuda -filter_hw_device cuda -hwaccel cuvid -c:v h264_cuvid -resize 1920x1080 -i 720p.mp4 -i watermark.png -filter_complex "[1:v]format=nv12,hwupload[img];[0:v][img]overlay_cuda=x=50:y=800[out]" -map [out] -c:v h264_nvenc -b:v 6M -an -preset fast -y out_nvenc_overlay.mp4 ... ffmpeg version git-2020-04-01-afa5e38 ... [h264_cuvid @ 000001dd1b356d00] CUVID capabilities for h264_cuvid: [h264_cuvid @ 000001dd1b356d00] 8 bit: supported: 1, min_width: 48, max_width: 4096, min_height: 16, max_height: 4096 [h264_cuvid @ 000001dd1b356d00] 10 bit: supported: 0, min_width: 0, max_width: 0, min_height: 0, max_height: 0 [h264_cuvid @ 000001dd1b356d00] 12 bit: supported: 0, min_width: 0, max_width: 0, min_height: 0, max_height: 0 Stream mapping: Stream #0:0 (h264_cuvid) -> overlay_cuda:main Stream #1:0 (png) -> format overlay_cuda -> Stream #0:0 (h264_nvenc) Press [q] to stop, [?] for help [h264_cuvid @ 000001dd1b356d00] Formats: Original: cuda | HW: cuda | SW: nv12 [graph 0 input from stream 1:0 @ 000001dd2e84a100] w:1894 h:302 pixfmt:rgba tb:1/25 fr:25/1 sar:11811/11811 [graph 0 input from stream 0:0 @ 000001dd2e84ae00] w:1920 h:1080 pixfmt:cuda tb:1/24000 fr:24000/1001 sar:1/1 [auto_scaler_0 @ 000001dd2ebf4cc0] w:iw h:ih flags:'bilinear' interl:0 [Parsed_format_0 @ 000001dd2e849780] auto-inserting filter 'auto_scaler_0' between the filter 'graph 0 input from stream 1:0' and the filter 'Parsed_format_0' [auto_scaler_0 @ 000001dd2ebf4cc0] w:1894 h:302 fmt:rgba sar:11811/11811 -> w:1894 h:302 fmt:nv12 sar:1/1 flags:0x2 [overlay_cuda @ 000001dd2ebc87c0] cu->cuModuleLoadData(&ctx->cu_module, vf_overlay_cuda_ptx) failed -> CUDA_ERROR_INVALID_IMAGE: device kernel image is invalid [Parsed_overlay_cuda_2 @ 000001dd2e84b6c0] Failed to configure output pad on Parsed_overlay_cuda_2 Error reinitializing filters! Failed to inject frame into filter network: Generic error in an external library Error while processing the decoded data for stream #0:0 ... --- Original message --- From: "Yaroslav Pogrebnyak" <yyyaroslav@gmail.com> Date: 18 March 2020, 09:29:15 This patch adds 'vf_overlay_cuda' filter. It draws one picture on top of another on CUDA GPU. For the end-user, it's similar to 'vf_overlay_opencl' and other overlay filters. This filter would be especially useful for building video processing pipelines that execute fully on the CUDA GPU. For example, the following pipeline would be possible: decode -> scale -> overlay -> encode, without copying frames between CPU and GPU in between. Technical details. Supported sw input formats are NV12 and YUV420P for main input, and NV12, YUV420P and YUVA420P for overlay input. Main and overlay sw formats should match (i.e, overlaying YUVA420P on NV12 is not implemented). All pixel format conversions are needed to be done with 'format' or 'scale_npp' filters before 'overlay_cuda'. It was needed to slightly modify 'hwcontext_cuda.c' to allow overlays with alpha channel: - Allow AV_PIX_FMT_YUVA420P to enable hwuploading frames with alpha channel to GPU. - Do not shift Height of 4rd plane (alpha) when uploading to GPU. Examples. - Overlay picture on top of video (main: YUVJ420P->NV12, overlay: NV12) $ ffmpeg -y -init_hw_device cuda=cuda -filter_hw_device cuda -hwaccel cuvid \ -c:v h264_cuvid -i main.mp4 \ -i ~/overlay.jpg \ -filter_complex "[1:v]format=nv12, hwupload[overlay], [0:v][overlay]overlay_cuda=x=0:y=0:shortest=false" \ -an -c:v h264_nvenc -b:v 5M output.mp4 - Overlay one video on top of another (main: NV12, overlay: NV12) $ ffmpeg -y \ -hwaccel cuvid -c:v h264_cuvid -i main.mp4 \ -hwaccel cuvid -c:v h264_cuvid -i overlay.mp4 \ -filter_complex "[1:v]scale_npp=512:-1[o], [v:0][o]overlay_cuda=x=100:y=100:shortest=true" \ -an -c:v h264_nvenc -b:v 5M output.mp4 - Overlay picture with alpha channel on top of video (main: NV12->YUV420P, overlay: RGBA->YUVA420P) $ ffmpeg -y \ -init_hw_device cuda=cuda -filter_hw_device cuda -hwaccel cuvid \ -c:v h264_cuvid -i ~/main.mp4 \ -i ~/overlay.png \ -filter_complex "[1:v]format=yuva420p, hwupload[o], [v:0]scale_npp=format=yuv420p[m], [m][o]overlay_cuda=x=0:y=0:shortest=false" \ -an -c:v h264_nvenc -b:v 5M output.mp4 Patch attached. P.S. This is my first patch, I would be grateful for any feedback to know if I'm doing things correctly or not. Thanks! Signed-off-by: Yaroslav Pogrebnyak <yyyaroslav@gmail.com> --- configure | 2 + libavfilter/Makefile | 1 + libavfilter/allfilters.c | 1 + libavfilter/vf_overlay_cuda.c | 451 +++++++++++++++++++++++++++++++++ libavfilter/vf_overlay_cuda.cu | 54 ++++ libavutil/hwcontext_cuda.c | 3 +- 6 files changed, 511 insertions(+), 1 deletion(-) create mode 100644 libavfilter/vf_overlay_cuda.c create mode 100644 libavfilter/vf_overlay_cuda.cu _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
On Wed, 1 Apr 2020 at 16:43, Alex <3.14pi@ukr.net> wrote:
Hi!Is it working? I try everything but constantly get error from overlay_cuda:
ffmpeg -y -init_hw_device cuda=cuda -filter_hw_device cuda -hwaccel cuvid -c:v h264_cuvid -resize 1920x1080 -i 720p.mp4 -i watermark.png -filter_complex "[1:v]format=nv12,hwupload[img];[0:v][img]overlay_cuda=x=50:y=800[out]" -map [out] -c:v h264_nvenc -b:v 6M -an -preset fast -y out_nvenc_overlay.mp4 ... ffmpeg version git-2020-04-01-afa5e38 ... [h264_cuvid @ 000001dd1b356d00] CUVID capabilities for h264_cuvid: [h264_cuvid @ 000001dd1b356d00] 8 bit: supported: 1, min_width: 48, max_width: 4096, min_height: 16, max_height: 4096 [h264_cuvid @ 000001dd1b356d00] 10 bit: supported: 0, min_width: 0, max_width: 0, min_height: 0, max_height: 0 [h264_cuvid @ 000001dd1b356d00] 12 bit: supported: 0, min_width: 0, max_width: 0, min_height: 0, max_height: 0 Stream mapping: Stream #0:0 (h264_cuvid) -> overlay_cuda:main Stream #1:0 (png) -> format overlay_cuda -> Stream #0:0 (h264_nvenc) Press [q] to stop, [?] for help [h264_cuvid @ 000001dd1b356d00] Formats: Original: cuda | HW: cuda | SW: nv12 [graph 0 input from stream 1:0 @ 000001dd2e84a100] w:1894 h:302 pixfmt:rgba tb:1/25 fr:25/1 sar:11811/11811 [graph 0 input from stream 0:0 @ 000001dd2e84ae00] w:1920 h:1080 pixfmt:cuda tb:1/24000 fr:24000/1001 sar:1/1 [auto_scaler_0 @ 000001dd2ebf4cc0] w:iw h:ih flags:'bilinear' interl:0 [Parsed_format_0 @ 000001dd2e849780] auto-inserting filter 'auto_scaler_0' between the filter 'graph 0 input from stream 1:0' and the filter 'Parsed_format_0' [auto_scaler_0 @ 000001dd2ebf4cc0] w:1894 h:302 fmt:rgba sar:11811/11811 -> w:1894 h:302 fmt:nv12 sar:1/1 flags:0x2 [overlay_cuda @ 000001dd2ebc87c0] cu->cuModuleLoadData(&ctx->cu_module, vf_overlay_cuda_ptx) failed -> CUDA_ERROR_INVALID_IMAGE: device kernel image is invalid [Parsed_overlay_cuda_2 @ 000001dd2e84b6c0] Failed to configure output pad on Parsed_overlay_cuda_2 Error reinitializing filters! Failed to inject frame into filter network: Generic error in an external library Error while processing the decoded data for stream #0:0 ...
--- Original message --- From: "Yaroslav Pogrebnyak" <yyyaroslav@gmail.com> Date: 18 March 2020, 09:29:15
This patch adds 'vf_overlay_cuda' filter. It draws one picture on top of another on CUDA GPU. For the end-user, it's similar to 'vf_overlay_opencl' and other overlay filters.
This filter would be especially useful for building video processing pipelines that execute fully on the CUDA GPU. For example, the following pipeline would be possible: decode -> scale -> overlay -> encode, without copying frames between CPU and GPU in between.
Technical details.
Supported sw input formats are NV12 and YUV420P for main input, and NV12, YUV420P and YUVA420P for overlay input. Main and overlay sw formats should match (i.e, overlaying YUVA420P on NV12 is not implemented). All pixel format conversions are needed to be done with 'format' or 'scale_npp' filters before 'overlay_cuda'.
It was needed to slightly modify 'hwcontext_cuda.c' to allow overlays with alpha channel: - Allow AV_PIX_FMT_YUVA420P to enable hwuploading frames with alpha channel to GPU. - Do not shift Height of 4rd plane (alpha) when uploading to GPU.
Examples.
- Overlay picture on top of video (main: YUVJ420P->NV12, overlay: NV12) $ ffmpeg -y -init_hw_device cuda=cuda -filter_hw_device cuda -hwaccel cuvid \ -c:v h264_cuvid -i main.mp4 \ -i ~/overlay.jpg \ -filter_complex "[1:v]format=nv12, hwupload[overlay], [0:v][overlay]overlay_cuda=x=0:y=0:shortest=false" \ -an -c:v h264_nvenc -b:v 5M output.mp4
- Overlay one video on top of another (main: NV12, overlay: NV12) $ ffmpeg -y \ -hwaccel cuvid -c:v h264_cuvid -i main.mp4 \ -hwaccel cuvid -c:v h264_cuvid -i overlay.mp4 \ -filter_complex "[1:v]scale_npp=512:-1[o], [v:0][o]overlay_cuda=x=100:y=100:shortest=true" \ -an -c:v h264_nvenc -b:v 5M output.mp4
- Overlay picture with alpha channel on top of video (main: NV12->YUV420P, overlay: RGBA->YUVA420P) $ ffmpeg -y \ -init_hw_device cuda=cuda -filter_hw_device cuda -hwaccel cuvid \ -c:v h264_cuvid -i ~/main.mp4 \ -i ~/overlay.png \ -filter_complex "[1:v]format=yuva420p, hwupload[o], [v:0]scale_npp=format=yuv420p[m], [m][o]overlay_cuda=x=0:y=0:shortest=false" \ -an -c:v h264_nvenc -b:v 5M output.mp4
Patch attached.
P.S. This is my first patch, I would be grateful for any feedback to know if I'm doing things correctly or not. Thanks!
Signed-off-by: Yaroslav Pogrebnyak <yyyaroslav@gmail.com> --- configure | 2 + libavfilter/Makefile | 1 + libavfilter/allfilters.c | 1 + libavfilter/vf_overlay_cuda.c | 451 +++++++++++++++++++++++++++++++++ libavfilter/vf_overlay_cuda.cu | 54 ++++ libavutil/hwcontext_cuda.c | 3 +- 6 files changed, 511 insertions(+), 1 deletion(-) create mode 100644 libavfilter/vf_overlay_cuda.c create mode 100644 libavfilter/vf_overlay_cuda.cu
How does the NVDEC path work out? Try this: ffmpeg -y -init_hw_device cuda=cuda -filter_hw_device cuda -hwaccel cuda --hwaccel_output_format cuda -i 720p.mp4 -i watermark.png -filter_complex "[1:v]format=nv12,hwupload[img];[0:v][img]overlay_cuda=x=50:y=800[out]" -map [out] -c:v h264_nvenc -b:v 6M -an -preset fast -y out_nvenc_overlay.mp4
How does the NVDEC path work out?
It fails to even initialize the filter on his hardware, no path will work any differently.
Hi!My GPU is GTX 1080Ti. Trying Your command but same error result. I tested on windows build downloaded from https://ffmpeg.zeranoe.com/builds/ Stream mapping: Stream #0:0 (h264) -> overlay_cuda:main Stream #1:0 (png) -> format overlay_cuda -> Stream #0:0 (h264_nvenc) Press [q] to stop, [?] for help [h264 @ 00000231eee7ce40] NVDEC capabilities: [h264 @ 00000231eee7ce40] format supported: yes, max_mb_count: 65536 [h264 @ 00000231eee7ce40] min_width: 48, max_width: 4096 [h264 @ 00000231eee7ce40] min_height: 16, max_height: 4096 [h264 @ 00000231eee7ce40] Reinit context to 1280x720, pix_fmt: cuda [graph 0 input from stream 1:0 @ 0000023182422180] w:1894 h:302 pixfmt:rgba tb:1/25 fr:25/1 sar:11811/11811 [graph 0 input from stream 0:0 @ 000002318bbe1540] w:1280 h:720 pixfmt:cuda tb:1/24000 fr:24000/1001 sar:1/1 [auto_scaler_0 @ 000002318bbe55c0] w:iw h:ih flags:'bilinear' interl:0 [Parsed_format_0 @ 00000231825e4bc0] auto-inserting filter 'auto_scaler_0' between the filter 'graph 0 input from stream 1:0' and the filter 'Parsed_format_0' [auto_scaler_0 @ 000002318bbe55c0] w:1894 h:302 fmt:rgba sar:11811/11811 -> w:1894 h:302 fmt:nv12 sar:1/1 flags:0x2 [overlay_cuda @ 0000023182798140] cu->cuModuleLoadData(&ctx->cu_module, vf_overlay_cuda_ptx) failed -> CUDA_ERROR_INVALID_IMAGE: device kernel image is invalid [Parsed_overlay_cuda_2 @ 0000023182431d40] Failed to configure output pad on Parsed_overlay_cuda_2 Error reinitializing filters! Failed to inject frame into filter network: Generic error in an external library Error while processing the decoded data for stream #0:0 [AVIOContext @ 0000023182437840] Statistics: 0 seeks, 0 writeouts [AVIOContext @ 00000231eee87b80] Statistics: 409657 bytes read, 2 seeks [AVIOContext @ 000002318248e700] Statistics: 67602 bytes read, 0 seeks Conversion failed! --- Original message --- From: "Dennis Mungai" <dmngaie@gmail.com> Date: 1 April 2020, 16:51:16 On Wed, 1 Apr 2020 at 16:43, Alex <3.14pi@ukr.net> wrote:
Hi!Is it working? I try everything but constantly get error from overlay_cuda:
ffmpeg -y -init_hw_device cuda=cuda -filter_hw_device cuda -hwaccel cuvid -c:v h264_cuvid -resize 1920x1080 -i 720p.mp4 -i watermark.png -filter_complex "[1:v]format=nv12,hwupload[img];[0:v][img]overlay_cuda=x=50:y=800[out]" -map [out] -c:v h264_nvenc -b:v 6M -an -preset fast -y out_nvenc_overlay.mp4 ... ffmpeg version git-2020-04-01-afa5e38 ... [h264_cuvid @ 000001dd1b356d00] CUVID capabilities for h264_cuvid: [h264_cuvid @ 000001dd1b356d00] 8 bit: supported: 1, min_width: 48, max_width: 4096, min_height: 16, max_height: 4096 [h264_cuvid @ 000001dd1b356d00] 10 bit: supported: 0, min_width: 0, max_width: 0, min_height: 0, max_height: 0 [h264_cuvid @ 000001dd1b356d00] 12 bit: supported: 0, min_width: 0, max_width: 0, min_height: 0, max_height: 0 Stream mapping: Stream #0:0 (h264_cuvid) -> overlay_cuda:main Stream #1:0 (png) -> format overlay_cuda -> Stream #0:0 (h264_nvenc) Press [q] to stop, [?] for help [h264_cuvid @ 000001dd1b356d00] Formats: Original: cuda | HW: cuda | SW: nv12 [graph 0 input from stream 1:0 @ 000001dd2e84a100] w:1894 h:302 pixfmt:rgba tb:1/25 fr:25/1 sar:11811/11811 [graph 0 input from stream 0:0 @ 000001dd2e84ae00] w:1920 h:1080 pixfmt:cuda tb:1/24000 fr:24000/1001 sar:1/1 [auto_scaler_0 @ 000001dd2ebf4cc0] w:iw h:ih flags:'bilinear' interl:0 [Parsed_format_0 @ 000001dd2e849780] auto-inserting filter 'auto_scaler_0' between the filter 'graph 0 input from stream 1:0' and the filter 'Parsed_format_0' [auto_scaler_0 @ 000001dd2ebf4cc0] w:1894 h:302 fmt:rgba sar:11811/11811 -> w:1894 h:302 fmt:nv12 sar:1/1 flags:0x2 [overlay_cuda @ 000001dd2ebc87c0] cu->cuModuleLoadData(&ctx->cu_module, vf_overlay_cuda_ptx) failed -> CUDA_ERROR_INVALID_IMAGE: device kernel image is invalid [Parsed_overlay_cuda_2 @ 000001dd2e84b6c0] Failed to configure output pad on Parsed_overlay_cuda_2 Error reinitializing filters! Failed to inject frame into filter network: Generic error in an external library Error while processing the decoded data for stream #0:0 ...
--- Original message --- From: "Yaroslav Pogrebnyak" <yyyaroslav@gmail.com> Date: 18 March 2020, 09:29:15
This patch adds 'vf_overlay_cuda' filter. It draws one picture on top of another on CUDA GPU. For the end-user, it's similar to 'vf_overlay_opencl' and other overlay filters.
This filter would be especially useful for building video processing pipelines that execute fully on the CUDA GPU. For example, the following pipeline would be possible: decode -> scale -> overlay -> encode, without copying frames between CPU and GPU in between.
Technical details.
Supported sw input formats are NV12 and YUV420P for main input, and NV12, YUV420P and YUVA420P for overlay input. Main and overlay sw formats should match (i.e, overlaying YUVA420P on NV12 is not implemented). All pixel format conversions are needed to be done with 'format' or 'scale_npp' filters before 'overlay_cuda'.
It was needed to slightly modify 'hwcontext_cuda.c' to allow overlays with alpha channel: - Allow AV_PIX_FMT_YUVA420P to enable hwuploading frames with alpha channel to GPU. - Do not shift Height of 4rd plane (alpha) when uploading to GPU.
Examples.
- Overlay picture on top of video (main: YUVJ420P->NV12, overlay: NV12) $ ffmpeg -y -init_hw_device cuda=cuda -filter_hw_device cuda -hwaccel cuvid \ -c:v h264_cuvid -i main.mp4 \ -i ~/overlay.jpg \ -filter_complex "[1:v]format=nv12, hwupload[overlay], [0:v][overlay]overlay_cuda=x=0:y=0:shortest=false" \ -an -c:v h264_nvenc -b:v 5M output.mp4
- Overlay one video on top of another (main: NV12, overlay: NV12) $ ffmpeg -y \ -hwaccel cuvid -c:v h264_cuvid -i main.mp4 \ -hwaccel cuvid -c:v h264_cuvid -i overlay.mp4 \ -filter_complex "[1:v]scale_npp=512:-1[o], [v:0][o]overlay_cuda=x=100:y=100:shortest=true" \ -an -c:v h264_nvenc -b:v 5M output.mp4
- Overlay picture with alpha channel on top of video (main: NV12->YUV420P, overlay: RGBA->YUVA420P) $ ffmpeg -y \ -init_hw_device cuda=cuda -filter_hw_device cuda -hwaccel cuvid \ -c:v h264_cuvid -i ~/main.mp4 \ -i ~/overlay.png \ -filter_complex "[1:v]format=yuva420p, hwupload[o], [v:0]scale_npp=format=yuv420p[m], [m][o]overlay_cuda=x=0:y=0:shortest=false" \ -an -c:v h264_nvenc -b:v 5M output.mp4
Patch attached.
P.S. This is my first patch, I would be grateful for any feedback to know if I'm doing things correctly or not. Thanks!
Signed-off-by: Yaroslav Pogrebnyak <yyyaroslav@gmail.com> --- configure | 2 + libavfilter/Makefile | 1 + libavfilter/allfilters.c | 1 + libavfilter/vf_overlay_cuda.c | 451 +++++++++++++++++++++++++++++++++ libavfilter/vf_overlay_cuda.cu | 54 ++++ libavutil/hwcontext_cuda.c | 3 +- 6 files changed, 511 insertions(+), 1 deletion(-) create mode 100644 libavfilter/vf_overlay_cuda.c create mode 100644 libavfilter/vf_overlay_cuda.cu
How does the NVDEC path work out? Try this: ffmpeg -y -init_hw_device cuda=cuda -filter_hw_device cuda -hwaccel cuda --hwaccel_output_format cuda -i 720p.mp4 -i watermark.png -filter_complex "[1:v]format=nv12,hwupload[img];[0:v][img]overlay_cuda=x=50:y=800[out]" -map [out] -c:v h264_nvenc -b:v 6M -an -preset fast -y out_nvenc_overlay.mp4 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
On 01.04.2020 15:43, Alex wrote:
Hi!Is it working? I try everything but constantly get error from overlay_cuda:
ffmpeg -y -init_hw_device cuda=cuda -filter_hw_device cuda -hwaccel cuvid -c:v h264_cuvid -resize 1920x1080 -i 720p.mp4 -i watermark.png -filter_complex "[1:v]format=nv12,hwupload[img];[0:v][img]overlay_cuda=x=50:y=800[out]" -map [out] -c:v h264_nvenc -b:v 6M -an -preset fast -y out_nvenc_overlay.mp4 ... ffmpeg version git-2020-04-01-afa5e38 ... [h264_cuvid @ 000001dd1b356d00] CUVID capabilities for h264_cuvid: [h264_cuvid @ 000001dd1b356d00] 8 bit: supported: 1, min_width: 48, max_width: 4096, min_height: 16, max_height: 4096 [h264_cuvid @ 000001dd1b356d00] 10 bit: supported: 0, min_width: 0, max_width: 0, min_height: 0, max_height: 0 [h264_cuvid @ 000001dd1b356d00] 12 bit: supported: 0, min_width: 0, max_width: 0, min_height: 0, max_height: 0 Stream mapping: Stream #0:0 (h264_cuvid) -> overlay_cuda:main Stream #1:0 (png) -> format overlay_cuda -> Stream #0:0 (h264_nvenc) Press [q] to stop, [?] for help [h264_cuvid @ 000001dd1b356d00] Formats: Original: cuda | HW: cuda | SW: nv12 [graph 0 input from stream 1:0 @ 000001dd2e84a100] w:1894 h:302 pixfmt:rgba tb:1/25 fr:25/1 sar:11811/11811 [graph 0 input from stream 0:0 @ 000001dd2e84ae00] w:1920 h:1080 pixfmt:cuda tb:1/24000 fr:24000/1001 sar:1/1 [auto_scaler_0 @ 000001dd2ebf4cc0] w:iw h:ih flags:'bilinear' interl:0 [Parsed_format_0 @ 000001dd2e849780] auto-inserting filter 'auto_scaler_0' between the filter 'graph 0 input from stream 1:0' and the filter 'Parsed_format_0' [auto_scaler_0 @ 000001dd2ebf4cc0] w:1894 h:302 fmt:rgba sar:11811/11811 -> w:1894 h:302 fmt:nv12 sar:1/1 flags:0x2 [overlay_cuda @ 000001dd2ebc87c0] cu->cuModuleLoadData(&ctx->cu_module, vf_overlay_cuda_ptx) failed -> CUDA_ERROR_INVALID_IMAGE: device kernel image is invalid
Looks like your GPU does not support some of the required features of this filters CUDA Kernel. Which seems odd, given it's general simplicity. What GPU is that?
My GPU is GTX 1080Ti. --- Original message --- From: "Timo Rothenpieler" <timo@rothenpieler.org> Date: 1 April 2020, 16:51:27 On 01.04.2020 15:43, Alex wrote:
Hi!Is it working? I try everything but constantly get error from overlay_cuda:
ffmpeg -y -init_hw_device cuda=cuda -filter_hw_device cuda -hwaccel cuvid -c:v h264_cuvid -resize 1920x1080 -i 720p.mp4 -i watermark.png -filter_complex "[1:v]format=nv12,hwupload[img];[0:v][img]overlay_cuda=x=50:y=800[out]" -map [out] -c:v h264_nvenc -b:v 6M -an -preset fast -y out_nvenc_overlay.mp4 ... ffmpeg version git-2020-04-01-afa5e38 ... [h264_cuvid @ 000001dd1b356d00] CUVID capabilities for h264_cuvid: [h264_cuvid @ 000001dd1b356d00] 8 bit: supported: 1, min_width: 48, max_width: 4096, min_height: 16, max_height: 4096 [h264_cuvid @ 000001dd1b356d00] 10 bit: supported: 0, min_width: 0, max_width: 0, min_height: 0, max_height: 0 [h264_cuvid @ 000001dd1b356d00] 12 bit: supported: 0, min_width: 0, max_width: 0, min_height: 0, max_height: 0 Stream mapping: Stream #0:0 (h264_cuvid) -> overlay_cuda:main Stream #1:0 (png) -> format overlay_cuda -> Stream #0:0 (h264_nvenc) Press [q] to stop, [?] for help [h264_cuvid @ 000001dd1b356d00] Formats: Original: cuda | HW: cuda | SW: nv12 [graph 0 input from stream 1:0 @ 000001dd2e84a100] w:1894 h:302 pixfmt:rgba tb:1/25 fr:25/1 sar:11811/11811 [graph 0 input from stream 0:0 @ 000001dd2e84ae00] w:1920 h:1080 pixfmt:cuda tb:1/24000 fr:24000/1001 sar:1/1 [auto_scaler_0 @ 000001dd2ebf4cc0] w:iw h:ih flags:'bilinear' interl:0 [Parsed_format_0 @ 000001dd2e849780] auto-inserting filter 'auto_scaler_0' between the filter 'graph 0 input from stream 1:0' and the filter 'Parsed_format_0' [auto_scaler_0 @ 000001dd2ebf4cc0] w:1894 h:302 fmt:rgba sar:11811/11811 -> w:1894 h:302 fmt:nv12 sar:1/1 flags:0x2 [overlay_cuda @ 000001dd2ebc87c0] cu->cuModuleLoadData(&ctx->cu_module, vf_overlay_cuda_ptx) failed -> CUDA_ERROR_INVALID_IMAGE: device kernel image is invalid
Looks like your GPU does not support some of the required features of this filters CUDA Kernel. Which seems odd, given it's general simplicity. What GPU is that? _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
Driver 445.75 (Win 10) --- Original message --- From: "Alex" <3.14pi@ukr.net> Date: 1 April 2020, 17:01:28 My GPU is GTX 1080Ti. --- Original message --- From: "Timo Rothenpieler" <timo@rothenpieler.org> Date: 1 April 2020, 16:51:27 On 01.04.2020 15:43, Alex wrote:
Hi!Is it working? I try everything but constantly get error from overlay_cuda:
ffmpeg -y -init_hw_device cuda=cuda -filter_hw_device cuda -hwaccel cuvid -c:v h264_cuvid -resize 1920x1080 -i 720p.mp4 -i watermark.png -filter_complex "[1:v]format=nv12,hwupload[img];[0:v][img]overlay_cuda=x=50:y=800[out]" -map [out] -c:v h264_nvenc -b:v 6M -an -preset fast -y out_nvenc_overlay.mp4 ... ffmpeg version git-2020-04-01-afa5e38 ... [h264_cuvid @ 000001dd1b356d00] CUVID capabilities for h264_cuvid: [h264_cuvid @ 000001dd1b356d00] 8 bit: supported: 1, min_width: 48, max_width: 4096, min_height: 16, max_height: 4096 [h264_cuvid @ 000001dd1b356d00] 10 bit: supported: 0, min_width: 0, max_width: 0, min_height: 0, max_height: 0 [h264_cuvid @ 000001dd1b356d00] 12 bit: supported: 0, min_width: 0, max_width: 0, min_height: 0, max_height: 0 Stream mapping: Stream #0:0 (h264_cuvid) -> overlay_cuda:main Stream #1:0 (png) -> format overlay_cuda -> Stream #0:0 (h264_nvenc) Press [q] to stop, [?] for help [h264_cuvid @ 000001dd1b356d00] Formats: Original: cuda | HW: cuda | SW: nv12 [graph 0 input from stream 1:0 @ 000001dd2e84a100] w:1894 h:302 pixfmt:rgba tb:1/25 fr:25/1 sar:11811/11811 [graph 0 input from stream 0:0 @ 000001dd2e84ae00] w:1920 h:1080 pixfmt:cuda tb:1/24000 fr:24000/1001 sar:1/1 [auto_scaler_0 @ 000001dd2ebf4cc0] w:iw h:ih flags:'bilinear' interl:0 [Parsed_format_0 @ 000001dd2e849780] auto-inserting filter 'auto_scaler_0' between the filter 'graph 0 input from stream 1:0' and the filter 'Parsed_format_0' [auto_scaler_0 @ 000001dd2ebf4cc0] w:1894 h:302 fmt:rgba sar:11811/11811 -> w:1894 h:302 fmt:nv12 sar:1/1 flags:0x2 [overlay_cuda @ 000001dd2ebc87c0] cu->cuModuleLoadData(&ctx->cu_module, vf_overlay_cuda_ptx) failed -> CUDA_ERROR_INVALID_IMAGE: device kernel image is invalid
Looks like your GPU does not support some of the required features of this filters CUDA Kernel. Which seems odd, given it's general simplicity. What GPU is that? _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@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-request@ffmpeg.org with subject "unsubscribe".
On 01.04.2020 16:14, Alex wrote:
Driver 445.75 (Win 10)
I just tested a similar commandline on the same driver: ./ffmpeg_g.exe -v verbose -init_hw_device cuda=cuda -filter_hw_device cuda -hwaccel_output_format cuda -hwaccel cuda -i recode.mkv -i test.png -filter_complex "[1:v]format=nv12,hwupload[p],[0:v][p]overlay_cuda=x=100:y=100" -an -c:v h264_nvenc -y out.mp4 And that works perfectly fine on a RTX2070S. Make sure your driver installation is not somehow damaged.
Driver is ok (I just updated it and same result), and nvenc working without without cuda filters. But with overlay_cuda or scale_cuda ffmpeg is failing. Then I try to install ffmpeg on linux machine and looks like all working ok, but not on windows for me. --- Original message --- From: "Timo Rothenpieler" <timo@rothenpieler.org> Date: 1 April 2020, 18:04:05 On 01.04.2020 16:14, Alex wrote:
Driver 445.75 (Win 10)
I just tested a similar commandline on the same driver: ./ffmpeg_g.exe -v verbose -init_hw_device cuda=cuda -filter_hw_device cuda -hwaccel_output_format cuda -hwaccel cuda -i recode.mkv -i test.png -filter_complex "[1:v]format=nv12,hwupload[p],[0:v][p]overlay_cuda=x=100:y=100" -an -c:v h264_nvenc -y out.mp4 And that works perfectly fine on a RTX2070S. Make sure your driver installation is not somehow damaged. _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
But on my linux machine is rtx2070 card, not 1080ti. Do You testing filter on 10xx gpu card? 1 April 2020, 18:12:22, by "Alex" < 3.14pi@ukr.net >: Driver is ok (I just updated it and same result), and nvenc working without without cuda filters. But with overlay_cuda or scale_cuda ffmpeg is failing. Then I try to install ffmpeg on linux machine and looks like all working ok, but not on windows for me. --- Original message --- From: "Timo Rothenpieler" <timo@rothenpieler.org> Date: 1 April 2020, 18:04:05 On 01.04.2020 16:14, Alex wrote:
Driver 445.75 (Win 10)
I just tested a similar commandline on the same driver: ./ffmpeg_g.exe -v verbose -init_hw_device cuda=cuda -filter_hw_device cuda -hwaccel_output_format cuda -hwaccel cuda -i recode.mkv -i test.png -filter_complex "[1:v]format=nv12,hwupload[p],[0:v][p]overlay_cuda=x=100:y=100" -an -c:v h264_nvenc -y out.mp4 And that works perfectly fine on a RTX2070S. Make sure your driver installation is not somehow damaged. _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@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-request@ffmpeg.org with subject "unsubscribe".
On 01.04.2020 17:12, Alex wrote:
Driver is ok (I just updated it and same result), and nvenc working without without cuda filters. But with overlay_cuda or scale_cuda ffmpeg is failing. Then I try to install ffmpeg on linux machine and looks like all working ok, but not on windows for me.
Do not top-post on this list. I just tested this, and with Zeranoes Windows-Builds, I am getting the same kind of CUDA-Kernel-Errors. With my own build, everything works fine. So you will have to complain to Zeranoe or whoever made your binaries.
Hi Yaroslav First of all, thanks for your wonderful work!, works as described, I started to use it in another Open source project "Opencast". Well I started to make some tests and I wrote a more comprehensive example in Stack Overflow of it: https://stackoverflow.com/questions/63471028/how-to-use-the-ffmpeg-overlay-c... Because of my exhaustive testing, I found some bugs with the filter: - You can't use images as a lower source. - If you try to generate an still mp4 movie (For example a blank color background and try to overlay it, gives you an error. - Transparent PNG gives blurry image with artifacts when is use for an overlay. Another error, that I think it comes from the GPU used. If I use a latest generation Quadro or Geforce RTX, the filter works without problems. but if I use a more older model (Quadro K6000, Kepler), it gives you this error: [overlay_cuda @ 0x72356c0] cu->cuModuleLoadData(&ctx->cu_module, vf_overlay_cuda_ptx) failed -> CUDA_ERROR_INVALID_PTX: a PTX JIT compilation failed [Parsed_overlay_cuda_6 @ 0x72355c0] Failed to configure output pad on Parsed_overlay_cuda_6 I think this goes to an issue with the Compute Capability version supported. The K6000 only supports up to version 3.5 If you want, I can make a more complete report on the FFMPEG bug tracker. Best Regards Max.
participants (6)
-
Alex -
Carl Eugen Hoyos -
Dennis Mungai -
Maximiliano Lira Del Canto -
Timo Rothenpieler -
Yaroslav Pogrebnyak