I want to convert RGB packed data to YUV420P format using fragment shader. How do I get shader output in a planar format.
I am not really getting how can I make fragment shader to output in planar format.
I am new to OpenGL.
With standard OpenGL ES you can't - it has no concept of YUV.
With extensions, if you have a device that supports the GL_EXT_YUV_target extension you can write into an YUV buffer that is imported.
https://registry.khronos.org/OpenGL/extensions/EXT/EXT_YUV_target.txt
... although exactly what is supported is implementation-defined.
Related
I am confused about image formats. I have read what theoretically YUV and RGB mean. The problem is that I understand them just theoretically.
I have a PNG file. Are PNG files RGB by default? Or can they be NV12(YUV) too?
If no, in what format do NV12 images come from? How do I recognize they are NV12 images? Do I have to perform conversion from a PNG file to read it as NV12?
Part of my confusion is because I read a program that converted RGB to YUV but then later extracted only the Y part and saved it in a file. So the file only had the Y part. Are there files with the whole YUV information?
I am decoding raw H.265 data using avcodec_decode_video2 api. When I examine the resulting instance pictYUV of type AVFrame, I see that pictYUV->format is AV_PIX_FMT_YUV420P and pictYUV->data[0] points to Y-plane. Both of these are expected. However, it appears pictYUV->data[1] seem to contain V-plane data and pictYUV->data[2]seem to contain U-plane data. My intuition was that pictYUV->data would store YUV planes in that order and not YVU planes. Wondering if the data is always ordered as YVU or is there some flag I failed to look at. Regards.
AV_PIX_FMT_YUV420P is planar YUV format (see P at the end of its name), so Y, U, and V are stored separated. There are also YUV formats with interleaved YUV format.
If you are getting the data from an IP camera, it is normal to get planar format.
As far as I can see in the documentation, all conversions involving YUV actually use YCbCr. There are slight differences though, and I would like to convert to the actual YUV format. Is there any way at all using ffmpeg? As an afterthought, is there any other way that is as fast as ffmpeg?
Image source
It turns out it is possible: for example when processing an AVFrame using an AVCodecContext,
use AV_PIX_FMT_YUVJ420P instead of AV_PIX_FMT_YUV_420P (deprecated),
or use AV_PIX_FMT_YUV_420P and set the color_range to AVCOL_RANGE_JPEG.
All links are relative to release 3.2.
Edit:
I believe the actual mathematical conversions are in yuv2rgb.c.
No, it is not possible. YUV is PAL ITU-R BT.470 standard as used for analog TV, it is not in use anymore. You can use https://github.com/fsphil/hacktv with software defined radio instead.
https://git.videolan.org/?p=ffmpeg.git;a=blob;f=libavutil/pixfmt.h;h=d41d1ca12fd381058df41cddfb74fa8e21ad13b0;hb=HEAD#l62
These do not use YCbCr or YUV, those are pixel formats, not color matrices.
I'm building one part of H264 encoder. For testing system, I need to created input image for encoding. We have a programme for read image to RAM file format to use.
My question is how to create a RAW file: bitmap or tiff (I don't want to use compressed format link JPEG)? I googled and recognize alot of raw file type. So what type i should use and how to create? . I think i will use C/C++ or Matlab to create raw file.
P/S: my need format is : YUV ( or Y Cb Cr) 4:2:0 and 8 bit colour deepth
The easiest raw format is just a stream of numbers, representing the pixels. Each raw format can be associated with metadata such as:
width, heigth
width / image row (ie. gstreamer & x-window align each row to dword boundaries)
bits per pixel
byte format / endianness (if 16 bits per pixel or more)
number of image channels
color system HSV, RGB, Bayer, YUV
order of channels, e.g. RGBA, ABGR, GBR
planar vs. packed (or FOURCC code)
or this metadata can be just an internal specification...
I believe one of the easiest approaches (after of course a steep learning curve :) is to use e.g. gstreamer, where you can use existing file/stream sources that read data from camera, file, pre-existing jpeg etc. and pass those raw streams inside a defined pipeline. One useful element is a filesink, which would simply write a single or few successive raw data frames to your filesystem. The gstreamer infrastructure has possibly hundreds of converters and filters, btw. including h264 encoder...
I would bet that if you just dump your memory, that output will conform already to some FOURCC -format (also recognized by gstreamer).
I got a raw YUV file format all I know at this point is that the clip has a resolution of 176x144.
the Y pla is 176x144=25344 bytes, and the UV plan is half of that. Now, I did some readings about YUV, and there are different formats corresponding to different ways how the Y & US planes are stored.
Now, how can perform some sort of check in Cocoa to find the raw YUV file format. Is there a file header in the YUV frame where I can extract some information?
Thanks in advance to everyone
Unfortunately, if it's just a raw YUV stream, it will just be the data for the frames written to disk, one after another. There probably won't be a header that indicates what specific format is being used.
It sounds like you have determined that it's a YUV 4:2:2 stream, so you just need to determine the interleaving order (the most common possibilities are listed here). In response to your previous question, I posted a function which converts a frame from the UYVY (Y422) YUV format to the 2VUY format used by Apple's YUV OpenGL extension. Your best bet may be to try that out and see how the images look, then modify the interleaving format until the colors and image clears up.