YUV display in OpenGL
|
I am having trouble displaying a raw YUV file that it is in NV12 format. I can display a selected frame, however, it is still mainly in black and white with certain shades of pink and green. Here is how my output looks like Anyways, here is how my program works. (This is done in cocoa/objective-c, but I need your expert advice on program algorithm, not on syntax.) Prior to program execution, the YUV file is stored in a binary file named "test.yuv". The file is in NV12 format, meaning the Y plan is stored first, then the UV plan is interlaced. My file extraction has no problem because I did a lot testings on it. During initiation, I create a lookup table that will convert binary/8 bites/a byte/chars into respected Y, U, V float values For the Y plane this is my code
The U Plane lookup table
And the V look-up table
after this point, I extract the Y & UV plan and store them into two buffers, yBuffer & uvBuffer at this point, I attempt to convert the YUV data and stored it into a RGB buffer array called "frameImage"
then I tried to draw the Image in OpenGl
so basically this my program in a nut shell. essentially i read the binary YUV files, stores all the data in a char array buffer. i then translate these values into their respected YUV float values. This is where I think the error might be: in the Y lookup table I standardize the Y plane to [0,1], in the U plane I standardized the values between [-0.435,0.436], and in the V plane I standardized it bewteen [-0.615,0.615]. I did this because those are the YUV value ranges according to wikipedia. And the YUV to RGB formula is the same formula from Wikipedia. I have also tried various other formulas, and this is the only formula that gives the rough outlook of the frame. Anyone might venture to guess to why my program is not correctly displaying the YUV frame data. I think it is something to do with my standardization technique, but it seems alright to me. I have done a lot of testings, and I am 100% certain that the error is caused by by look up table. I don't think my setting formulas are correct.
@nschmidt I changed my code to what you suggested
and this is the result that i get here is the print line from the console. i am print out the values for Y, U, V and RGB value that are being translated and stored on in the frameImage array YUV:[0.658824,-0.022227,-0.045824] RGBFinal:[0.606593,0.694201,0.613655] YUV:[0.643137,-0.022227,-0.045824] RGBFinal:[0.590906,0.678514,0.597969] YUV:[0.607843,-0.022227,-0.045824] RGBFinal:[0.555612,0.643220,0.562675] YUV:[0.592157,-0.022227,-0.045824] RGBFinal:[0.539926,0.627534,0.546988] YUV:[0.643137,0.025647,0.151941] RGBFinal:[0.816324,0.544799,0.695255] YUV:[0.662745,0.025647,0.151941] RGBFinal:[0.835932,0.564406,0.714863] YUV:[0.690196,0.025647,0.151941] RGBFinal:[0.863383,0.591857,0.742314] Update July 13, 2009 The problem was finally solved thanks to the recommendation from nschmidt . It turns out that my YUV file was actually in YUV 4:1:1 format. I was originally told that it was in YUV NV12 format. Anyways, I would like to share my results with you. Here is output
and my code for decode is as follows
essentially, I used NSData for the raw file extraction. stored in a char array buffer. For YUV to RGB conversion, I used the above formula, afterwards, I clamped the values to [0:255]. then I used a 2DTexture in OpenGL for display. So if you are converting YUV to RGB in the future, use the formula from above. If are using the YUV to RGB conversion formula from the earlier post, then you need to display the texture in GL_Float from the values for RGB are clamped between [0:1]
|
community wiki
|
|
Next try :) I think you're uv buffer is not interleaved. It looks like the U values come first and then the array of V values. Changing the lines to
might indicate if this is really the case.
|
|
|
wow, I tested out my program with your adjustment and it finally worked. thanks a lot man.it turns out that you were right, the U & V plane are not interlaced as I was originally told. thank you so much nschmidt. I'm rating you up – ReachConnection Jul 13 '09 at 15:07
|
||
|
|
no problem :). for the record the first guess about the format being 4:1:1 was actually incorrect. You have 4:2:2 format. The real problem was only your data not being interleaved. – nschmidt Jul 14 '09 at 17:54
|


