Can a GPU be used to Encode h264?
Solution 1
Using Handbrake the answer would be no. Handbrake is a CPU-only h.264 encoder, though it now is able to use OpenCL for video scaling and has some support for DXVA for video decoding.
The question linked by slhck mentions MediaCoder, but it requires either an Nvidia graphics card or an Intel CPU with a 2nd generation graphics core.
There are a couple of older products that have been obsoleted, specifically Badaboom and the ATi Avivo software.
Badaboom which could use Nvidia and Intel graphics processors to speed up the encoding process but it is now end-of-life and does not support newer graphics cards.
ATi had their own video encoder that used to be called "Avivo" before being merged into the AMD Codec Package which included the AMD Video Converter though it is no longer available.
Solution 2
x264 now supports OpenCL encoding acceleration. How much acceleration you get will depend on your graphics card's performance, on my GTS 450 I get none and with slower cards it actually slows down encoding. Better cards may help. All you need to do is add --opencl to the x264 command line. I believe handbrake makes use of the same x264 libraries and does offer the same OpenCL acceleration in newer builds.
Solution 3
https://trac.ffmpeg.org/wiki/HWAccelIntro
FFmpeg provides a subsystem for hardware acceleration.
Hardware acceleration allows to use specific devices (usually graphical card > or other specific devices) to perform multimedia processing. This allows to use dedicated hardware to perform demanding computation while freeing the CPU from such computations. Typically hardware acceleration enables specific hardware devices (usually the GPU) to perform operations related to decoding and encoding video streams, or filtering video.
When using FFmpeg the tool, HW-assisted decoding is enabled using through the
-hwaccel
option, which enables a specific decoder. Each decoder may have specific limitations (for example an H.264 decoder may only support baseline profile). HW-assisted encoding is enabled through the use of a specific encoder (for example nvenc_h264). Filtering HW-assisted processing is only supported in a few filters, and in that case you enable the OpenCL code through a filter option.There are several hardware acceleration standards API, some of which are supported to some extent by FFmpeg.
"-hwaccel auto" option allows you to select the hardware-based accelerated decoding to use for the encode session. You can add this param with "auto" before input (if your x264 is compiled with OpenCL support you can try to add -x264opts param), for example:
ffmpeg -hwaccel auto -i input -vcodec libx264 -x264opts opencl output
Sorry, but I can't remember how to list all available options for "-hwaccel".
Also you can try this: https://wiki.archlinux.org/index.php/Hardware_video_acceleration
Related videos on Youtube
peter
Updated on September 18, 2022Comments
-
peter almost 2 years
I am wondering if I get a better graphics card could it speed up h264 encoding on my machine using handbrake?
If so how can I tell what graphics card will support this?
I am aware that the GPU can do hardware decoding of h264, but am not sure about encoding.
-
slhck over 12 yearsRelated: Accelerated Video Compression – in any way, you want to have an NVIDIA card for this and be willing to spend money.
-
slhck over 12 yearsAnother related blog post: Encode Your Videos Using Your GPU
-
michael over 6 yearsFor h.264 encoding, handbrake uses software encoder x264 (videolan). Some answers below imply handbrake uses ffmpeg, which can use x264 or hw (GPU) implementations. Although this old (but still relevant) question probably is not asking "how to make handbrake faster", but rather "how to make h.264 encoding faster". Answers will have a shelf-life (some are already expired); but for now, if doing ML and/or batch processing you may have to match an implementation to your hardware
-
michael over 6 yearsfwiw, I found this comment from ffmeg interesting: "Hardware encoders typically generate output of significantly lower quality than good software encoders like x264, but are generally faster and do not use much CPU resource. (That is, they require a higher bitrate to make output with the same perceptual quality, or they make output with a lower perceptual quality at the same bitrate.) "
-
-
peter over 12 yearsSo I am using an AMD CPU at the moment, does that mean this is a waste of time for me? Can it be any NVIDIA card - oh so it has to support CUDA?
-
peter over 12 yearsI found this link, en.wikipedia.org/wiki/CUDA which suggests that quite a lot of NVIDIA cards support CUDA.
-
Mokubai over 12 yearsI've updated my answer with a link to the AMD software package that may help you use the GPU to encode video, but it requires a HD2000 series card or better. If you have a particularly powerful CPU but a budget graphics card then Handbrake may still be faster.
-
Hans Van Slooten about 12 yearsBadaboom is being end-of-lifed as of 4/18/2012.
-
totaam almost 11 yearsThe answer above is not/no-longer correct.
-
Dr.jacky over 8 yearsHow should I use OpenCL encoding acceleration?
-
Ravindra Bawane over 7 yearsIt doesn't appear this specifically answers the question, though it appears useful. How about you add some details that show how ffmpeg and it's arguments can help the OP.
-
michael over 6 yearsThis answer implies using ffmpeg instead of handbrake for h.264 encoding, which is probably fine, as the question is probably just asking for the fastest way to encode -- and presumes GPU would enable this. Note that not all GPUs are equally powerful (eg integrated GPUs vs dedicated), and CPUs also have optimizations that libraries may utilize if the library is compiled to support it. So "hardware acceleration" is the right path to go down, whether it be via CPU or GPU.