Repository navigation
Usage
Yoshihiro Yamazaki edited this page Nov 27, 2026
·
1 revision
メソッドの一覧は 機能、fromHEVC が作る box と toHEVC の流れは 設計、コマンドラインのスクリプトは サンプル一覧 にあります。
例の input.hevc は、ffmpeg (libx265) で作った 64x64・1 フレームの HEVC のバイトストリームです。
% ffmpeg -f lavfi -i testsrc=size=64x64:rate=1 -frames:v 1 -pix_fmt yuv420p -c:v libx265 -f hevc input.hevc
require_once 'IO/HEIF.php';
$heif = new IO_HEIF();
$heif->fromHEVC(file_get_contents('input.hevc')); // 最初の IDR ピクチャから 1 枚の画像
file_put_contents('output.heic', $heif->build());fromHEVC() は boxTree を組み立てるだけなので、書き出すには build() を呼びます。
toHEVC() は結果を返さずに標準出力に書くので、ファイルにするときは ob_start() で受けます。
$heif = new IO_HEIF();
$heif->parse(file_get_contents('output.heic'));
ob_start();
$heif->toHEVC(["RoleType" => "primary"]); // または ["ItemID" => 1]
file_put_contents('output.hevc', ob_get_clean());出力は VPS・SPS・PPS と IDR ピクチャの NAL ユニットに、開始コード 00 00 00 01 を付けたものです。ffmpeg でそのまま読めます。
サムネイルは ["RoleType" => "thumbnail"]、補助画像 (透過など) は ["RoleType" => "aux", "urn" => "urn:mpeg:hevc:2015:auxid:1"] で選びます。
$info = $heif->getHEVCBuildInfo($heif->boxTree);
var_export($info["iloc"]); // array (1 => array ('extents' => array (0 => array (0 => 32, 1 => 805))))
var_export($info["ipma"]); // array (1 => array (0 => 1, 1 => 2, 2 => 3))
var_export($info["ipco"][1]); // array ('type' => 'ispe', 'width' => 64, 'height' => 64)
count($info["hvcC"][1]["nals"]); // 3 (VPS, SPS, PPS)IO_HEIF は IO_ISOBMFF を継承しているので、IO_ISOBMFF の利用方 の例がそのまま使えます。
$heif = new IO_HEIF();
$heif->parse(file_get_contents('output.heic'));
foreach ($heif->getBoxesByTypes(["hvcC"]) as $box) {
echo $box["profileIdc"], " ", $box["levelIdc"], " ", $box["chromaFormat"], PHP_EOL; // 1 30 1
}
$heif->analyze();
var_export($heif->itemTree[1]["iloc"]); // array ('reference' => 0, 'offset' => 32, 'length' => 805)
$heif->appendICCProfile(file_get_contents('sRGB.icc'));
file_put_contents('output-icc.heic', $heif->build());