当前位置:   article > 正文

音视频入门基础:像素格式专题(1)——RGB简介_rgb格式

rgb格式

===============================================

音视频入门基础:像素格式专题系列文章:

音视频入门基础:像素格式专题(1)——RGB简介

音视频入门基础:像素格式专题(2)——不通过第三方库将RGB24格式视频转换为BMP格式图片

音视频入门基础:像素格式专题(3)——FFmpeg源码解析BMP格式图片的底层实现原理

音视频入门基础:像素格式专题(4)——YUV简介

音视频入门基础:像素格式专题(5)——使用OpenGL实现yuv420p转rgb播放视频(三重纹理实现)

===============================================

一、像素格式简介  

    像素格式(pixel format)指像素色彩按分量的大小和排列。这种格式以每个像素所使用的总位数以及用于存储像素色彩的红、绿、蓝和 alpha 分量的位数指定。在音视频领域,常用的像素格式包括RGB格式和YUV格式,本文对RGB格式进行简介。

======================

二、RGB格式简介

    三原色光模式(RGB color model,又称RGB表色系统、RGB颜色模型、红绿蓝颜色模型,是一种加色模型,将红(Red)、绿(Green)、蓝(Blue)三原色的色光以不同的比例相加混色,以合成产生各种色彩光。

    RGB颜色模型的主要目的是在电子系统中检测,表示和显示图像,比如电视和电脑,利用大脑强制视觉生理模糊化(失焦),将红绿蓝三原色子像素合成为一色彩像素,产生感知色彩(其实此真彩色并非加色法所产生的合成色彩,原因为该三原色光从来没有重叠在一起,只是人类为了“想”看到色彩,大脑强制眼睛失焦而形成。情况其实就有点像看那些 autostereograms 的立体图时,大脑与眼睛扭曲才能看到“想”看的立体影像的情况)。 红绿蓝三色模型在传统摄影中也有应用。在电子时代之前,基于人类对颜色的感知,RGB颜色模型已经有了坚实的理论支撑。

三、RGB24格式简介

   RGB24是表明图像以RGB三原色,每个像素点3个字节表示的一种图像存储格式,即每像素24位编码的RGB值:使用三个8位无符号整数(0到255)表示红色、绿色和蓝色的强度。这是当前主流的标准表示方法,用于真彩色和JPEG或者TIFF等图像文件格式里的通用颜色交换。它可以产生一千六百万种颜色组合,比如:

(0, 0, 0)是黑色;(255, 255, 255)是白色;(255, 0, 0)是红色;(0, 255, 0)是绿色;(0, 0, 255)是蓝色;(255, 255, 0)是黄色;(0, 255, 255)是青色或水色;(255, 0, 255)是洋红色。

四、RGB24格式视频大小计算

由于RGB24格式每像素占3个字节。所以一张rgb图片的大小 = 图片的宽 * 图片的高 *3 byte。

一个rgb视频的大小 =  里面一张rgb图片的大小 * 该视频文件的总帧数。

下面我们用FFmpeg(我用的FFmpeg版本是5.0.3)来验证上述的公式。

首先查看FFmpeg将视频文件转为rgb文件的命令,执行命令:

ffmpeg -h full

打印ffmpeg的所有帮助信息

可以看到有一栏写道:-pix_fmts           show available pixel formats

  1. Print help / information / capabilities:
  2. -L show license
  3. -h topic show help
  4. -? topic show help
  5. -help topic show help
  6. --help topic show help
  7. -version show version
  8. -buildconf show build configuration
  9. -formats show available formats
  10. -muxers show available muxers
  11. -demuxers show available demuxers
  12. -devices show available devices
  13. -codecs show available codecs
  14. -decoders show available decoders
  15. -encoders show available encoders
  16. -bsfs show available bit stream filters
  17. -protocols show available protocols
  18. -filters show available filters
  19. -pix_fmts show available pixel formats
  20. -layouts show standard channel layouts
  21. -sample_fmts show available audio sample formats
  22. -dispositions show available stream dispositions
  23. -colors show available color names
  24. -sources device list sources of the input device
  25. -sinks device list sinks of the output device
  26. -hwaccels show available HW acceleration methods

意思是FFmpeg命令中可以通过-pix_fmts 选项显示可用的像素格式

所以执行命令:

ffmpeg -pix_fmts

得到输出如下:

  1. Pixel formats:
  2. I.... = Supported Input format for conversion
  3. .O... = Supported Output format for conversion
  4. ..H.. = Hardware accelerated format
  5. ...P. = Paletted format
  6. ....B = Bitstream format
  7. FLAGS NAME NB_COMPONENTS BITS_PER_PIXEL BIT_DEPTHS
  8. -----
  9. IO... yuv420p 3 12 8-8-8
  10. IO... yuyv422 3 16 8-8-8
  11. IO... rgb24 3 24 8-8-8
  12. IO... bgr24 3 24 8-8-8
  13. IO... yuv422p 3 16 8-8-8
  14. IO... yuv444p 3 24 8-8-8
  15. IO... yuv410p 3 9 8-8-8
  16. IO... yuv411p 3 12 8-8-8
  17. IO... gray 1 8 8
  18. IO..B monow 1 1 1
  19. IO..B monob 1 1 1
  20. I..P. pal8 1 8 8
  21. IO... yuvj420p 3 12 8-8-8
  22. IO... yuvj422p 3 16 8-8-8
  23. IO... yuvj444p 3 24 8-8-8
  24. IO... uyvy422 3 16 8-8-8
  25. ..... uyyvyy411 3 12 8-8-8
  26. IO... bgr8 3 8 3-3-2
  27. .O..B bgr4 3 4 1-2-1
  28. IO... bgr4_byte 3 4 1-2-1
  29. IO... rgb8 3 8 2-3-3
  30. .O..B rgb4 3 4 1-2-1
  31. IO... rgb4_byte 3 4 1-2-1
  32. IO... nv12 3 12 8-8-8
  33. IO... nv21 3 12 8-8-8
  34. IO... argb 4 32 8-8-8-8
  35. IO... rgba 4 32 8-8-8-8
  36. IO... abgr 4 32 8-8-8-8
  37. IO... bgra 4 32 8-8-8-8
  38. IO... gray16be 1 16 16
  39. IO... gray16le 1 16 16
  40. IO... yuv440p 3 16 8-8-8
  41. IO... yuvj440p 3 16 8-8-8
  42. IO... yuva420p 4 20 8-8-8-8
  43. IO... rgb48be 3 48 16-16-16
  44. IO... rgb48le 3 48 16-16-16
  45. IO... rgb565be 3 16 5-6-5
  46. IO... rgb565le 3 16 5-6-5
  47. IO... rgb555be 3 15 5-5-5
  48. IO... rgb555le 3 15 5-5-5
  49. IO... bgr565be 3 16 5-6-5
  50. IO... bgr565le 3 16 5-6-5
  51. IO... bgr555be 3 15 5-5-5
  52. IO... bgr555le 3 15 5-5-5
  53. ..H.. vaapi 0 0 0
  54. IO... yuv420p16le 3 24 16-16-16
  55. IO... yuv420p16be 3 24 16-16-16
  56. IO... yuv422p16le 3 32 16-16-16
  57. IO... yuv422p16be 3 32 16-16-16
  58. IO... yuv444p16le 3 48 16-16-16
  59. IO... yuv444p16be 3 48 16-16-16
  60. ..H.. dxva2_vld 0 0 0
  61. IO... rgb444le 3 12 4-4-4
  62. IO... rgb444be 3 12 4-4-4
  63. IO... bgr444le 3 12 4-4-4
  64. IO... bgr444be 3 12 4-4-4
  65. IO... ya8 2 16 8-8
  66. IO... bgr48be 3 48 16-16-16
  67. IO... bgr48le 3 48 16-16-16
  68. IO... yuv420p9be 3 13 9-9-9
  69. IO... yuv420p9le 3 13 9-9-9
  70. IO... yuv420p10be 3 15 10-10-10
  71. IO... yuv420p10le 3 15 10-10-10
  72. IO... yuv422p10be 3 20 10-10-10
  73. IO... yuv422p10le 3 20 10-10-10
  74. IO... yuv444p9be 3 27 9-9-9
  75. IO... yuv444p9le 3 27 9-9-9
  76. IO... yuv444p10be 3 30 10-10-10
  77. IO... yuv444p10le 3 30 10-10-10
  78. IO... yuv422p9be 3 18 9-9-9
  79. IO... yuv422p9le 3 18 9-9-9
  80. IO... gbrp 3 24 8-8-8
  81. IO... gbrp9be 3 27 9-9-9
  82. IO... gbrp9le 3 27 9-9-9
  83. IO... gbrp10be 3 30 10-10-10
  84. IO... gbrp10le 3 30 10-10-10
  85. IO... gbrp16be 3 48 16-16-16
  86. IO... gbrp16le 3 48 16-16-16
  87. IO... yuva422p 4 24 8-8-8-8
  88. IO... yuva444p 4 32 8-8-8-8
  89. IO... yuva420p9be 4 22 9-9-9-9
  90. IO... yuva420p9le 4 22 9-9-9-9
  91. IO... yuva422p9be 4 27 9-9-9-9
  92. IO... yuva422p9le 4 27 9-9-9-9
  93. IO... yuva444p9be 4 36 9-9-9-9
  94. IO... yuva444p9le 4 36 9-9-9-9
  95. IO... yuva420p10be 4 25 10-10-10-10
  96. IO... yuva420p10le 4 25 10-10-10-10
  97. IO... yuva422p10be 4 30 10-10-10-10
  98. IO... yuva422p10le 4 30 10-10-10-10
  99. IO... yuva444p10be 4 40 10-10-10-10
  100. IO... yuva444p10le 4 40 10-10-10-10
  101. IO... yuva420p16be 4 40 16-16-16-16
  102. IO... yuva420p16le 4 40 16-16-16-16
  103. IO... yuva422p16be 4 48 16-16-16-16
  104. IO... yuva422p16le 4 48 16-16-16-16
  105. IO... yuva444p16be 4 64 16-16-16-16
  106. IO... yuva444p16le 4 64 16-16-16-16
  107. ..H.. vdpau 0 0 0
  108. IO... xyz12le 3 36 12-12-12
  109. IO... xyz12be 3 36 12-12-12
  110. ..... nv16 3 16 8-8-8
  111. ..... nv20le 3 20 10-10-10
  112. ..... nv20be 3 20 10-10-10
  113. IO... rgba64be 4 64 16-16-16-16
  114. IO... rgba64le 4 64 16-16-16-16
  115. IO... bgra64be 4 64 16-16-16-16
  116. IO... bgra64le 4 64 16-16-16-16
  117. IO... yvyu422 3 16 8-8-8
  118. IO... ya16be 2 32 16-16
  119. IO... ya16le 2 32 16-16
  120. IO... gbrap 4 32 8-8-8-8
  121. IO... gbrap16be 4 64 16-16-16-16
  122. IO... gbrap16le 4 64 16-16-16-16
  123. ..H.. qsv 0 0 0
  124. ..H.. mmal 0 0 0
  125. ..H.. d3d11va_vld 0 0 0
  126. ..H.. cuda 0 0 0
  127. IO... 0rgb 3 24 8-8-8
  128. IO... rgb0 3 24 8-8-8
  129. IO... 0bgr 3 24 8-8-8
  130. IO... bgr0 3 24 8-8-8
  131. IO... yuv420p12be 3 18 12-12-12
  132. IO... yuv420p12le 3 18 12-12-12
  133. IO... yuv420p14be 3 21 14-14-14
  134. IO... yuv420p14le 3 21 14-14-14
  135. IO... yuv422p12be 3 24 12-12-12
  136. IO... yuv422p12le 3 24 12-12-12
  137. IO... yuv422p14be 3 28 14-14-14
  138. IO... yuv422p14le 3 28 14-14-14
  139. IO... yuv444p12be 3 36 12-12-12
  140. IO... yuv444p12le 3 36 12-12-12
  141. IO... yuv444p14be 3 42 14-14-14
  142. IO... yuv444p14le 3 42 14-14-14
  143. IO... gbrp12be 3 36 12-12-12
  144. IO... gbrp12le 3 36 12-12-12
  145. IO... gbrp14be 3 42 14-14-14
  146. IO... gbrp14le 3 42 14-14-14
  147. IO... yuvj411p 3 12 8-8-8
  148. I.... bayer_bggr8 3 8 2-4-2
  149. I.... bayer_rggb8 3 8 2-4-2
  150. I.... bayer_gbrg8 3 8 2-4-2
  151. I.... bayer_grbg8 3 8 2-4-2
  152. I.... bayer_bggr16le 3 16 4-8-4
  153. I.... bayer_bggr16be 3 16 4-8-4
  154. I.... bayer_rggb16le 3 16 4-8-4
  155. I.... bayer_rggb16be 3 16 4-8-4
  156. I.... bayer_gbrg16le 3 16 4-8-4
  157. I.... bayer_gbrg16be 3 16 4-8-4
  158. I.... bayer_grbg16le 3 16 4-8-4
  159. I.... bayer_grbg16be 3 16 4-8-4
  160. ..H.. xvmc 0 0 0
  161. IO... yuv440p10le 3 20 10-10-10
  162. IO... yuv440p10be 3 20 10-10-10
  163. IO... yuv440p12le 3 24 12-12-12
  164. IO... yuv440p12be 3 24 12-12-12
  165. IO... ayuv64le 4 64 16-16-16-16
  166. ..... ayuv64be 4 64 16-16-16-16
  167. ..H.. videotoolbox_vld 0 0 0
  168. IO... p010le 3 15 10-10-10
  169. IO... p010be 3 15 10-10-10
  170. IO... gbrap12be 4 48 12-12-12-12
  171. IO... gbrap12le 4 48 12-12-12-12
  172. IO... gbrap10be 4 40 10-10-10-10
  173. IO... gbrap10le 4 40 10-10-10-10
  174. ..H.. mediacodec 0 0 0
  175. IO... gray12be 1 12 12
  176. IO... gray12le 1 12 12
  177. IO... gray10be 1 10 10
  178. IO... gray10le 1 10 10
  179. IO... p016le 3 24 16-16-16
  180. IO... p016be 3 24 16-16-16
  181. ..H.. d3d11 0 0 0
  182. IO... gray9be 1 9 9
  183. IO... gray9le 1 9 9
  184. IO... gbrpf32be 3 96 32-32-32
  185. IO... gbrpf32le 3 96 32-32-32
  186. IO... gbrapf32be 4 128 32-32-32-32
  187. IO... gbrapf32le 4 128 32-32-32-32
  188. ..H.. drm_prime 0 0 0
  189. ..H.. opencl 0 0 0
  190. IO... gray14be 1 14 14
  191. IO... gray14le 1 14 14
  192. IO... grayf32be 1 32 32
  193. IO... grayf32le 1 32 32
  194. IO... yuva422p12be 4 36 12-12-12-12
  195. IO... yuva422p12le 4 36 12-12-12-12
  196. IO... yuva444p12be 4 48 12-12-12-12
  197. IO... yuva444p12le 4 48 12-12-12-12
  198. IO... nv24 3 24 8-8-8
  199. IO... nv42 3 24 8-8-8
  200. ..H.. vulkan 0 0 0
  201. ..... y210be 3 20 10-10-10
  202. I.... y210le 3 20 10-10-10
  203. IO... x2rgb10le 3 30 10-10-10
  204. ..... x2rgb10be 3 30 10-10-10
  205. IO... x2bgr10le 3 30 10-10-10
  206. ..... x2bgr10be 3 30 10-10-10
  207. IO... p210be 3 20 10-10-10
  208. IO... p210le 3 20 10-10-10
  209. IO... p410be 3 30 10-10-10
  210. IO... p410le 3 30 10-10-10
  211. IO... p216be 3 32 16-16-16
  212. IO... p216le 3 32 16-16-16
  213. IO... p416be 3 48 16-16-16
  214. IO... p416le 3 48 16-16-16

可以看到ffmpeg是支持rgb24的像素格式转换的。

我们用下面的这个“视频素材_天空中的云.mp4”视频作为演示:

该视频的大小为4.57 MB (4,794,032 字节)

分辨率为:1280 * 720

通过命令:

ffprobe -v error -count_frames -select_streams v:0 -show_entries stream=nb_read_frames -of default=nokey=1:noprint_wrappers=1 视频素材_天空中的云.mp4

可以得到该视频总共有387帧

将“视频素材_天空中的云.mp4”转换为像素格式为rgb24的文件:output.rgb

ffmpeg -i 视频素材_天空中的云.mp4 -pix_fmt rgb24 output.rgb

该文件即包含原视频“视频素材_天空中的云.mp4” 里面解压并像素格式转换为rgb24后的所有数据

可以看到它的大小为0.99 GB  = 1,069,977,600 byte = 1280 * 720 * 3 * 387 byte。所以可以证明“RGB24格式每像素占3个字节” 以及相关公式是正确的。

五、播放RGB24格式视频

常用的播放器无法播放裸rgb24格式的视频,但可以通过YUView 来播放,该播放器支持播放裸RGB 文件。

打开YUView,"File" -> "Open File"

设置视频宽度和高度,选择RGB Format为RGB 8bit(因为rgb24每个像素占8位),点击播放按钮就能播放了

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/木道寻08/article/detail/930100
推荐阅读
相关标签
  

闽ICP备14008679号