iPhoneで撮影した画像のHEIFファイルが開けないエラー

ソフトウェア

いままでiPhoneで撮影した画像のHEIFファイル (拡張子*.HEIC) はLinuxのPCに取り込んでは、扱いやすいようにJPEGに変換していました。変換には libheif のコマンドである heif-convert を使っていました。

Ubuntu 22.04の環境でいままでのように変換しようとしたらエラーが発生するようになってしまいました。iPhone (iOS) のバージョンアップ が原因みたいです。

$ sudo apt install libheif-dev libheif-examples
$ heif-convert IMG_6822.HEIC IMG_6822.JPG
Could not read HEIF/AVIF file: Invalid input: Unspecified: Metadata not correctly assigned to image

検索したらlibheifの更新で直るという情報を見つけたので試してみます。

$ sudo add-apt-repository ppa:strukturag/libheif                                                                                                                             
PPA publishes dbgsym, you may need to include 'main/debug' component                                                                                                                                        
Repository: 'deb https://ppa.launchpadcontent.net/strukturag/libheif/ubuntu/ jammy main'                                                                                                                    
Description:                                                                                                                                                                                                
This PPA contains packages to add support for HEIC / HEIF and AVIF files.                                                                                                                                   
                                                                                                                                                                                                            
libheif is an ISO/IEC 23008-12:2017 HEIF and AVIF (AV1 Image File Format) file format decoder and encoder.                                                                                                  
                                                                                                                                                                                                            
HEIF and AVIF are new image file formats employing HEVC (h.265) or AV1 image coding, respectively, for the best compression ratios currently possible.                                                      
                                                                                                                                                                                                            
libheif makes use of libde265 for HEIF image decoding and x265 for encoding. For AVIF, libaom, dav1d, or rav1e are used as codecs.                                                                          
                                                                                                                                                                                                            
libheif has support for decoding                                                                                                                                                                            
- tiled images                                                                                                                                                                                              
- alpha channels                                                                                                                                                                                            
- thumbnails                                                                                                                                                                                                
- reading EXIF and XMP metadata                                                                                                                                                                             
- reading the depth channel                                                                                                                                                                                 
- multiple images in a file                                                                                                                                                                                 
- image transformations (crop, mirror, rotate)                                                                                                                                                              
- overlay images                                                                                                                                                                                            
- plugin interface to add alternative codecs for additional formats (AVC, JPEG)                                                                                                                             
- decoding of files while downloading (e.g. extract image size before file has been completely downloaded)                                                                                                  
- reading color profiles                                                                                                                                                                                    
- heix images (10 and 12 bit, chroma 4:2:2)                                                                                                                                                                 

The encoder supports:                                                                                                                                                                                       
- lossy compression with adjustable quality                                                                                                                                                                 
- lossless compression                                                                                                                                                                                      
- alpha channels                                                                                                                                                                                            
- thumbnails                                                                                                                                                                                                
- save multiple images to a file                                                                                                                                                                            
- save EXIF and XMP metadata                                                                                                                                                                                
- writing color profiles                                                                                                                                                                                    
- 10 and 12 bit images                                                                                                                                                                                      
- monochrome images                                                                                                                                                                                         

See https://github.com/strukturag/libheif for further information.                                    

NOTE: You might also need to enable the PPA "strukturag/libde265",                                    
so dependencies can be resolved.                   
More info: https://launchpad.net/~strukturag/+archive/ubuntu/libheif                                  
Adding repository.                                 
Press [ENTER] to continue or Ctrl-c to cancel.

aptのリポジトリを追加して、

$ sudo add-apt-repository ppa:strukturag/libde265Repository: 'deb https://ppa.launchpadcontent.net/strukturag/libde265/ubuntu/ jammy main'
Description:                                       
libde265 is an open source implementation of the h.265 video codec. It is written from scratch and has a plain C API to enable a simple integration into other software.

libde265 supports WPP and tile-based multithreading and includes SSE optimizations. The decoder supports all features of the Main and Main10 profile (HEVC-V1) and most profiles of HEVC-V2 (chroma 4:2:2, 4
:4:4, monochrome, and bit depths up to 14 bits).

libde265 is released under the LGPL, further information are available at
http://www.libde265.org
https://github.com/strukturag/libde265

This PPA contains Ubuntu packages of the libde265 library.                                            

Plugins for the GStreamer framework, VLC and required dependencies are only provided for older versions of Ubuntu and are no longer maintained since the libde265 plugin is part of upstream GStreamer.

The (old) GStreamer plugin source is available at
https://github.com/strukturag/gstreamer-libde265                           

The VLC plugin source is available at
https://github.com/strukturag/vlc-libde265

You can get sample Matroska streams from
http://www.libde265.org/downloads-videos/
http://www.divx.com/de/hevc
http://labs.divx.com/node/127909
More info: https://launchpad.net/~strukturag/+archive/ubuntu/libde265
Adding repository.
Press [ENTER] to continue or Ctrl-c to cancel.

もう1つリポジトリを追加して

$ sudo apt update
$ sudo apt install libheif-examples                                                                                                                                          
パッケージリストを読み込んでいます... 完了                                                            
依存関係ツリーを作成しています... 完了                                                                
状態情報を読み取っています... 完了                                                                    
以下のパッケージが自動でインストールされましたが、もう必要とされていません:                           
  libaom-dev libdav1d-dev libde265-dev libx265-dev                                                    
これを削除するには 'sudo apt autoremove' を利用してください。                                         
以下の追加パッケージがインストールされます:                                                           
  libc-dev-bin libc-devtools libc6-dev libcrypt-dev libheif-dev                                       
  libheif-plugin-aomenc libheif-plugin-dav1d libheif-plugin-libde265                                  
  libheif-plugin-x265 libheif1 libnsl-dev libtirpc-dev linux-libc-dev                                 
  manpages-dev rpcsvc-proto zlib1g-dev             
提案パッケージ:                                                                                       
  glibc-doc libheif-plugin-ffmpegdec libheif-plugin-jpegdec                                           
  libheif-plugin-jpegenc libheif-plugin-j2kdec libheif-plugin-j2kenc                                  
  libheif-plugin-svtenc                                                                               
以下のパッケージが新たにインストールされます:                                                         
  libc-dev-bin libc-devtools libc6-dev libcrypt-dev libheif-plugin-aomenc                                                                                                                                   
  libheif-plugin-dav1d libheif-plugin-libde265 libheif-plugin-x265 libnsl-dev                         
  libtirpc-dev linux-libc-dev manpages-dev rpcsvc-proto zlib1g-dev                                    
以下のパッケージはアップグレードされます:                                                             
  libheif-dev libheif-examples libheif1                                                               
アップグレード: 3 個、新規インストール: 14 個、削除: 0 個、保留: 69 個。                              
6,993 kB のアーカイブを取得する必要があります。                                                       
この操作後に追加で 28.6 MB のディスク容量が消費されます。                                             
続行しますか? [Y/n] y

apt updateを行ってからlibheif-examplesを更新します。

$ heif-convert IMG_6365.HEIC IMG_6365.jpg                              
File contains 1 image                                                                                 
decoding image... 100%                                                                                
Written to IMG_6365.jpg

更新したlibheifのコマンドを使って変換を行うとエラーが解消されていました。

同じエラーで困っている方がいましたらこの方法を試してみてください。

コメント