Skip to content

Bug fix: H265 encoded images are incorrectly labelled - #800

Merged
asahtik merged 3 commits into
luxonis:developfrom
SwapnilPande:fix/h265-ffmpeg-label-develop
Nov 18, 2026
Merged

asahtik merged 3 commits into
luxonis:developfrom
SwapnilPande:fix/h265-ffmpeg-label-develop

Conversation

@SwapnilPande

@SwapnilPande SwapnilPande commented Oct 27, 2026 •

Copy link
Copy Markdown
Contributor

Summary

i_low_bandwidth_ffmpeg_encoder is declared (default libx264) but never read. ImgConverterConfig::ffmpegEncoder therefore always falls back to the default, and ImagePublisher passes that to ImageConverter::setFFMPEGEncoding(). Every FFMPEGPacket comes out with encoding: libx264, even when the camera's VideoEncoder runs H265_MAIN.

ffmpeg_image_transport picks its decoder from that field, so it attempts to use an H.264 decoder for an HEVC stream.

Known follow-ups, deliberately left out to keep this PR minimal:

  • The label and the encoder profile are still set independently. Profile H265_MAIN with the encoder param left at libx264 still gives a wrong label, with no warning. A mismatch warning, or a profile-derived default, could be added
    later.

  • Same unread param in the other nodes. stereo_param_handler.cpp declares i_low_bandwidth_ffmpeg_encoder, i_left_rect_low_bandwidth_ffmpeg_encoder and i_right_rect_low_bandwidth_ffmpeg_encoder, and thermal_param_handler.cpp declares i_low_bandwidth_ffmpeg_encoder. None of them is read in stereo.cpp (setupStereoQueue, setupRectQueue) or thermal.cpp, so their FFMPEG packets are always labelled libx264 too. tof.cpp sets convConfig.lowBandwidth but the ToF param handler doesn't declare the param. Thermal and ToF don't publish compressed output today. Stereo does.

Related issues

None

Compatibility and configuration

None. The param already exists, and its default (libx264) matches the value that
was previously hard-coded, so H.264 output is unchanged. Users who already set
i_low_bandwidth_ffmpeg_encoder (which had no effect before) now get that label.

Repro config:

rgb:
  ros__parameters:
    i_low_bandwidth: true
    i_publish_compressed: true
    i_low_bandwidth_profile: 3          # H265_MAIN
    i_low_bandwidth_ffmpeg_encoder: libx265
ros2 topic echo --once --field encoding /oak/rgb/image_raw/compressed   # libx264 before, libx265 after
ros2 run image_transport republish ffmpeg raw --ros-args \
  -r in/ffmpeg:=/oak/rgb/image_raw/compressed -r out:=/decoded \
  -p in.ffmpeg.decoders.libx265:=hevc

Testing

  • ROS distribution and OS: Humble / Ubuntu 22.04 (Docker) for the 3.3.0 release; Kilted / Ubuntu 24.04 (Docker) for this develop branch
  • DepthAI library version: depthai-core 3.10.0 (apt)
  • Camera model and connection (USB / PoE): OAK-D Pro PoE and OAK-D Pro W PoE, both PoE
  • Test commands or launch configuration: the repro config above on an RGBD pipeline (640x400, 15 FPS, not synced), decoded with ros2 run image_transport republish ffmpeg raw
  • Results:
    • Build. The same change on top of v3.3.0-humble builds in ros:humble against the apt ros-humble-depthai-ros-v3 3.3.0 packages, with no new warnings. This branch builds in ros:kilted (depthai_ros_driver, depthai_bridge, depthai_ros_msgs, depthai_descriptions from develop, apt depthai-core 3.10.0).

    • On a device. I built the one-line change on top of v3.3.0-humble (no other changes) and ran it in a Humble container with the apt ros-humble-depthai-ros-v3 3.3.0 packages, on both cameras at once. Each camera's FFMPEG stream was decoded with republish, and the packets and decoded images were recorded for 20 s:

      driver color config packet encoding republish decoded images (cam 1 / cam 2)
      unpatched (apt 3.3.0) profile 3 (H265_MAIN), i_low_bandwidth_ffmpeg_encoder: libx265; decoders.libx265:=hevc libx264 picks h264_cuvid,h264, then segfaults 0 / 0
      this PR same libx265 opens hevc 316 / 313
      this PR profile 1 (H264_HIGH), encoder param left at its default; decoders.libx264:=h264 libx264 opens h264 316 / 316

      Decoded images are 640x400 bgr8, in stamp order, with the packet's frame_id. Every decoded frame inside the recording window carries the exact stamp of a published packet.

    • Decoder side, without a device. Same ffmpeg_image_transport 3.0.5 and ffmpeg_encoder_decoder 3.0.1 as Humble apt. An rclpy node published 640x400 Annex-B packets (I/P only, keyframe every 30) shaped like ImageConverter::toRosFFMPEGPacket output: stamp, frame_id, pts in ns, flags = keyframe. They were decoded with ros2 run image_transport republish ffmpeg raw:

      stream encoding label republish params result
      HEVC libx264 (before) decoders.libx264:=hevc ignoring invalid decoder hevc for codec libx264, picks h264_cuvid, segfault
      HEVC libx265 (after) decoders.libx265:=hevc 60/60 frames decoded, in order, stamps and frame_id identical
      H.264 libx264 (default) decoders.libx264:=h264 60/60 frames decoded, in order, stamps and frame_id identical
    • Not tested on a device: this develop branch on its own.

