MacOS How to convert a heic image file into a png/jpeg file.
MacOS にデフォルトでインストールされている sips コマンドを使うと、
ヒーフ(HEIF / 拡張子 .HEIC) 形式の画像ファイルを別の画像の形式 (png / jpeg / jpeg2000 ...) に変換できる。
() {
readonly toFormat="jpeg"
readonly original="${1}"
readonly converted="${1%.*}.${toFormat}"
sips \
--setProperty format "${toFormat}" \
"${original}" \
--out "${converted}"
} "[変換したいファイル].HEIC"
iPhone で撮影した写真を AirDrop で Mac に共有すると、 Mac には ${HOME}/Downloads の下に .HEIC という拡張子でファイルが保存される。
ffmpeg において現在(2024/02)はまだ .HEIC 形式には対応していない(git リポジトリのコードは対応済になっている)ので、 sips コマンドの出番となる。
iPhone から Mac に AirDrop する場合は、複数のファイルを送ることが多いので、次のようなコマンドで使えるようにしておくと良いかもしれない。
find ~/Downloads \
-type f \
-name 'IMG_*.HEIC' \
-exec bash -c '
readonly original="${1}"
readonly toFormat="${2:-jpeg}"
readonly converted="${1%.*}.${toFormat}"
sips \
--setProperty format "${toFormat}" \
"${original}" \
--out "${converted}"
' _ {} "jpeg"
\;