how to use the the function "ARGBToNV12" in libyuv

45 views Asked by At

I want to convert the argb to nv12.but I dont know the meaning of src_stride_argb,dst_stride_y and dst_stride_uv. I simply think the src_stride_argb is width * 4, and dst_stride_y is width, dst_stride_uv is width too,but it seems not correctly. My code blow

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <libyuv.h>

#define input_width 1920
#define input_height 1080



int main() {
    FILE *fp = fopen("output.raw", "rb");
    uint8_t *rgba = (uint8_t*) malloc(1920*1080*4);

    uint32_t total_pixel = input_height * input_width;

    fread(rgba, 1, total_pixel*4, fp);
    uint8_t *yuv = (uint8_t*) malloc( input_width * input_height + input_width * input_height / 2);

    uint8_t* start = rgba;

    ARGBToNV12(start, input_width * 4, 
            yuv,input_width ,
            yuv + total_pixel,input_width ,
            input_width, input_height);
    
    uint8_t *src_buff;
    src_buff = (uint8_t*) malloc(total_pixel + total_pixel/2);
    memcpy(src_buff, yuv, total_pixel + total_pixel/2);
    FILE *xfp = fopen("yes.yuv", "wb");
    fwrite(src_buff, 1, total_pixel + total_pixel/2, xfp);

    fclose(fp);
    fclose(xfp);
    free(rgba);
    free(src_buff);
    printf("finish\n");

}

the source pic

the output pic

I try to change the dst_stride_uv as width /2, because I think the uv should look as one. but I failed.

0

There are 0 answers