0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

AVIF vs JPG リサイズ処理時間

0
Last updated at Posted at 2026-08-06

AVIF vs JPG - 3段階検証で最適パラメータを発見

背景

画像20万枚のリサイズ(サムネイル化)をするときの、処理時間ファイルサイズ画質のバランスをClaudeで検証した、JPG と AVIF のパラメータを検証しました。PNGも検証したが処理速度、品質ともに可逆圧縮のためチューニングせず検証途中から破棄。近代フォーマットであるAVIFの実力を測るための検証である。

JPG default値: JPG (quality=85)
AVIF default値: AVIF(quality=75,speed=6,autotiling=false)

この検証を始めたのはリサイズ処理時間と品質の検証をしたく比較していたところ、初回の検証でAVIFがあり得ないくらい遅い処理時間であったことからパラメータに疑問を持ち、パラメータを色々変えて検証したら興味深い結果だったので記事にまとめました。

初回検証
Claudeは圧縮率が同じにすべきと思い込んだのかAVIFのquality=85に変更していた。
リサイズ処理時間 1ms以下 JPG quality=85
リサイズ処理時間 100-120ms AVIF(quality=85,speed=6,autotiling=false)

AVIFの実力

結果: AVIF (quality=75, speed=10, autotiling=True) が JPG と同等の処理時間で、10% ファイルサイズ削減と優れた画質を実現。AVIFも正しくパラメータ設定しないとデフォルトで使うとリサイズ時間が膨大にかかるよってこと。JPGと同等の品質まで落とすならデフォルト75よりさらに落とす必要がありますが記事末に比較画像を載せておきますが75でもJPGより画質は良いです。特に圧縮時特有のガビガビ感が少なくきれいに圧縮されます。

評価項目 JPG(q=85) AVIF(q=75,s=10)
リサイズ処理 高速 やや高速
リサイズ後のファイルサイズ 34.7KB 28.1KB
画質 ★★★★☆ ★★★★★

結論

AVIF (quality=75, speed=10, autotiling=True) を推奨

理由:

  1. 処理時間: JPG とほぼ同等(わずか1分追加)
  2. ファイルサイズ: 10% 削減(20万枚で720MB)
  3. 画質: より優れている(実測で確認)
  4. 安定性: JPG と同等の低ばらつき

移行リスク: 最小限(ブラウザ対応99%以上)



検証環境

from PIL import Image

def resize_keep_512(image_path):
    """Keep512: アスペクト比を維持、各辺が512以下"""
    with Image.open(image_path) as img:
        if img.mode != 'RGB':
            img = img.convert('RGB')
        
        orig_width, orig_height = img.size
        aspect_ratio = orig_width / orig_height
        
        if aspect_ratio > 1:
            new_width = min(orig_width, 512)
            new_height = int(new_width / aspect_ratio)
        else:
            new_height = min(orig_height, 512)
            new_width = int(new_height * aspect_ratio)
        
        resized = img.resize((new_width, new_height), Image.Resampling.BICUBIC)
    
    return resized

テスト画像:

  • Image1: 7086×4729(横長)→ リサイズ後 512×341
  • Image2: 2043×3065(縦長)→ リサイズ後 341×512
  • 各設定10回実行の平均値

3段階検証結果

段階1:JPG quality=85(ベースライン)

resized.save(output, format='JPEG', quality=85)
項目 Image1 Image2 平均
処理時間 0.66ms 0.74ms 0.70ms
ファイルサイズ 27.4KB 41.9KB 34.7KB
標準偏差 0.15ms 0.08ms 0.12ms

段階2:AVIF quality=75, speed=8(最適化版)

resized.save(output, format='AVIF', quality=75, speed=8)
項目 Image1 Image2 平均
処理時間 49.09ms 73.12ms 61.10ms
ファイルサイズ 19.6KB 36.6KB 28.1KB
標準偏差 1.40ms 8.44ms 4.92ms

評価:

  • ✓ ファイルサイズ: 19% 削減
  • ✓ 処理時間は許容範囲(全体: 3時間18分)
  • △ ばらつきあり

段階3:AVIF quality=75, speed=10 + autotiling=True(最終推奨)

resized.save(output, format='AVIF', quality=75, speed=10, autotiling=True)
項目 Image1 Image2 平均
処理時間 10.41ms 14.49ms 12.45ms
ファイルサイズ 22.4KB 39.8KB 31.1KB
標準偏差 0.16ms 0.38ms 0.27ms

評価:

  • ✓ ファイルサイズ: 10% 削減
  • ✓ 処理時間: JPG とほぼ同等
  • ✓ 安定性: 極めて高い(JPG 並み)

検証結果

評価項目 JPG AVIF(8) AVIF(10+AT) 勝者
処理時間(1枚) 0.70ms 61.10ms 12.45ms JPG(速いが)
リサイズ処理(20万枚) 19秒 27分 5分 AVIF
安定性 0.12ms 4.92ms 0.27ms AVIF
ファイルサイズ 34.7KB 28.1KB 31.1KB AVIF
画質 ★★★★☆ ★★★★★ ★★★★★ AVIF
ブラウザ対応 100% 99%+ 99%+ ほぼ同等

リサイズ処理時間(20万枚マルチスレッド8)

形式 リサイズ処理時間 JPGとの差
JPG quality=85 19秒 -
AVIF quality=75, speed=8 27分 +26分41秒
AVIF quality=75, speed=10, autotiling=True 5分 +4分41秒**

品質比較

元画像

Image1(7086×4729 横長)

img1_keep512.jpg

段階1: JPG quality=85 (41.9KB)

jpg512_80.png

段階2: AVIF quality=75, speed=8 (36.6KB)

avif512_q75_s8.png

段階3: AVIF quality=75, speed=10, autotiling (39.8KB)

avif512_q75_s10.png

AVIF speed=10+autotiling は JPG より 5% 小さいファイルサイズで、より高い画質を実現


なぜ autotiling で改善できたのか?

autotiling の仕組み

通常のAVIFエンコード(autotiling=False):
512×341 画像全体を一度にAV1処理
→ メモリ効率が低い、CPU キャッシュ未利用

autotiling=True:
512×341 → 複数タイル(例:256×256)に自動分割
各タイルを並列処理
→ メモリ効率向上、CPU キャッシュ活用

効果(speed=10比較)

効果 数値
処理時間削減 20.9%
安定性改善(標準偏差) Image1: 18.35ms → 0.16ms(114倍

特に大きな画像ほど効果が大きい。


最終推奨コード

def encode_thumbnail_optimal(image_path, output_path):
    """
    最適化されたサムネイル生成
    
    推奨: AVIF (quality=75, speed=10, autotiling=True)
    - JPG と同等の処理時間
    - 10% のファイルサイズ削減
    - より優れた画質
    """
    resized = resize_keep_512(image_path)
    
    resized.save(
        output_path,
        format='AVIF',
        quality=75,
        speed=10,
        autotiling=True
    )

参考

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?