如何使用OpenCV或其他图像处理库从RGB数据写入YUV 420视频帧? [英] How to write YUV 420 video frames from RGB data using OpenCV or other image processing library?

查看:142
本文介绍了如何使用OpenCV或其他图像处理库从RGB数据写入YUV 420视频帧?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从glReadPixels()生成的rgb数据数组。

请注意,RGB数据是像素打包的(r1,g1,b1,r2,g2,b2,...)。

I have an array of rgb data generated from glReadPixels().
Note that RGB data is pixel packed (r1,g1,b1,r2,g2,b2,...).

如何使用OpenCV或其他C ++库快速编写YUV视频帧,以便我能将它们流式传输到FFMPEG?将RGB像素转换为YUV像素不是问题,因为有许多转换公式在线可用。但是写YUV帧是我的主要问题。我一直在试图写自YUV视频帧自从最近几天,并没有成功这样做。

How can I quickly write a YUV video frame using OpenCV or another C++ library, so that I can stream them to FFMPEG? Converting RGB pixel to YUV pixel is not a problem, as there are many conversion formula available online. However writing the YUV frame is the main problem for me. I have been trying to write the YUV video frame since the last few days and were not successful in doing that.

这是关于编写YUV框架和我遇到的问题的其他问题之一:
我不知道我目前的方法在编写的时候出了什么问题YUV帧到文件。

This is one of my other question about writing YUV frame and the issues that I encountered: Issue with writing YUV image frame in C/C++ I don't know what is wrong with my current approach in writing the YUV frame to a file.

现在我可能想使用现有库(如果有),接受RGB数据,并将它们转换为YUV并写入YUV帧直接到文件或管道。当然,如果我可以修复我现有的程序来编写YUV框架会更好,但你知道,每个软件开发项目也有一个截止日期,所以时间也是我和我的项目团队成员的优先考虑。 / p>

So right now I may want to use existing library (if any), that accepts an RGB data, and convert them to YUV and write the YUV frame directly to a file or to a pipe. Of course it would be much better if I can fix my existing program to write the YUV frame, but you know, there is also a deadline in every software development project, so time is also a priority for me and my project team members.

推荐答案

FFmpeg会很乐意接收RGB数据。你可以看到FFmpeg支持的像素格式:

FFmpeg will happily receive RGB data in. You can see what pixel formats FFmpeg supports by running:

ffmpeg -pix_fmts

可以将第一列中的 I 的条目用作输入。

Any entry with an I in the first column can be used as an input.

由于您没有指定像素位深度,因此我假设它是8位元,并使用 rgb8 像素格式。因此,要获得FFmpeg从 stdin 中读取rgb8数据,您将使用以下命令(我 cat 您将通过您的管道提供):

Since you haven't specified the pixel bit depth, I am going to assume it's 8-bit and use the rgb8 pixel format. So to get FFmpeg to read rgb8 data from stdin you would use the following command (I am cating data in but you would be supplying via your pipe):

cat data.rgb | ffmpeg -f rawvideo -pix_fmt rgb8 -s WIDTHxHEIGHT -i pipe:0 output.mov

一个没有成帧的原始像素格式,您需要对图像尺寸的适当值重新定位WIDTH和HEIGHT,以便FFmpeg知道如何对数据进行成帧。

Since it is a raw pixel format with no framing, you need to subsitite WIDTH and HEIGHT for the appropriate values of your image dimensions so that FFmpeg knows how to frame the data.

我已经将输出指定为MOV文件,但是您需要相应地配置FFmpeg / Red5输出。

I have specifed the output as a MOV file but you would need to configure your FFmpeg/Red5 output accordingly.

这篇关于如何使用OpenCV或其他图像处理库从RGB数据写入YUV 420视频帧?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