Repository: opencv
Issue: libv4l2: error converting / decoding frame data: v4l-convert: error destination buffer too small
Labels: bug,auto-transferred,priority: normal,category: videoio(camera),affected: 3.4

Transferred from http://code.opencv.org/issues/3427

```
|| Patrick Brown on 2013-12-09 22:09
|| Priority: Normal
|| Affected: branch 'master' (3.0-dev)
|| Category: highgui-camera
|| Tracker: Bug
|| Difficulty: 
|| PR: 
|| Platform: x64 / Linux
```
## libv4l2: error converting / decoding frame data: v4l-convert: error destination buffer too small

```
FPS: 11, width: 640, height: 480
width:3264:height:2448
HIGHGUI ERROR: V4L: Property <unknown property string>(6) not supported by device
HIGHGUI ERROR: V4L: Property <unknown property string>(8) not supported by device
FPS: 11, width: 3264, height: 2448
iteration:0
libv4l2: error converting / decoding frame data: v4l-convert: error destination buffer too small (16777216 < 23970816)
VIDIOC_DQBUF: Bad address
```
## History
##### Patrick Brown on 2013-12-09 22:10

```
This is an econ 8 megapixel camera
```
##### Patrick Brown on 2013-12-10 00:20

```
I noticed that in lib_jasper that the value 16 * 1024 * 1024 corresponds to the value 16777216 .

.//3rdparty/libjasper/jasper/jas_image.h:#define JAS_IMAGE_INMEMTHRESH  (16 * 1024 * 1024)

I the error related to this define?

I rebuilt the libjasper.so.1 and installed it on my system and I get the same error so I believe that the error is the result of something else.

Has anyone ever used a 8 megapixel camera with opencv?
```
##### Nikita Manovich on 2013-12-10 19:39

```
Hi,

Thank you for the bug report. Could you please help us to investigate and fix the problem? You can find all necessary information in the article: http://www.code.opencv.org/projects/opencv/wiki/How_to_contribute. Also please provide more information: model of the camera, exact API call which leads to the problem.
-   Assignee set to Patrick Brown
```
##### Patrick Brown on 2013-12-10 21:21

