c/c++ developer
https://github.com/PengShiqiu

导航

 

 

1、分解YUV视频像素数据原理

参照雷神博客:https://blog.csdn.net/leixiaohua1020/article/details/50534150

2、测试源码

源码及测试yuv文件下载地址:github  https://github.com/PengShiqiu/simple_media_test

 1 #include <iostream>
 2 #include <sys/types.h>
 3 #include <sys/stat.h>
 4 #include <fcntl.h>
 5 #include <unistd.h>
 6 
 7 int mytest_yuv420_split(const std::string &path, int w, int h)
 8 {
 9     int yuv_size = w * h * 3 / 2;
10 
11     int fd = open(path.c_str(), O_RDONLY);
12     int yfd = open("output_256x256_y.y", O_WRONLY | O_CREAT);
13     int ufd = open("output_128x128_u.u", O_WRONLY | O_CREAT);
14     int vfd = open("output_128x128_v.v", O_WRONLY | O_CREAT);
15 
16     void *buff = malloc(yuv_size);
17     ssize_t size = read(fd, buff, yuv_size);
18 
19     if (size < 0)
20     {
21         std::cout << "read err" << std::endl;
22         free(buff);
23         return -1;
24     }
25 
26     // Y分量为w * h个字节
27     // U、V分量为w * h / 4个字节
28     write(yfd, buff, w * h);
29     write(ufd, (void *)(buff + w * h), w * h / 4);
30     write(vfd, (void *)(buff + w * h * 5 / 4), w * h / 4);
31 
32     free(buff);
33     close(fd);
34     close(yfd);
35     close(ufd);
36     close(vfd);
37 
38     return 0;
39 }
40 
41 int main(void)
42 {
43     mytest_yuv420_split("lena_256x256_yuv420p.yuv", 256, 256);
44     return 0;
45 }

 

输出效果:

 

 

 

2、按照雷神的博客进行复现时候出现以下问题

1.1)使用yuvplayer.exe工具打开拆解的YUV视频分量显示花屏

输出文件名中存在分辨率信息,工具将自动设置分辨率,如代码中所示 256x256 或 128x128,如果文件名不存在则需要手动设置,否则显示乱码。

 

 

1.2)  yuvplayer.exe显示格式设置

 

参考资料:

【雷神】https://blog.csdn.net/leixiaohua1020/article/details/50534150
https://www.cnblogs.com/azraelly/archive/2013/01/01/2841269.html

 

posted on 2022-04-04 23:52  Pengshiqiu  阅读(202)  评论(1编辑  收藏  举报