opencv: corrupt JPEG data: # extraneous bytes before marker 0x##

System information (version)
  • OpenCV => 3.3
  • Operating System / Platform => Ubuntu 16.04.3 LTS (x86_64)
  • Compiler => gcc 5.4.0 20160609
Detailed description

When accessing a Logitech C310 webcam with Java OpenCV 3.3 the following error message is repeatedly printed to the terminal (with varying values for number of bytes and marker) Corrupt JPEG data: 2 extraneous bytes before marker 0xd3

The error message comes from 3rdparty/libjpeg/jdmarker.c usage of JWRN_EXTRANEOUS_DATA

The problem appears to be caused by a bug with the libjpeg that ships with OpenCV. A fix is to build OpenCV with the option WITH_JPEG switched OFF causing OpenCV to use the platform’s copy of libjpeg.

I recommend updating the instructions here to include WITH_JPEG=OFF

Steps to reproduce

Build OpenCV for Java and run in Linux using the settings recommended in the Introduction to Java Development

About this issue

  • Original URL
  • State: open
  • Created 7 years ago
  • Reactions: 7
  • Comments: 21 (4 by maintainers)

Most upvoted comments

I had the same problem while running cv2.VideoCapture(0) and I solved it by re-installing openCv: pip install opencv-python

I am also experiencing the same issue.
Python 2.7.6 OpenCV 2.4.13 Ubuntu 14.04.1 LTS Is anyone actively working on this?

Any update on this issue? This is occurring on Python 3.5.2, Opencv 3.3.0, Ubuntu 16.04.4 LTS (GNU/Linux 3.10.105-141 armv7l).

Anyway to at least hide these warnings apart from switching to YUYV codec. The data is not corrupted.

For those who are using a web-cam to capture images/video feed.

This issue occurs with a few of Logitech webcams as seen in Issue2194 .

I faced the same problem with Logitech C270 web-cam. I tried running the same code and replacing the Logitech C270p web-cam with Nulaxy C900 & it ran without any of those warnings.

The reason could more likely be something highlighted by @fzcooper here

Best, Kavit Shah

What worked for me while using Python 3.7.3 on the Raspberry PI while using an USB Logitech Webcam was to install the following dependencies:

pip3 install opencv-contrib-python; sudo apt-get install -y libatlas-base-dev libhdf5-dev libhdf5-serial-dev libatlas-base-dev libjasper-dev libqtgui4 libqt4-test

Now the warning is gone.

I had the same problem while running cv2.VideoCapture(0) and I solved it by re-installing openCv: pip install opencv-python

yeah this works

thank you @simontamayo @AjinkyaPrabhu did you guys try this on linux?

@Fazankabir : yes, I did it on my Ubuntu 18.04.1 Cheers,

@simontamayo I have compiled the OpenCV on raspberry pi following steps from here https://www.pyimagesearch.com/2017/09/04/raspbian-stretch-install-opencv-3-python-on-your-raspberry-pi/ and now when i have connected the USB logitech camera I am getting the same issue. any help? Thanks in advance

how do i simply shut up the warning?

I think this needs to be reopened because the issue still occurs once the camera is switched into MJPEG codec. The workaround causes it to default to YUYV codec but once switched to MJPEG the problem still occurs.

I verified the workaround does fix this issue on my hardware. Thank you.

bug with the libjpeg that ships with OpenCV 3rdparty/libjpeg

Small clarification: this warning is reproduced with system libjpeg libraries too.

I’m observed that these warnings are not showed for each frame. So It is hard to say what is source of problem. Anyway result is not corrupted.

Could you check this workaround on your hardware: #9479 ?