Creating JPEG file from .heic files #901
Comments
|
Hey, have same issue No chance to get how to convert from heif to jpg? |
|
You guys miss an important point: MP4Box can only manipulate the container. JPEG and HEVC are different codecs so you'll need to re-encode. The easiest way to do the conversion is to use the Nokia tool to decode your HEIF content to RAW -formats to be precised). Then use a JPEG encoder to perform the RAW -> JPEG conversion. |
|
@rbouqueau It seemed like the below invocation of MP4Box is supposed to extract the raw tiles (in HEVC format) from the HEIC container, but as you can see they don't seem to be valid HEVC when I get them out even though they do work properly for the same test file when extracting them with the nokia library. Am I misunderstanding the MP4Box options or what exactly gpac supports? Thanks
|
|
@ericcj I don't know if it is supposed to be HEVC compliant but I could reproduce your issue:
|
|
The extraction code is very generic. It takes the bytes of the item and outputs them. This works well when the resource is stored as is in the item. For HEIC, it's a bit tricky. The payload of the item is only the VCL NALU (IIRC), the SPS/PPS should be in an item property (hvcC). It's highly likely that the extraction does not extract the hvcC content because the notion of item property did not exist when we first wrote the item extraction code. Also the start code vs. length fields and maybe the emulation prevention bytes processing have to be added. |
|
Apparently, MP4Box does not support HEIF/HEIC as generated by iOS 11 devices. Here are samples I took with my iPhone 7+ myself, useful for tests and debug. https://avi.alkalay.net/clipboard/HEIF-iOS-11.zip Zip file contains videos, regular photos, photos with depth and photo bursts. I'm particularly interested in MP4Box support for iOS 11 HEIF tags and metadata. This is what I get with GPAC 0.6.1 and 0.7.1 on Fedora Linux:
|
|
This is now fixed on git, thanks for the report |
|
@jeanlf is it possible that this commit while fixing it for most cases missed an edge case? I've got a file (IMG_5915.HEIC attached in the zip) that when i do:
Then if I extract all of these:
I get 51 files, item1.hevc through item51.hevc, for every extraction i get this warning: Then if i continue, and convert these to PNG with ffmpeg nearly all of them convert successfully, but 2 fail: Although, it seems that image 48 is the bottom right corner of the image (because of the "letterboxing" visible). And that image 50 is some sort of thumbnail stored in an extra tile. So perhaps image 49 and image 51 are some other superfluous information? metadata stored in a "tile"? |
|
item 49 and item 51 are not HEVC. 49 is a 'grid' item. 51 is EXIF metadata. |
|
@cconcolato Awesome! thanks for the help! So i guess maybe there would be some way of grabbing the EXIF metadata from 51 and applying it to the final image once the tiles are recombined? |
|
Ok. for anyone wanting to do this, here's an example cobbled together python script it had a TON of dependancies but it will convert HEIC files to PNG with a single command: Its late now, so just dropping the file here, but i'll put it on github as a separate project tomorrow. |
|
Very useful discussion and command line and script samples. What about the inverse: conversion of a lossless DNG or lossless JPEG 2000 file, containing EXIF and XMP metadata, to lossless HEVC still into a HEIF container with metadata ? I first tried PNG to lossless HEVC but stopped with a x265 error message related to wrong image dimensions. Anyone knows how to do this ? |
|
@cconcolato Can we discuss this tile 49 (grid item) a bit further? I've been trying to follow the way it is extracted in the Nokia implementation:
If i understand correctly, this code takes the first 8 bits and discards it. Then takes the next 8 bits, and treats is as a flag to check if we are using either 32 bit or 16 bit ints to describe the image size. Then takes the next 16 bits, 8 bits at a time to get the number of rows and columns, finally getting the image dimensions. The file attached above has the following binary representation:
So from this I get: The rows is clearly incorrect, and so is the columns, the actual image was made up of 8 columns and 6 rows. The width and height are also incorrect, the image is 4096px by 3072px. Is it possible that MP4Box did not properly extract this data when i did: My python implementation of extracting this data for reference:
Logfile of dump in question:
|
|
Actually @cconcolato @jeanlf the output of dumping the grid is literally just the first 8 bytes of the HEIC file, is this correct?
|
|
@deweydb you're right, there is a bug in the item extraction this is the location info (in the
It says that the item is at offset this is the location info of item 49:
If we interpret it the same way it looks like the data is at offset 0 and length 8. That's why we extract the header of the file, but that's incorrect. The fourth byte, which is different for these two items, is the If I look at the 8 bytes at the start of the
meaning
which looks a lot better. I'll look into the extraction bug in mp4box. |
|
I'm glad to see this is evolving and bugs are getting destroyed. Let me know if you need more sample files. |
|
@aureliendavid thank you for solving that mystery, I was really pulling my hair out yesterday trying to figure out what i was doing wrong! Interesting about the height and width, I must also have a bug somewhere in my reconstruction code because i should not have ended up with 4096px by 3072px because this is wrong. I just looked for some sample photos from an iPhone 7 and they are all 4032x3024 as you suggested. |
|
@deweydb you can test with the latest commit, the grid should be extracted properly now |
|
@aureliendavid awesome! seems fixed! so far getting correct values in all my tests! As a side question that also touches on what @avibrazil mentioned above, would it be possible with mp4box to do the reverse of -dump-item. i.e. Can i take a folder with all the tiles, grid item, thumbnail, and exif item, and recombine them into an heic with mp4box? Actually nevermind, there is another way to do what i was asking: |
|
I am using these two converters and it works just fine. |
|
@deweydb Did you upload your python script to github or is the attached version the latest? |
|
FYI in case it can help some of you: for a customer that contacted the GPAC Licensing professional services, we have developed an HEIC to JPEG conversion tool that is very fast. |
Thanks for reporting your issue. Please make sure these boxes are checked before submitting your issue - thank you!
Detailed guidelines: http://gpac.io/2013/07/16/how-to-file-a-bug-properly/
Hi there,
I see on the GPAC post that there is an easy way to create HEIF files using mp4box... Apologies if this is clearly stated somewhere, but is there a way to get jpeg's from .heic files using mp4box? Any documentation/references would be greatly appreciated.
Thanks!
-Ahmed
The text was updated successfully, but these errors were encountered: