5

I've been looking around for a while for a way to start packing image bytestreams into HEIF files, since macOS High Sierra and and iOS 11 are now out. Haven't had much luck, just large numbers of people converting .heic files to .jpg, and the Nokia JS viewer on GitHub

To start, I am not looking to convert my existing Photo Library all to HEVC encoded .heic files, there's diminishing returns to be had there since they're already jpegged and have had quality loss from the original. So this question is not a duplicate of the "Convert whole library to new .HEIC format" question

My goal:

  • Take both a mpeg bytestream and a PNG or JPG bytestream and pack them into a .heic file

  • Take multiple PNG and/or JPG bytestreams and make a .heic file of them (like a burst series of photos)

HEIF is just a container, so while it was designed for HEVC use, it does support other data types like jpg, png, pretty much anything that the viewing applications support in their natives file formats.

I just haven't been able to find any software that will let me do it. Everything I search for to do with HEIF or HEIC in the term just pumps me with tech news headlines about Apple trying to replace jpeg, and people converting their .heic files once their imported from their computer (which seems like it would take effort to do since iOS defaultly will convert them for you if you try to import them or share them anywhere it can't explicitly confirm the reaching end supports them...)

So I'm hoping someone here knows a thing or two and could point me in the right direction at least.

I'm not adverse to command line tools, or even doing some development myself if I can get pointed at a library I can import into a Swift application (I'm a late bloomer in programming, and while I could say the same for Javascript, if I was to build an app around a library to do this work, I'd much rather use Swift than use a scripting language)

So hopefully someone has thought the same thing and had better luck than me finding this! :)

Edit 1, Nov 10:

I've found a site by a bloke called Ben Gotow that talks about converting existing JPEGs into HEVC bitstreams, and then putting them into a .heic or .heif container. It's close, but he hadn't been able to find a lot of detail for doing more than that. I'm not adding this as an answer, just as an edit since it is relevant but doesn't actually achieve my goal. hope anyone else finding this question will find his site useful!
jpgtoheif.com

2
  • 1
    it feels it will be very hard to find the answer on "making" these files on your own, since it's hard to find even a viewer-app for HEIC, not even saying about creation/editing...
    – Farside
    Commented Nov 9, 2017 at 11:21
  • Yeah, that is my worry... Still, at least if I ask the question, hopefully gradually other people will find this question and maybe even contribute what they have found. For them moment all I can find, no matter what I search, is "How do I convert HEIC/HEIF to JPEG" posts. And one website talking about converting jpegs and videos to HEVC and putting them in a HEIF container (I'm about to add that to the original question as an edit, since it has a little relevant data anyway :) Commented Nov 10, 2017 at 5:54

2 Answers 2

3

This use of GPAC may move closer to the goals you desire:

What is GPAC?

GPAC is an Open Source multimedia framework. GPAC is used for research and academic purposes and beyond through industrial collaborations! The project covers different aspects of multimedia, with a focus on presentation technologies (graphics, animation and interactivity) and on multimedia packaging formats such as MP4.

More details:

A little more research and an answer here provides the way! We need several things installed, ideally with homebrew:

  • x265 and GPAC brew install x265 gpac

  • FFmpeg with x265 support

    brew install ffmpeg --with-fdk-aac --with-ffplay --with-freetype --with-libass --with-libquvi --with-libvorbis --with-libvpx --with-opus --with-x265
    

Reference

Now that you have the tools, try a script like this to convert images in a folder to HEIF/HEIC:

for F in *.jpg *.png *.tif *.tiff; \
  do ffmpeg -i "$F" -crf 23 -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" -preset slower -pix_fmt yuv420p -f hevc "${F%.*}.hvc" && \
     MP4Box -add-image "${F%.*}.hvc" -ab heic -new "${F%.*}.heic" && \
     rm "${F%.*}.hvc";
  done;

I tried it with a folder of images and it works. It turns images with odd dimensions to even dimensions, for instance, but besides a few caveats it works.

3
  • 1
    I'm gonna be doing a lotta reading now, it looks like! If it can get what I'm after down pat, I'll be back here and edit what I find onto the end of your answer for anyone else who might be after the same thing and mark it as accepted, unless someone else comes along with a better answer :) Commented Mar 18, 2018 at 7:15
  • No, this doesn't answer your taking multiple PNG and/or JPG bytestreams and making a .heic file of them (like a burst series of photos) - but I suspect it just requires learning some more GPAC. It seems pretty versatile! Commented Apr 7, 2018 at 17:11
  • 1
    As a point of interest, you are not restricted to JPEG, PNG and TIFF images. FFmpeg supports other image formats. JPEG2000 worked out of the box when tested, for instance. Commented Apr 9, 2018 at 4:47
3

Install ImageMagick and use basic convert format to go from one format to another.

I know this is an old thread, but posting my two cents that in 2020 it is far easier to bulk convert images to HEIC nowadays than it was in the past.

The first step is to get ImageMagick and ExifTool installed via Homebrew like this:

brew install imagemagick exiftool

Once you have ImageMagick installed, converting to HEIC is as simple as this:

convert image.jpg image.heic

That’s it! ImageMagick converts files from one format to another based the file extension of the destination file. And all metadata from the source file is cleanly transferred from the old file to the new file by using ExifTool after the image conversion has happened.

So in this example just naming the destination file image.heic is enough to get an HEIC file generated from the source file image.jpg.

But since I had to bulk convert some directories filled with images, I wrote this simple Bash script that searches a directory for JPG, PNG and TIFF images and then runs them through ImageMagick and saves an HEIC file with the same filename in the same directory.

Just take this script and change /path/to/images to match your source directory and you are all set!

find -E '/path/to/images' -type f -iregex '.*\.(JPG|JPEG|PNG|TIF|TIFF)$' |\
  while read full_image_path
  do
    path_sans_extension="${full_image_path%.*}"
    convert "${full_image_path}" "${path_sans_extension}".heic
    exiftool -overwrite_original_in_place -tagsFromFile "${full_image_path}" "${path_sans_extension}".heic
  done
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .