Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

corrupted HEIC tile when converting to JPEG

Tags:

c++

ffmpeg

heif

I'm having trouble converting a .HEIC image to a jpeg. The .HEIC file an image taken with an iphone running the latest ios public beta. I'm using the library nokia provided to parse the file and extract the image tiles from the .HEIC file, convert them to jpeg and glue them together using ffmpeg/montage.

There is a bit too much code to paste it all into this question so i put all of it in this github repo. Its pretty self explanatory and should be runnable with just a few dependencies. They are explained in the repo's README. This has all been done on osx btw.

The .HEIC files contains a 8x6 grid of images(tiles) and if you put them together you get the complete image. Simply put whatever image i input the 7th tile is corrupted as shown below and i really don't understand why. I've filed an issue with nokia, but the repo seems pretty dead and i don't really expect an answer there.

like image 488
Kimmeh Avatar asked Mar 08 '23 10:03

Kimmeh


1 Answers

There's a bug in the VPS/SPS/PPS parameter sets in the 7th tile. I have not tracked down if the issue lies in the actual file or in the HEIF parser, but there is a simple workaround in the meantime.

Refer to HevcImageFileReader::getItemDataWithDecoderParameters and observe how it prepends the parameter sets to the actual item data for each tile.

All you need to do is read the parameter sets for the first tile and reuse them for subsequent tiles instead of re-reading them. This will work around the corrupt parameters coming from the 7th tile. It appears safe to do this since this is a grid format and the requirement is that each tile be identical.

like image 91
Richard Kuo Avatar answered Mar 15 '23 03:03

Richard Kuo