How to save image to file ?

Hi,

I have known the bug. when I call

int ret = jpegenc->encodeFromFd( fd, JCS_YCbCr, &outBuf, outBufSize);

the outBufSize will change, so I have to assign the value every time. I don’t know if it’s NVIDA bug, because it have not a specific explain.

Hi ClancyLian,
You need to allocate outBuf:

(code sniffer from 05_jpeg_encode)
static bool
conv_capture_dqbuf_thread_callback(struct v4l2_buffer *v4l2_buf,
                                   NvBuffer * buffer, NvBuffer * shared_buffer,
                                   void *arg)
{
    context_t *ctx = (context_t *) arg;
    unsigned long out_buf_size = ctx->in_width * ctx->in_height * 3 / 2;
    unsigned char *out_buf = new unsigned char[out_buf_size];

    if (!v4l2_buf)
    {
        cerr << "Failed to dequeue buffer from conv capture plane" << endl;
        abort(ctx);
        delete[] out_buf;
        return false;
    }

    if (v4l2_buf->m.planes[0].bytesused > 0)
    {
        if (ctx->jpegenc->encodeFromFd(buffer->planes[0].fd, JCS_YCbCr, &out_buf,
                out_buf_size) < 0)
        {
            cerr << "Error while encoding from fd" << endl;
            ctx->got_error = true;
        }
        else
        {
            ctx->out_file->write((char *) out_buf, out_buf_size);
        }
    }

    delete[] out_buf;

    return false;
}