🇰🇷 한국어로 읽기 (Korean version): 임베디드 리눅스 GStreamer에서 하드웨어 인코더(VPU)가 안 쓰이고 CPU가 치솟을 때 점검할 곳 6가지와 해결 방향
You want to compress camera video to H.264 or H.265 on an embedded Linux board to record or stream it. The SoC has a dedicated hardware encoder, yet CPU usage suddenly shoots up and you cannot reach the target frame rate. If the board heats up and other features slow down as soon as you raise the resolution a little, there is a good chance that the compression, or the processing just before and after it, is running on the CPU instead of the hardware.
Many SoCs (System on Chip, a chip that integrates a processor and its peripherals) include a VPU (Video Processing Unit, a dedicated hardware block for video encoding and decoding) or codec IP. GStreamer (an open-source framework that builds audio and video pipelines by linking elements) uses that hardware through dedicated encoder elements. But if the pipeline picks a software encoder, or if format conversion and memory copies around the hardware encoder run on the CPU, the benefit of hardware acceleration disappears. In this note, THEFINE summarizes the 6 things we check first in this situation, each broken down into symptom, cause, and how to fix. If hardware encoding already works and latency is your problem, start with our GStreamer video latency note (Korean).
What to check first (overview): With the pipeline running, use top -H or htop to find the threads that use the most CPU, and check which encoder and conversion elements were actually inserted, using the gst-launch-1.0 -v output or a pipeline graph generated with GST_DEBUG_DUMP_DOT_DIR. Next, use gst-inspect-1.0 to see whether the hardware encoder element is registered, and v4l2-ctl --list-devices and dmesg to see whether the encoder device node and firmware came up. Finally, narrow things down in order: formats (caps), the buffer-sharing method, and encoder settings.
| Where the CPU time goes | Suspect first | Section |
|---|---|---|
| Software encoders such as x264enc, x265enc, or openh264enc | The hardware encoder element was not selected or is not registered | 1, 2 |
| videoconvert, videoscale | The input format differs from what the encoder accepts, so a CPU conversion is inserted | 3, 5 |
| memcpy-type functions, at the capture/encoder boundary | Buffers are not shared, so every frame is copied | 4, 5 |
| After the encoder (preview, streaming, storage), or everything on one thread | Encoder settings, preview path, queue and thread layout | 6 |
1. A software encoder is selected instead of the hardware encoder
Symptom: The pipeline runs and the file gets written, but several CPU cores are almost fully loaded, and frames start backing up when you raise the resolution or fps. The pipeline graph shows a software encoder such as x264enc, openh264enc, or x265enc in the encoder slot.
Cause: Either an example pipeline written on a PC was copied over with x264enc hard-coded, or the pipeline uses something that picks the encoder automatically, such as encodebin, and a software encoder with a higher rank (the element priority GStreamer uses for automatic selection) wins. Hardware encoder element names vary by SoC and BSP (Board Support Package, the kernel, drivers, and libraries supplied by the board vendor). Standard Linux V4L2 (Video4Linux2, the Linux video device framework) memory-to-memory (M2M, a device that takes frames from memory and writes the result back to memory) encoders usually appear as v4l2h264enc and v4l2h265enc. Depending on the vendor BSP, you may instead see the OpenMAX-based omxh264enc (for example, the video codec unit on some FPGA SoCs), or vendor plugin names such as vpuenc_h264 or mpph264enc. Confirm the exact name and supported formats in your BSP documentation and in the actual gst-inspect-1.0 output.
How to fix: First list every encoder element registered on the board with gst-inspect-1.0 | grep -iE '264|265|hevc|enc', then specify the hardware encoder explicitly in the pipeline. To see which elements were actually used, run with GST_DEBUG_DUMP_DOT_DIR=/tmp gst-launch-1.0 ... and render the resulting .dot file with dot -Tpng. If you must rely on automatic selection, you can lower the rank of the software encoder with the GST_PLUGIN_FEATURE_RANK environment variable (for example, GST_PLUGIN_FEATURE_RANK=x264enc:NONE). If your application code builds the pipeline string, also check that the configuration for the development PC and the board is kept separate so that each uses the right encoder.
2. The hardware encoder does not show up because a plugin, driver, or firmware is missing
Symptom: Running gst-inspect-1.0 v4l2h264enc (or your BSP's encoder element) returns a "No such element or plugin" message, or the element exists but the pipeline fails at startup with an error saying it cannot open the device.
Cause: Hardware encoding needs all three layers: the kernel encoder driver and its device tree (data that describes the board's hardware layout to the kernel) node, the firmware file that the codec block requires, and the user-space GStreamer plugin (plus any vendor libraries). If the driver probe fails, no encoder device node is created. If the firmware file is missing from the root file system, the driver may load but still cannot start encoding. The V4L2 plugin registers encoder elements by scanning the /dev/video* devices when GStreamer builds its registry (the cache where it stores plugin information), so if the device was not present at that moment, the element may not appear. On boards with several encoder nodes, elements may be registered with the node number in the name, such as v4l2video11h264enc.
How to fix: Use v4l2-ctl --list-devices to find the encoder driver name and its /dev/videoN, and check that the Device Caps in v4l2-ctl -d /dev/videoN --all include Video Memory-to-Memory (or its Multiplanar variant). Use dmesg | grep -iE 'vpu|venc|codec|firmware' to look for probe errors or firmware load failures such as "Direct firmware load ... failed". For plugin load failures, list blacklisted plugins with gst-inspect-1.0 -b, and if needed delete the GStreamer registry file in the user cache (~/.cache/gstreamer-1.0/registry.*.bin) so that it is rebuilt. If the driver does not come up, continue with our device tree and driver probe failure note; if the plugin or firmware package is missing from your Yocto image, see our Yocto/PetaLinux build checklist (Korean).
3. A caps mismatch forces format conversion (videoconvert) on the CPU
Symptom: The hardware encoder is in the pipeline, yet CPU usage is high and top -H shows the threads for the section containing videoconvert or videoscale at the top. If you remove videoconvert, the pipeline fails to start with a "not-negotiated" error.
Cause: GStreamer elements negotiate caps (capabilities: the video format, resolution, and frame rate exchanged between elements) to agree on a format. If the camera outputs YUY2 (YUYV) or RAW but the hardware encoder accepts only a specific format such as NV12, videoconvert ends up in between and rearranges the pixels on the CPU for every frame. Even though the encoding itself runs in hardware, this conversion can account for most of the CPU load at higher resolutions. When you use decodebin or other auto-plugging elements, conversion elements you never added can also appear in the graph automatically. Some drivers also require a profile and level in the encoder's output caps before negotiation can complete.
How to fix: Check the formats the sink pad accepts in the Pad Templates of gst-inspect-1.0 v4l2h264enc (or your encoder), and compare them with the pixel formats the encoder device accepts, using v4l2-ctl -d /dev/videoN --list-formats-out. If the camera or ISP (Image Signal Processor, the block that corrects and converts sensor images) can output that format directly, specify caps after the source, such as video/x-raw,format=NV12,width=1920,height=1080,framerate=30/1, and connect them directly with no conversion. If conversion is unavoidable, use a hardware path such as v4l2convert (the element for V4L2 M2M conversion devices) or a conversion element based on a 2D accelerator from your BSP. Verify the negotiated result for each link using the caps lines in the gst-launch-1.0 -v output.
4. Buffers are not shared through DMA-BUF, so every frame is copied
Symptom: There is no conversion element and the hardware encoder is in use, yet CPU usage and memory bandwidth rise in proportion to resolution. If you can run perf top, memcpy-type functions show up near the top.
Cause: The camera capture device and the hardware encoder each use DMA (Direct Memory Access, a way for a device to read and write memory directly without going through the processor) buffers. If both devices pass the same buffer through DMA-BUF (the Linux mechanism for sharing buffers between devices as file descriptors), the frame can be processed without copying (zero-copy). Depending on element settings, versions, and driver support, however, each element may allocate its own buffers and the CPU copies the frame at the boundary. Designs in which the application pulls frames out with appsink and pushes them back with appsrc are also prone to copies.
How to fix: In a V4L2-based pipeline, a good starting point is io-mode=dmabuf on the capture-side v4l2src and output-io-mode=dmabuf-import on the encoder so that it imports the incoming buffers. For example: gst-launch-1.0 v4l2src device=/dev/video0 io-mode=dmabuf ! video/x-raw,format=NV12,width=1920,height=1080 ! v4l2h264enc output-io-mode=dmabuf-import ! h264parse ! fakesink. Supported modes and property names vary by element and BSP, so check them with gst-inspect-1.0, and follow the zero-copy settings in the documentation for vendor plugins. Buffer sharing needs enough contiguous memory, so if you also see allocation failures, continue with our DMA and contiguous memory (CMA) note.
5. Pixel format, stride, or alignment mismatches cause negotiation failures or copies
Symptom: With dmabuf-import set, the pipeline will not start, or the picture is skewed diagonally or shows stripes. Sometimes the problem appears only at certain resolutions (for example, 1920×1080), while 1280×720 works fine.
Cause: Hardware encoders often impose alignment requirements on width and height, on stride (bytesperline, the number of bytes one line occupies in memory), and on the offset between planes. For example, 1080 is not a multiple of 16, so some devices internally pad it to 1088. If the stride or plane layout of the buffers produced by the capture device does not match the encoder's requirements, the buffers cannot be used as-is, and depending on the element, negotiation fails or the pipeline falls back to a CPU copy. Even within NV12, a single-buffer format with both planes packed together differs from a multi-planar format with separate planes (such as NV12M), and some vendors use their own tiled or compressed formats.
How to fix: Read the capture-side width, height, bytesperline, and sizeimage with v4l2-ctl -d /dev/video0 --get-fmt-video, read the input-side format on the encoder node with --get-fmt-video-out (or --all), and compare the two. Raising the debug level for the V4L2 elements, as in GST_DEBUG="v4l2*:5", logs the negotiated format and buffer pool configuration. Where possible, choose resolutions that meet the alignment the hardware requires; if one section cannot match the stride, consider routing only that section through a hardware conversion device. Stripes or a skewed picture mean the format was negotiated but the two sides interpret the stride differently, so check this section first.
6. Encoder settings and the preview, queue, and thread layout push the CPU back up
Symptom: The encoder runs in hardware, yet overall CPU usage is higher than expected, or a single core is maxed out and fps drops. Raising the bitrate overloads streaming or storage, lowering it hurts image quality, and you are not even sure the settings are being applied.
Cause: The processing after the encoder often runs on the CPU. If you split off a preview with tee while recording and use a software rendering path such as videoconvert ! autovideosink, the preview consumes CPU even though encoding is done in hardware. An unnecessarily high bitrate adds load to rtph264pay, network transmission, and file storage, and if the rate control (how the encoder holds the bitrate constant or lets it vary) or GOP (Group of Pictures, the set of frames between keyframes) length does not suit the use case, the instantaneous bitrate can spike sharply. And if elements are linked without a queue, capture, encoding, and transmission run one after another on a single streaming thread, so only one core stays busy even on a multi-core SoC.
How to fix: When you view per-thread CPU usage with top -H, the thread names may show element or pad names depending on your environment, which makes it easier to see which section is busy. Use a hardware display path for preview (for example, kmssink or waylandsink), or split it into a separate branch at a lower resolution and fps, and insert queue elements between capture, encoding, and transmission to separate the threads. For V4L2 encoders, check the supported control names for bitrate, GOP, and similar settings with v4l2-ctl -d /dev/videoN --list-ctrls, then pass them in a form such as extra-controls="encode,video_bitrate=4000000"; for vendor plugins, set the element properties (the bitrate and GOP entries shown by gst-inspect-1.0). The numbers are only examples, so choose real values for your resolution, use case, and link bandwidth, and after configuring, measure the bitrate and keyframe interval of the resulting stream to confirm the settings took effect. You can check the output fps with fpsdisplaysink video-sink=fakesink text-overlay=false -v.
Checklist at a glance
- Use
top -Hto find the threads and sections using the CPU. - Check the actual encoder and conversion elements in the pipeline graph (
.dot). - Check the hardware encoder element, device, and firmware with
gst-inspect-1.0,v4l2-ctl --list-devices, anddmesg. - Specify caps explicitly to eliminate CPU format conversion.
- Match DMA-BUF sharing and stride/alignment requirements to reduce copies.
- Clean up the preview, queues, and encoder settings, then measure fps and bitrate.
Summary: hardware encoding is about the whole path the frames take, not the encoder name
When hardware encoding is not used properly in GStreamer, the cause is almost always one of the following, or a combination: a software encoder being selected, a missing plugin, driver, or firmware, CPU conversion caused by a caps mismatch, memory copies, stride or alignment mismatches, or the encoder settings and preview/thread layout. Rather than just swapping the encoder element, remove each section where frames pass through the CPU, from the camera all the way to storage or streaming; that is how you get the full performance of the VPU.
THEFINE provides contract development for video pipelines, from camera input through hardware encoding and streaming, as well as embedded Linux development.
If CPU usage stays high even with a hardware encoder, send us your SoC and BSP version, the resolution, pixel format, and target fps, the GStreamer pipeline string you use, and your gst-inspect-1.0 and top -H output. We will review them and get back to you.
Related notes
- Why GStreamer video latency increases (Korean)
- Running Out of DMA or Contiguous Memory (CMA) on Embedded Linux?
- Camera Set to 30 fps but Getting 24? How to Find Where V4L2 Frames Are Dropped
Related services: Video Pipeline Development · Embedded Linux Development
Contact us / Request a quote | ☎ +82-31-498-3130
