LoginSignup
11
8

More than 5 years have passed since last update.

お手軽なHEIFファイルの作成・表示方法

Last updated at Posted at 2017-08-05

HEIFファイルの作成

あらかじめFFmpeg+libx265GPACをインストールしておく。

$ brew install ffmpeg --with-x265
$ brew install gpac

ソース画像ファイル{source}から生のHEVCビットストリームへエンコードし、続いてHEIFファイル形式に格納する。

$ ffmpeg -i {source} -vcodec -pix_fmt yuv420p -codec:v libx265 ¥
  -crf 15 -preset placebo -x265-params info=0 -f hevc temp.hvc -y

$ MP4Box -add-image temp.hvc -ab heic -new output.heic

上記コマンド中の-crfで画質とファイサイズのトレードオフを制御する。値が小さいほど高画質だがファイルサイズが大きくなり、値が大きいほどファイサイズが小さくなるが画質は劣化する。

HEIFファイルの表示

NokiaによるJavaScript実装を利用すると、既存のWebブラウザ上でHEIFファイルを画像表示できる。商用利用時はライセンス条項に留意のこと。

<!DOCTYPE html>
<html>
<head>
  <script src="js/libde265-selector.js"></script>
  <script src="js/heif-api.js"></script>
  <script src="js/heif-extension.js"></script>
  <script src="js/hevc-decoder.js"></script>
  <script src="js/image-provider.js"></script>
</head>
<body>
  <img src="output.heic" />
</body>
</html>

技術的には、JavaScriptによりHEIFファイル解析とHEVCデコード(libde265)を行い、img要素から置き換えたcanvas要素にデコード画像が描画される。

11
8
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
11
8