SexyBoooom
SexyBoooom

Reputation: 111

How to copy CUdeviceptr planes from FFmpeg AVFrame into my own CUDA memory?

I'm trying to copy a frame planes decoded by FFmpeg(CUDA) into my own CUDA memory, but i tried a lot of times and all failed.

1, from FFmpeg doc, it says:

/// <summary>HW acceleration through CUDA. data[i] contain CUdeviceptr pointers exactly as for system memory frames.</summary>
@AV_PIX_FMT_CUDA = 117

that means AVFrame.data[n] are the CUdeviceptr to copy from.

2, i have created my own CUDA memory without problem:

var dstPtr = new CUdeviceptr();
var error = cuMemAlloc_v2(ref dstPtr, length);

3, try to copy from AVFrame into dstPtr, but failed:

var dstPtr = new CUdeviceptr();
var error = cuMemAlloc_v2(ref dstPtr, length);  // allocate a CUDA mem for test

var plane = ffmpeg.av_frame_get_plane_buffer(avFrame, 0);  // get the plane 0 info
var srcPtr = new CUdeviceptr((long)plane->data);  // get CUdeviceptr from data[0]

error = cuMemcpyDtoD_v2(dstPtr, srcPtr, plane->size);  // try to copy from avFrame into my own CUDA mem block
Debug.Assert(error == CUResult.Success);  //  alway fail.....

the copy result is alwasy ErrorInvalidValue indicates that the CUdeviceptr returned from AVFrame.data[0] is invalid or something....

enter image description here

I really have no idea what am i doing wrong.... BTW, I have created a CUDA context for memory allocating, that said, i will set my own CUDA context as current before allocating memory, does this operation break the FFmpeg's current context? so the copy will fail?

but anyway, no matter i use cuCtxPushCurrent_v2 or cuCtxSetCurrent, both not work. this is just a really simple copy test, no? but why.... :(

Upvotes: 0

Views: 127

Answers (1)

SexyBoooom
SexyBoooom

Reputation: 111

the answer is simple: make the FFmpeg's CUcontext current correctly.

Upvotes: 1

Related Questions