I try to use the ffmpeg libraries in Swift, but I am struggling with the pointers. Actually I try to use the av_image_copy_to_buffer
function (defined here). The function is defined in imgutils.h
as:
int av_image_copy_to_buffer(uint8_t *dst, int dst_size,
const uint8_t * const src_data[4], const int src_linesize[4],
enum AVPixelFormat pix_fmt, int width, int height, int align);
I don't know a lot about C, but is my assumption correct, that const uint8_t * const src_data[4]
means, that this function excepts an array with the size 4, pointing to four UInt8-Arrays?
I would like to pass the frame data like in this example. There they use this C code:
ret = av_image_copy_to_buffer(buffer, size,
(const uint8_t * const *)tmp_frame->data,
(const int *)tmp_frame->linesize, tmp_frame->format,
tmp_frame->width, tmp_frame->height, 1);
If I now access myFrame.pointee.data
, this will lead to data: (UnsafeMutablePointer<UInt8>?, UnsafeMutablePointer<UInt8>?, UnsafeMutablePointer<UInt8>?, UnsafeMutablePointer<UInt8>?, ....)
.
I could access with myFrame.pointee.data.0
up to myFrame.pointee.data.7
. It seems to be a tuple?!
In frame.h
, the data property of the AVFrame
struct is defined as uint8_t *data[AV_NUM_DATA_POINTERS];
How can I now pass the data pointers to the function?
EDIT:
According to the swift docu (here), Type * const *
should be converted to UnsafePointer<Type>
. Why is then uint8_t *data[AV_NUM_DATA_POINTERS];
converted to a Tuple of (UnsafeMutablePointer<UInt8>?, ...)
?