diff --git a/api/tests/player_opencv.c b/api/tests/player_opencv.c index 042fd6ef..1f527284 100644 --- a/api/tests/player_opencv.c +++ b/api/tests/player_opencv.c @@ -30,7 +30,13 @@ void API_CALL on_frame_decode(void *user_data, mk_frame_pix frame) { int h = mk_get_av_frame_height(mk_frame_pix_get_av_frame(frame)); #if 1 - uint8_t *brg24 = malloc(w * h * 3); + int align = 32; + size_t pixel_size = 3; + size_t raw_linesize = w * pixel_size; + // 对齐后的宽度 + size_t aligned_linesize = (raw_linesize + align - 1) & ~(align - 1); + size_t total_size = aligned_linesize * h; + uint8_t* brg24 = malloc(total_size); mk_swscale_input_frame(ctx->swscale, frame, brg24); free(brg24); #else @@ -106,4 +112,4 @@ int main(int argc, char *argv[]) { mk_swscale_release(ctx.swscale); } return 0; -} \ No newline at end of file +}