FFMPEG and filters (drawtext,drawbox) using GPU acceleration

I am trying to find a way to use the drawbox and drawtext ffmpeg filters to overlay text onto video,and speed this process up using GPU acceleration. From the reference materials listed below, I have been unsuccessful in finding a way to do so, but I wanted to check with the community to see if there is are additional approaches.

Below is an example of drawtext and drawbox being used together.

ffmpeg -i <input.mp4> -vf "[in] drawbox= x=iw*0.75:y=ih*0.88:w=iw*0.25:h=ih*0.12:color=black@0.7:t=fill, drawtext=fontsize=20:fontcolor=White:text='Test Line 1':x=(w*.75)+15:y=(h*.88)+15,[out]" -y  C:/Users/Garrett/Desktop/video/test.mp4

Below is an example using GPU hardware acceleration from documentation.

ffmpeg -vsync 0 -hwaccel cuvid -hwaccel_device 1 -c:v h264_cuvid -i input.mp4 -c:a copy -c:v h264_nvenc -b:v 5M output.mp4

What I’d like to do is somehow combine these commands so I get the output of command 1 with the speed of command 2. I’ve tried placing the drawtext portion standalone portion within command 2 without success.

FFMPEG (drawbox): FFmpeg Filters Documentation
FFMPEG (drawtext): FFmpeg Filters Documentation
NVIDIA transcoding guide: NVIDIA FFmpeg Transcoding Guide | NVIDIA Technical Blog
NVIDIA (ffmpeg): FFmpeg | NVIDIA Developer

3 Likes

There is no good way to do this. drawtext and drawbox are not supported on the GPU so if you decode/encoder on the GPU you would have to copy each frame to the CPU in order to apply the draw text/box filters. In all likelihood this would be slower than just running on the CPU. If you wanted to try it you could use the hwdownload and hwupload filters to move the frame to the CPU, apply the draw filters and then copy it back to the GPU.

Thanks for the reply.

What if we used OpenGL, use this as a draw renderer and apply it directly to the GPU on the run? OpenGL is a GPU backend which can draw directly using GPU. Can OpenGL be integrated or used as a filter in FFMPEG?