```
Here is the code that creates the error:
/*
 * capcam.cpp
 *
 *  Created on: Nov 4, 2013
 *      Author: student
 */
#include <iostream>

#include <opencv2/opencv.hpp>

using namespace std;
using namespace cv;
#include <stdio.h>
int saveImageToFile(Mat img,char *fname);
static int maxcams = 1;
int main()
{
    char fName[256];
    int icnt = 0;
    // VideoCapture capture(-1); // use webcam
    //VideoCapture capture("input.mpg"); // use input file
    Mat frame;
    int icam ;

    icam = 0;
    while(true)
    {
        char cOut[256];
        VideoCapture *capture;
        capture = new VideoCapture(icam); // use webcam

        if(capture->isOpened())
        {
            int mode;
            // if using webcam:
            int fps = 11;
            // if using input file:
            //int fps = capture.get(CV_CAP_PROP_FPS);

            int width = capture->get(CV_CAP_PROP_FRAME_WIDTH);
            int height = capture->get(CV_CAP_PROP_FRAME_HEIGHT);
            cout << "FPS: " << fps << ", width: " << width << ", height: " << height << endl;

            width =  3264;//2592;//3296;//2592;
            height = 2448;//1944;//2472;//1944;

            capture->set(CV_CAP_PROP_FRAME_WIDTH,width);
            capture->set(CV_CAP_PROP_FRAME_HEIGHT,height);
            width = capture->get(CV_CAP_PROP_FRAME_WIDTH);
            height = capture->get(CV_CAP_PROP_FRAME_HEIGHT);
printf("width:%d:height:%d\r\n",width,height);

            mode = ('M' & 255) + (('J' & 255) << 8) + (('P' & 255) << 16) + (('G' & 255) << 24);
            capture->set(CV_CAP_PROP_FOURCC, CV_FOURCC('M', 'J', 'P', 'G'));
            capture->set(CV_CAP_PROP_FORMAT , mode);
            cout << "FPS: " << fps << ", width: " << width << ", height: " << height << endl;


            capture->set(CV_CAP_PROP_FPS, 1);
            sprintf(cOut,"mycam:%d",icam);

for(int ii=0;ii<maxcams;ii++)
{
    for(int jj=0;jj<10;jj++)
    {
        printf("iteration:%d\r\n",jj);
            *capture >> frame;
    }
    printf("display image\r\n");

            imshow(cOut,frame);
            sprintf(fName,"f%d.jpg",icnt);
printf("at 1\r\n");
            saveImageToFile(frame,fName);
            printf("Frame to file %s\r\n",fName);
            icnt = icnt + 1;
            int key = waitKey(10);
            if((char)key == 'q') { break; }

}

            destroyWindow(cOut);

            capture->release();
            delete capture;
            icam = icam + 1;
            if(icam >= maxcams)
            {
                icam = 0;
            }
        }
    }

    return 0;
}

#define COMPRESSION_QUALITY (100) /* from 1 to 100 [100 is best] */

int saveImageToFile(Mat img,char *fname)
{
    // Mat img(x, y, CV_16UC3, Scalar(0,50000, 50000)); //create an image ( 3 channels, 16 bit image depth, 650 high, 600 wide, (0, 50000, 50000) assigned for Blue, Green and Red plane respectively. )

    if (img.empty()) //check whether the image is loaded or not
    {
        printf("ERROR : Image cannot be loaded..!!\r\n");

        return -1;
    }
    else
    {
        printf("saving image>%s<\r\n",fname);
    }
    vector<int> compression_params; //vector that stores the compression parameters of the image

    compression_params.push_back(CV_IMWRITE_JPEG_QUALITY); //specify the compression technique

    compression_params.push_back(COMPRESSION_QUALITY); //specify the compression quality


    bool bSuccess = imwrite(fname, img, compression_params); //write the image to file


    if ( !bSuccess )

    {

        printf("ERROR : Failed to save the image\r\n");


    }
    else
    {
        printf("saved image>%s<\r\n",fname);
    }


    return 0;
}
```
##### Patrick Brown on 2013-12-10 21:25

```
The camera is a 8 Megapixel e-con camera that support 11 frames/sec at 8 megapixel. You can get the raw bmp image if you want.
```
##### Patrick Brown on 2013-12-11 04:19

```
In using an e-con 8 megapixel camera I am getting an error:
FPS: 11, width: 640, height: 480
width:3264:height:2448
HIGHGUI ERROR: V4L: Property <unknown property string>(6) not supported by device
HIGHGUI ERROR: V4L: Property <unknown property string>(8) not supported by device
FPS: 11, width: 3264, height: 2448
iteration:0
libv4l2: error converting / decoding frame data: v4l-convert: error destination buffer too small (16777216 < 23970816)
VIDIOC_DQBUF: Bad address

I believe that I have tracked it down to the define :
/lib/libv4l2/libv4l2-priv.h:#define V4L2_FRAME_BUF_SIZE (4096 * 4096)

I am trying to contact the support group for this code.
```
##### Nikita Manovich on 2013-12-11 08:10

```
-   Status changed from New to Open
```
##### Patrick Brown on 2013-12-11 20:19

```
I had made a change to http://git.linuxtv.org/v4l-utils.git/tree tip in file 
v4l-utils-HEAD-4dea4af/lib/libv4l2/libv4l2-priv.h
The change was 
define V4L2_FRAME_BUF_SIZE (4096 * 4096)

to
#define V4L2_FRAME_BUF_SIZE (2 * 4096 * 4096)

When the package is recompiled and then the shared object files updated the package now works with the 8 megapixel camera in the raw mode.

What action do you want me to take or maybe you have more insight into the how this is to work?
```
##### Vadim Pisarevsky on 2015-05-30 07:02

```
-   Affected version changed from 2.4.0 - 2.4.6 to branch 'master'
    (3.0-dev)
-   Category changed from highgui-gui to highgui-camera
```