1

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?

KansaiRobot
  • 7,564
  • 11
  • 71
  • 150
  • AFAIK it's used in some video formats. JPEG uses YCbCr which is pretty similar but not precisely the same. – user253751 May 20 '22 at 10:27
  • NV12 format is used for storing **raw** images, and mostly raw video frames (since NV12 is raw you can't identify it, need to know from advance). PNG is an image container, so it can't be in NV12 format. NV12 format is YUV420 format with specific ordering. You may look at my [following post](https://stackoverflow.com/questions/57022633/how-to-convert-srgb-to-nv12-format-using-numpy). According to [Wikipedia](https://en.wikipedia.org/wiki/Portable_Network_Graphics), it look like PNG doesn't supports YUV color space, so it must be converted to RGB (and my be converted back almost lossless). – Rotem May 20 '22 at 21:18
  • 1
    Is there a place where I can get raw images in NV12 format? – KansaiRobot May 20 '22 at 23:26
  • 1
    You may use [FFmpeg](https://ffmpeg.org/) (command line interface) for converting any image to (raw) NV12 format. Example: `ffmpeg -i in.png -pix_fmt nv12 -f rawvideo out.raw` – Rotem May 22 '22 at 16:06
  • I suppose `out.raw` would be in the nv12 format right? – KansaiRobot May 23 '22 at 00:28

0 Answers0