AI

  • Were AI agents used for this PR? (Yes / No): Yes
  • If yes, which agents or tools were used, and for what tasks?: Claude Code (Claude Opus 5.5) traced the bug, wrote the one-line change, ran the builds and the offline decoder round trip, and drafted this description.
  • Was the code checked by a human? (Yes / Partially / No): Yes. The submitter set the scope of the change (only this one line) and asked for the PR. A line-by-by line human review has also been completed.
  • Describe the scope of human review and anything that remains unchecked: I reviewed the results from the on-device testing, reviewed the code changes, and cleaned the body of this PR

🤖 Generated with Claude Code & with a human too :)

@SwapnilPande SwapnilPande reopened this Oct 27, 2026
@SwapnilPande SwapnilPande changed the title Honour i_low_bandwidth_ffmpeg_encoder for camera FFMPEG packets Bug fix: H265 encoded images are incorrectly labelled Oct 27, 2026
@asahtik
asahtik requested a balanced review from Copilot October 27, 2026 10:50

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Although the one-line fix is correct and well-scoped, the author's own description identifies the same unread-parameter bug persisting in the stereo path (which does publish compressed output), so the fix is incomplete for that code path.

No open issues 🎉

What changed in this PR

This PR fixes a bug where H.265 (HEVC) encoded images were incorrectly labelled as libx264 in their FFMPEGPacket encoding field. The i_low_bandwidth_ffmpeg_encoder parameter was declared but never read, so ImgConverterConfig::ffmpegEncoder always fell back to its default (libx264). Downstream, ffmpeg_image_transport selects its decoder from this field, causing it to attempt an H.264 decoder on an HEVC stream. The one-line change wires the declared parameter into the converter config for the camera sensor node.

Changes:

  • Read ParamNames::LOW_BANDWIDTH_FFMPEG_ENCODER into convConfig.ffmpegEncoder in Camera::setupQueues, so the configured encoder label propagates through ImagePublisher to ImageConverter::setFFMPEGEncoding().
File Description
depthai_ros_driver/​src/​dai_nodes/​sensors/​camera.cpp Populates convConfig.ffmpegEncoder from the previously-unread i_low_bandwidth_ffmpeg_encoder param so FFMPEG packets carry the correct encoding label.

I verified: the param constant exists (base_param_handler.hpp:16), it is declared for this node's handler (sensor_param_handler.cpp:36, with ph being a SensorParamHandler per camera.cpp:25), the target field ffmpegEncoder is a std::string (utils.hpp:57), and the value is consumed downstream (img_pub.cpp:101). The new line is consistent with the surrounding getParam calls. The default (libx264) preserves prior behavior, so H.264 output is unchanged. The remaining unread-param cases in stereo/thermal noted in the description are outside this diff and intentionally deferred.

Review effort: Balanced

asahtik
asahtik previously approved these changes Oct 27, 2026
SwapnilPande and others added 2 commits October 31, 2026 21:21
The param was declared but never copied into ImgConverterConfig, so every
FFMPEGPacket was labelled libx264, even for H.265 streams. ffmpeg_image_transport
then picks an H.264 decoder for an HEVC bitstream.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0114oQMBcCFbwHvHoVjCKjmE
Stereo declares i_low_bandwidth_ffmpeg_encoder and the left/right rect
variants, but setupStereoQueue and setupRectQueue never read them, so
their FFMPEG packets were always labelled libx264.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01QoDtVoMSv6LBPGZtf2pj33
@SwapnilPande

Copy link
Copy Markdown
Contributor Author

Stereo is fixed too, in 94b0bef. Depth and the left/right rectified streams now read their i_*low_bandwidth_ffmpeg_encoder parameter. On an OAK-D Pro PoE, the left rectified stream sent as H.265 was labelled libx264 before the change and libx265 after. I couldn't check the depth label on the device, because the depth encoder rejects depth frames with this config ("Arrived frame type (14) is not either NV12 or YUV400p"). That happens with or without this change.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The review surfaced no outstanding or unresolved issues against the change, leaving nothing blocking approval.

No open issues 🎉

Review effort: Balanced

@asahtik asahtik left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks

@asahtik
asahtik merged commit be24f1c into luxonis:develop Nov 18, 2026
8 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants