usb_cam icon indicating copy to clipboard operation
usb_cam copied to clipboard

outbuf size mismatch; YUV420P vs. YUV422P

Open clydemcqueen opened this issue 7 years ago • 5 comments

I'm getting errors of the form:

[ERROR] ros.usb_cam: outbuf size mismatch. pic_size: 720000 bufsize: 960000

I believe that this is because libavcodec is returning frames with YUV 4:2:0 pixels (1.5 bytes/pixel), but the buffer size is allocated for YUV 4:2:2 pixels (2 bytes per pixel). If I replace AV_PIX_FMT_YUV422P with AV_PIX_FMT_YUV420P in the following line the problem is resolved.

https://github.com/ros-drivers/usb_cam/blob/ce8c6a9df08050f6da22b39a472e4f99b35c9bd7/src/usb_cam.cpp#L397

I'm not sure what the fix is here. I doubt just replacing AV_PIX_FMT_YUV422P with AV_PIX_FMT_YUV420P works for all cameras.

clydemcqueen avatar Oct 25 '17 04:10 clydemcqueen

I was getting a similar error using an ELP-USB100W04H-L36 with the following launch file but making your changed fixed it. Now it runs with just the deprecated pixel warning but I'm getting the video as a MJPEG so that's good enough for me. It's weird what looks like a YUV settings effect MJPEG. Thanks for the info! error before @clydemcqueen fix: outbuf size mismatch. pic_size: 1382400 bufsize: 1843200 Launch File used before and after fix:

<launch>
  <node name="usb_cam" pkg="usb_cam" type="usb_cam_node" output="screen" >
    <param name="video_device" value="/dev/video2" />
    <param name="image_width" value="1280" />
    <param name="image_height" value="720" />
    <param name="pixel_format" value="mjpeg" />
    <param name="camera_frame_id" value="usb_cam" />
    <param name="io_method" value="mmap"/>
  </node>
</launch>

Deprecated Pixel Warning: deprecated pixel format used, make sure you did set range correctly

jack-digilabs avatar Jul 24 '18 19:07 jack-digilabs

I'm getting errors of the form:

[ERROR] ros.usb_cam: outbuf size mismatch. pic_size: 720000 bufsize: 960000

I believe that this is because libavcodec is returning frames with YUV 4:2:0 pixels (1.5 bytes/pixel), but the buffer size is allocated for YUV 4:2:2 pixels (2 bytes per pixel). If I replace AV_PIX_FMT_YUV422P with AV_PIX_FMT_YUV420P in the following line the problem is resolved.

https://github.com/ros-drivers/usb_cam/blob/ce8c6a9df08050f6da22b39a472e4f99b35c9bd7/src/usb_cam.cpp#L397

I'm not sure what the fix is here. I doubt just replacing AV_PIX_FMT_YUV422P with AV_PIX_FMT_YUV420P works for all cameras.

Thsi worked for me. Thank you for sharing

IsuruMS avatar Jun 19 '21 20:06 IsuruMS

thanks for the fix. As I am new to ROS, I feel like it might be important for others like me: after doing this I had to rebuild using catkin_make

hakanErgin avatar Mar 03 '22 09:03 hakanErgin

thank you! this fix is also working in ROS2!

1hao-Liu avatar Apr 08 '22 06:04 1hao-Liu

I have the same issue. But I don't have src folder inside my usb_cam folder. I only have cmake, launch, package.xml. Any idea on how to fix the issue in my case?

Adharshmahesh avatar Aug 21 '22 00:08 Adharshmahesh