convert a heif file to png/jpg using ffmpeg
Asked Answered
C

2

17

The use case is very straight forward. Imagemagick is able to do the conversion but I want to do it with ffmpeg. Here is the all commands I have tried and all of them gives moov atom not found error.

ffmpeg -i /Users/ajitesh/Downloads/sample1.heif -c:v png -pix_fmt rgb48 /Users/ajitesh/Downloads/sample.png

Output

[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f85aa813200] moov atom not found
/Users/ajitesh/Downloads/sample1.heif: Invalid data found when processing input

it seems like moov atom is actually not present by trying to extract the location of moov atom using the following command

ffmpeg -v trace -i /Users/ajitesh/Downloads/sample1.heif 2>&1 | grep -e type:\'mdat\' -e type:\'moov\'

Output

[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f824c00f000] type:'mdat' parent:'root' sz: 2503083 420 2503495
[mov,mp4,m4a,3gp,3g2,mj2 @ 0x7f824c00f000] type:'mdat' parent:'root' sz: 2503083 420 2503495
Catalogue answered 24/12, 2020 at 7:57 Comment(0)
T
18

FFmpeg does not currently support HEIF decoding (as of 2021-01-11).

Check the bug report #6521: HEIF support as FFmpeg development is active and the situation may change in the future.

Toniatonic answered 24/12, 2020 at 18:53 Comment(1)
For those of you who just want a command to convert files, I recommend sips on MacOS. apple.stackexchange.com/a/410920Arbitrate
B
17

Welp, it's 2023 and ffmpeg still doesn't support the heif image format. I recommend using heif-convert, which is available via all major linux package managers and homebrew.

Here are the instructions to install and use heif-convert on major Linux distributions and macOS. It's usage looks like this:

heif-convert input.[heic|heif] output.[png|jpg]

And you can install it via:

  1. Ubuntu/Debian:
sudo apt-get install libheif1
  1. Fedora:
sudo dnf install libheif
  1. RHEL/CentOS:
sudo yum install epel-release libheif
  1. Arch Linux:
sudo pacman -S libheif
  1. openSUSE:
sudo zypper install libheif1
  1. macOS:
brew install libheif
Breannabreanne answered 14/5, 2023 at 3:14 Comment(3)
please update ubuntu, Command 'heif-convert' not found, but can be installed with: sudo apt install libheif-examplesAlegar
WSL works like a charm.Esophagus
NixOS: nix-shell -p libheif works like a charm :-)Varien

© 2022 - 2024 — McMap. All rights reserved.