1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

ffmpeg でyuv420 semi planarの画像データを作成する

Last updated at Posted at 2018-01-10

動画を扱う機器は、映像の内部フォーマットとしてyuv420 semi planarを採用していることが多いと思います。

開発中にはそのフォーマットのデータを見たり、作成したりする場面があります。最初はこれを imagemagik を使ってやろうとしたのですがいまくいかず。
でもffmpegではうまくいきました。ポイントはそのピクセルフォーマットの名称が "nv12" または "nv21" であること。
nv12とnv21の違いはYUVのうちのUとVの位置が入れ替わっているだけ。
(nv12で試して、赤と青が入れ替わっていたらnv21に変えればいい。)

nv21フォーマットへの変換の方法

ffmpeg -i input.jpg -f rawvideo -pix_fmt nv21 out.raw

この画像のサイズは 1920x1080 でした。nv21フォーマットのデータサイズはこの1.5倍になります。
1920 x 1080 x 1.5 = 3110400

$ ls -l out.raw 
-rw-rw-r-- 1 koba koba 3110400 Jan 10 12:15 out.raw

nv21フォーマットの画像データを見る方法

ffplay -video_size 1920x1080 -f rawvideo -pixel_format nv21 out.raw  

画像のサイズは引数で指定してあげる必要があります。

1
2
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
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?