0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Windows bitmapをNV12に変換する

0
Last updated at Posted at 2026-08-29

はじめに

Windows bitmapファイルをNV12バイナリファイルに変換する方法を記載します。

YUV 4:2:0

YUVとは色を輝度(Y)、2つの色差(UV)に分ける方式です。
目は色差変化を感じにくいことを利用してデータ量を減らす目的で使用します。

YUV 4:2:0は色差のデータ量を減らす方式の一つです。
縦横4画素に対してYを4byte, Uを1byte, Vを1byte割り当てます。合計 6byte = 48bitです。
1画素あたり Yを8bit, Uを2bit, Vを2bit割り当てます。合計 12bitです。

NV12

YUV 4:2:0をメモリに配置する方法の一つです。[3][4]を参照ください。
4x4 pixelのメモリ配置の例です。Yを連続配置した後にUVを交互に配置します。
image.png
上記はアライメントなしですが
メモリアクセス効率およびGPUの制約から

  • 1ラインあたりのバイト数
  • 先頭アドレス

をアライメントすることがあります。1ラインあたりのバイト数をstrideといいます。
アライメントについては[5]を参照のこと。

Windows bitmapファイル作成

  • Windowsでペイントを開きます
  • Ctl+wを押下します
    サイズ変更と傾斜が開きます。ピクセルを選択して、水平8、垂直8を指定します。
    image.png
  • 色付けして保存します

    image.png

変換方法

FFmpeg

次のコマンドを実行してbitmapファイルをNV12バイナリファイルに変換します。

console
ffmpeg.exe -i input_8x8.bmp -pix_fmt nv12 -f rawvideo output_8x8.yuv

変換前後のファイルの16進数文字列のダンプ配下の通りです。

$ od -v -A x -t x1z input_8x8.bmp
000000 42 4d f6 00 00 00 00 00 00 00 36 00 00 00 28 00  >BM........6...(.<
000010 00 00 08 00 00 00 08 00 00 00 01 00 18 00 00 00  >................<
000020 00 00 c0 00 00 00 c2 0e 00 00 c2 0e 00 00 00 00  >................<
000030 00 00 00 00 00 00 00 00 ff 00 00 ff 00 00 ff 00  >................<
000040 00 ff 00 ff 00 00 ff 00 00 ff 00 00 ff 00 00 00  >................<
000050 ff 00 00 ff 00 00 ff 00 00 ff 00 ff 00 00 ff 00  >................<
000060 00 ff 00 00 ff 00 00 00 ff 00 00 ff 00 00 ff 00  >................<
000070 00 ff 00 ff 00 00 ff 00 00 ff 00 00 ff 00 00 00  >................<
000080 ff 00 00 ff 00 00 ff 00 00 ff 00 ff 00 00 ff 00  >................<
000090 00 ff 00 00 ff 00 00 00 00 00 00 00 00 00 00 00  >................<
0000a0 00 00 ff ff ff ff ff ff ff ff ff ff ff ff 00 00  >................<
0000b0 00 00 00 00 00 00 00 00 00 00 ff ff ff ff ff ff  >................<
0000c0 ff ff ff ff ff ff 00 00 00 00 00 00 00 00 00 00  >................<
0000d0 00 00 ff ff ff ff ff ff ff ff ff ff ff ff 00 00  >................<
0000e0 00 00 00 00 00 00 00 00 00 00 ff ff ff ff ff ff  >................<
0000f0 ff ff ff ff ff ff                                >......<
0000f6
$ od -v -A x -t x1z output_8x8.yuv
000000 10 10 10 10 eb eb eb eb 10 10 10 10 eb eb eb eb  >................<
000010 10 10 10 10 eb eb eb eb 10 10 10 10 eb eb eb eb  >................<
000020 51 51 51 51 91 91 91 91 51 51 51 51 91 91 91 91  >QQQQ....QQQQ....<
000030 51 51 51 51 91 91 91 91 51 51 51 51 91 91 91 91  >QQQQ....QQQQ....<
000040 81 7e 81 7e 81 81 81 81 7d 89 7d 89 7a 79 7a 79  >.~.~....}.}.zyzy<
000050 5d e7 5d e7 3b 29 3b 29 5a f0 5a f0 36 22 36 22  >].].;);)Z.Z.6"6"<
000060

YUView([6])を使ってNV12を閲覧します。次の設定をします。

  • width / height を設定します
  • YUV formatを選択します
  • Custom...を選択します
  • UV(A) Interleavedをチェックします
    image.png

References

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?