|
I think you're addressing U and V values incorrectly. Rather than:
It should be something along the lines of
|
|
|
thanks, I missed this mistake. however, I made the changes and the displayed frame is still mainly in black and white, with pink and green shades here and there. – ReachConnection Jul 10 '09 at 15:08
|
||
|
|
I just added a image to show how my output looks like – ReachConnection Jul 10 '09 at 15:33
|
|
The picture looks like you have 4:1:1 format. You should change your lines to
Maybe you can post the result to see, what else is wrong. I find it always hard to think about it. It's much easier to approach this iteratively. |
YUV display in OpenGL的更多相关文章
- 记录一次安装OpenGL的漫长过程
尝试codeblock和Dev-C++ 这学期新开了一门计算机图形图像的课,里面涉及到openGL,中午跑到图书馆开始倒腾OpenGL. 因为电脑里本来有codeblock,于是就想不用教材里面所说的 ...
- Draw the RGB data from kinect C++ via opengl
In order to improve my English writing skills,I am going to write the blogs in English form now! -- ...
- LCD framebuffer驱动设计文档
内容提要:1. android display相关的名词2. 调试LCD驱动需要注意的步骤3. 关于帧缓冲区及I/O内存---------------------------------------- ...
- Direct Access to Video Encoding and Decoding
来源:http://asciiwwdc.com/2014/sessions/513 Direct Access to Video Encoding and Decoding Session 5 ...
- RTSP H264/HEVC 流 Wasm 播放
本文将介绍 RTSP H264/HEVC 裸流如何于网页前端播放.涉及 WebSocket 代理发送流数据, Wasm 前端解码等. 代码: https://github.com/ikuokuo/rt ...
- C++实现数字媒体三维图像变换
C++实现数字媒体三维图像变换 必备环境 glut.h 头文件 glut32.lib 对象文件库 glut32.dll 动态连接库 程序说明 C++实现了用glut画物体对象的功能.并附带放大缩小,旋 ...
- EGL 1.0 学习笔记
http://hi.baidu.com/leo_xxx/item/b01b1fc29abff355ac00ef5c 基本概念 EGL是OpenGL ES与本地Window系统之间的桥梁.EGL创建渲染 ...
- 【2】【MOOC】Python游戏开发入门-北京理工大学【第三部分-游戏开发之机制(屏幕绘制机制)】
学习地址链接:http://www.icourse163.org/course/0809BIT021E-1001873001?utm_campaign=share&utm_medium=and ...
- Starling 2D框架简介(一)
本系列是对Introducing Starling pdf的翻译,下文是对adobe开发人员中心的一片日志的转载,地址为http://www.adobe.com/cn/devnet/flashplay ...
随机推荐
- mysql-配置主从数据库,实现读写分离
主从分离的原则:所有的写操作在主数据库中进行,因为主从分离的原理是涉及到同步数据,那就可能会出现延迟或者其他问题,就可能会出现脏数据. 所以,在从库中进行的读操作也必须是有一定容忍性的数据,例如日志等 ...
- 缓存与DB数据一致性问题解决的几个思路
使用缓存必然会碰到缓存跟真实数据不一致的问题,虽然我们会在数据发生变化时通知缓存,但是这个延迟时间内必然会导致数据不一致,如何解决一般有下面几个思路: 首先,当这个延迟如果在业务上时可以接受的,比如文 ...
- sun.misc.unsafe
Java中大部分错误都是基于内存管理方面的.如果想破坏,可以使用Unsafe这个类. 实例化Unsafe: 下面两种方式是不行的 private Unsafe() {} //私有构造方法 @Calle ...
- Class.forName之坑
今天遇到个问题 找不到类,最后发现 Class.forName中要完整的类名
- CSS3弹性盒布局
使用自适应的窗口弹性盒布局 可以使div总宽度等于浏览器宽度,而且可以随着浏览器的改变而改变. <!DOCTYPE html> <html lang="zh-CN" ...
- Git 命令 操作
常用 Git 命令清单 我每天使用 Git ,但是很多命令记不住.一般来说,日常使用只要记住下图6个命令,就可以了.但是熟练使用,恐怕要记住60-100个命令. 下面是我整理的常用 Git 命令清单. ...
- Windows 64位下安装Redis教程
Redis是一个开源的使用ANSI C语言编写.支持网络.可基于内存亦可持久化的日志型. Key-Value数据库,并提供多种语言的API. 一.下载 地址:Download redis-latest ...
- 命令行模式(CMD)下mysql查询中文显示乱码问题
mysql的默认编码已经设置为utf-8,用其他工具(代码,mysql workbench)写入或读出时显示正常,但用cmd查询时显示为乱码. 2.原因:mysql的客户端根本无法以utf-8的形式返 ...
- 使用 Load Balancer,Corosync,Pacemaker 搭建 Linux 高可用集群
由于网络架构的原因,在一般虚拟机或物理环境中常见的用 VIP 来实现双机高可用方案,无法照搬到 Azure 平台.但利用 Azure 平台提供的负载均衡或者内部负载均衡功能,可以达到类似的效果. 本文 ...
- C++ Deque(双向队列)
C++ Deque(双向队列)是一种优化了的.对序列两端元素进行添加和删除操作的基本序列容器.它允许较为快速地随机访问,但它不像vector 把所有的对象保存在一块连续的内存块,而是采用多个连续的 ...


