Skip to content
Yoshihiro Yamazaki edited this page Nov 27, 2026 · 1 revision

Home > 利用方

利用方

継承関係と AVIF の box の扱いは 設計、コマンドラインのスクリプトは サンプル一覧 にあります。 メソッドはすべて IO_ISOBMFF のものです。一覧は IO_ISOBMFF の機能、ほかの例は IO_ISOBMFF の利用方 にあります。 例の input.avif は avif-samples/bbb_4k.avif です。

av1C を読む

require_once 'IO/AVIF.php';

$avif = new IO_AVIF();
$avif->parse(file_get_contents('input.avif'));

$av1C = $avif->getBoxesByTypes(["av1C"])[0];
printf("profile:%d level:%d tier:%d bitdepth:%d mono:%d subsampling:%d,%d\n",
       $av1C["seq_profile"], $av1C["seq_level_idx_0"], $av1C["seq_tier_0"],
       $av1C["twelve_bit"] ? 12 : ($av1C["high_bitdepth"] ? 10 : 8),
       $av1C["monochrome"],
       $av1C["chroma_subsampling_x"], $av1C["chroma_subsampling_y"]);
// profile:0 level:13 tier:0 bitdepth:8 mono:0 subsampling:1,1
echo bin2hex($av1C["configOBUs"]), PHP_EOL;
// 0a0c0000006aefbfe1bdfff98040 (sequence header OBU)

item を探す

$avif->analyze();
$iloc = $avif->itemTree[1]["iloc"];
echo $avif->itemTree[1]["infe"]["type"], " ", $iloc["offset"], " ", $iloc["length"], PHP_EOL;
// av01 409 30980

item 1 (主画像) の AV1 のデータは、ファイルの 409 バイト目から 30980 バイトです。

編集して書き出す

$avif->removeBoxByType(["iref"]);
file_put_contents('output.avif', $avif->build());

mdat が動いた分は build が iloc のオフセットを書き直すので、output.avif は libheif (heif-dec) でそのまま読めます。

Clone this wiki locally