Reputation: 180
I would like to copy FFMpeg decoded image data to an UMat WITHOUT copying it to the CPU RAM:
Is there any way to do it? What if there are two or more GPU card in the PC?
I have this code for av_image_copy_to_buffer, works fine:
int copy_frame_to_buffer(void* handle, void* buffer, int bufferSize)
{
int ret = 0;
int calculatedBufferSize;
VideoDecoderContext* context = static_cast<VideoDecoderContext*>(handle);
calculatedBufferSize = av_image_get_buffer_size(static_cast<AVPixelFormat>(context->frame->format), context->frame->width, context->frame->height, 1);
if (calculatedBufferSize != bufferSize)
{
fprintf(stderr, "Calculated buffer (%d) is not equal to bufferSize (%d).\n", calculatedBufferSize, bufferSize);
return -1;
}
uint8_t* byte_buffer = static_cast<uint8_t*>(buffer);
ret = av_image_copy_to_buffer(byte_buffer, calculatedBufferSize,
(const uint8_t* const*)context->frame->data,
(const int*)context->frame->linesize, static_cast<AVPixelFormat>(context->frame->format),
context->frame->width, context->frame->height, 1);
if (ret < 0) {
fprintf(stderr, "Can not copy image to buffer\n");
return ret;
}
return ret;
}
...but if I change the context->frame to context->hwFrame it is not working.
Upvotes: -2
Views: 61