Repository navigation
media: decode HEIC photos with libheif so grid images aren't cropped - #272
Conversation
|
1 potential issue found:
All CI checks passed on
Select any unchecked box below to run or rerun that agent. Found issues (1)Full resultsIndent Review Agent
|
| // iPhone photos are HEIF grids of tiles. The ffmpeg CLI only decodes the | ||
| // first tile, while libheif assembles the full image. | ||
| var stderr bytes.Buffer | ||
| cmd := exec.CommandContext(ctx, "heif-dec", "--quiet", inputPath, outputPath) |
There was a problem hiding this comment.
🟡 Bug · Converted JPEG now leaks source EXIF/GPS metadata
The old ffmpeg mjpeg output had no EXIF. libheif's JPEG encoder copies the HEIC's EXIF block into the output, resetting Orientation but keeping GPS coordinates and device model, so photos sent to LINE now include location metadata. A malformed EXIF offset also makes heif-dec exit non-zero, which fails the conversion where ffmpeg used to succeed. Strip the EXIF segment from the result, or retry without metadata on failure.
Found by Indent Review Agent
highesttt
left a comment
There was a problem hiding this comment.
Looks good, just one thing a HEIC file can contain a broken EXIF block (although incredibly unlikely), this new converter tries to copy it and aborts when invalid, which rejects the send. If you think it's worth fixing, you can do so. Otherwise code looks good to merge
Photos sent from an iPhone show up on LINE as a blurry, zoomed-in corner of the picture.
iPhone HEICs are grids of 512x512 tiles.
convertHEICToJPEGranffmpeg -i x.heic -frames:v 1 … mjpeg, and ffmpeg (7.1.5 and 8.0.1) exposes the grid only as a "Tile Grid" stream group and encodes the first tile stream.-map 0:g:0doesn't change that. The bridge log shows the cropped size:The conversion now uses libheif's
heif-dec, which assembles the grid. If a file holds several top-level images, heif-dec numbers its outputs, and the first one is used. heif-dec also copies the photo's EXIF and XMP (location, device model), which ffmpeg didn't, so every APP1 segment is stripped from the JPEG. The color profile stays. libheif's JPEG writer gives up on a broken EXIF block (and heif-dec still exits 0), so in that case the photo is decoded to PNG, which skips the block, and re-encoded as JPEG in Go. The Dockerfile addslibheif-tools. The megabridge runtime image needslibheif-examplesbefore this rolls out there (beeper/megabridge#88), or HEIC sends will fail.Before / after
convertHEICToJPEGat main vs this branch, same file:Not yet checked with a live send to LINE.
Tag
@indentto continue the conversation here.