RGBA
The data is stored in RGBARGBARGBA... format, and the starting address is frame->data[0]. In fact, in addition to RGBA, there are BGRA, AGBR, ARGB, GBRA. For details, please refer to the source code ffmpeg-4.3.1/libavfilter/drawutils.c
Traverse access to RGBA pixel frames
for (int y = 0; y < frame->height; y++) {
row[0] = frame->data[0] + y * frame->linesize[0];
for (int x = 0; x < frame->width; x++) {
row[0][(x << 2) + 0]; //R
row[0][(x << 2) + 1]; //G
row[0][(x << 2) + 2]; //B
row[0][(x << 2) + 3]; //A
}
}
HOLE
The four types of data Y, U, V, and A are stored separately, and the starting addresses are frame->data[0], frame->data[1], frame->data[2], frame->data[3].
Traverse access to YUV pixel frame
const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
int hsub = desc->log2_chroma_w;
int vsub = desc->log2_chroma_h;
int have_alpha = desc->flags & AV_PIX_FMT_FLAG_ALPHA;
if (have_alpha) {
for (int y = 0; y < frame->height; y++) {
row[0] = frame->data[0] + y * frame->linesize[0];
row[1] = frame->data[1] + (y >> vsub) * frame->linesize[1];
row[2] = frame->data[2] + (y >> vsub) * frame->linesize[2]
row[3] = frame->data[3] + y * frame->linesize[3];
for (int x = 0; x < frame->width; x++) {
row[0][x ]; // Y
row[1][x >> hsub]; // U
row[2][x >> hsub]; // V
row[3][x ]; // A
}
}
} else {
for (int y = 0; y < frame->height; y++) {
row[0] = frame->data[0] + y * frame->linesize[0];
row[1] = frame->data[1] + (y >> vsub) * frame->linesize[1];
row[2] = frame->data[2] + (y >> vsub) * frame->linesize[2];
for (int x = 0; x < frame->width; x++) {
row[0][x ]; // Y
row[1][x >> hsub]; // U
row[2][x >> hsub]; // V
}
}
}