kornelski / cavif-rs

AVIF image creator in pure Rust
https://lib.rs/cavif
BSD 3-Clause "New" or "Revised" License
570 stars 27 forks source link

Decoder "Failed to find a NULL terminator..." #29

Closed bat999 closed 3 years ago

bat999 commented 3 years ago

Hi

I have two programs...

~ $ cavif -V
cavif-rs 1.2.0

~ $ avifenc -V
Version: 0.9.1 (dav1d [dec]:185194b, aom [enc/dec]:v3.1.1, rav1e [enc]:0.5.0-alpha (p20210608))

I create two files...

~ $ cavif -o Cortina_CAVIF.avif Cortina.png

~ $ avifenc -c rav1e Cortina.png Cortina_AVIFENC.avif

SAMPLES.zip is attached.

Both of the avif files open OK with Chromium and Firefox browsers. But I can't decode the one made by cavif.

Please advise... Is there something wrong with cavif's en-coder or Is there something wrong with libavif's de-coder

Look here...

 ~ $ avifdec --info Cortina_CAVIF.avif
ERROR: Failed to decode image: BMFF parsing failed
Diagnostics:
 * Box[hdlr]: Failed to find a NULL terminator when reading a string

~ $ avifdec --info Cortina_AVIFENC.avif
Image decoded: Cortina_AVIFENC.avif
 * Resolution     : 424x283
 * Bit Depth      : 8
 * Format         : YUV444
 * Alpha          : Absent
 * Range          : Full
 * Color Primaries: 1
 * Transfer Char. : 13
 * Matrix Coeffs. : 6
 * ICC Profile    : Absent (0 bytes)
 * XMP Metadata   : Absent (0 bytes)
 * EXIF Metadata  : Absent (0 bytes)
 * Transformations: None
 * 1 timescales per second, 1.00 seconds (1 timescales), 1 frame
 * Frames:
   * Decoded frame [0] [pts 0.00 (0 timescales)] [duration 1.00 (1 timescales)]

SAMPLES.zip

kornelski commented 3 years ago

Ooof, so it needed an empty string for a "creator" field, which apparently is some leftover from classic MacOS quicktime. This chunk already had 12 NUL bytes, but that wasn't enough zeros for it. I've added 13th zero there, and it worked. HEIF/ISOBMFF is such a weird format :/

bat999 commented 3 years ago

Tested OK thanks. :-)

I ran...

~ $ cargo install cavif --force

~ $ cavif -V
cavif-rs 1.2.0

~ $ cavif Cortina.png; avifdec -i Cortina.avif
Cortina.avif: 38KB (37422B color, 0B alpha, 238B HEIF)
Image decoded: Cortina.avif
 * Resolution     : 424x283
 * Bit Depth      : 8
 * Format         : YUV444
 * Alpha          : Absent
 * Range          : Full
 * Color Primaries: 1
 * Transfer Char. : 13
 * Matrix Coeffs. : 1
 * ICC Profile    : Absent (0 bytes)
 * XMP Metadata   : Absent (0 bytes)
 * EXIF Metadata  : Absent (0 bytes)
 * Transformations: None
 * 1 timescales per second, 1.00 seconds (1 timescales), 1 frame
 * Frames:
   * Decoded frame [0] [pts 0.00 (0 timescales)] [duration 1.00 (1 timescales)]