Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for detecting avif files #160

Closed
wants to merge 1 commit into from

Conversation

vansante
Copy link
Contributor

I took a stab at implementing this. Let me know if it needs more work 😃

@coveralls
Copy link

Coverage Status

Coverage remained the same at 97.059% when pulling 7e437d6 on vansante:avif into c4c6791 on gabriel-vasile:master.

Copy link
Owner

@gabriel-vasile gabriel-vasile left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, sorry for the late response.
It seems like the sample image in this PR is a HEIF and not AVIF:

bash> file --mime avif.avif
image/heif; charset=binary

I was able to convert it to AVIF with:

bash> mv avif.avif heif.heif # move to .heif because convert uses extension to detect source file format.
bash> convert heif.heif avif.avif

@@ -42,6 +42,14 @@ var (
Xpm = prefix([]byte{0x2F, 0x2A, 0x20, 0x58, 0x50, 0x4D, 0x20, 0x2A, 0x2F})
)

func Avif(raw []byte, limit uint32) bool {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AVIF format is using the FTYP container format so you can use the existing ftyp function to create the detector. Like it's done for other FTYP formats in ftyp.go. The index where avif should be searched for is 8:12, not 20:24.

Also, it seems like image/avif should be returned for avif (single image) and avis (image sequence): reference

@vansante
Copy link
Contributor Author

vansante commented Jul 12, 2021

Hey @gabriel-vasile,

I pulled the sample image from this page, which is supposed to be a list of sample AVIF images used by netflix. (I used this one I believe).

I did find some more avif samples here which do show the ftyp you describe here:

# xxd ~/Downloads/fox.profile0.10bpc.yuv420.monochrome.odd-height.avif | head
00000000: 0000 0020 6674 7970 6176 6966 0000 0000  ... ftypavif....
00000010: 6176 6966 6d69 6631 6d69 6166 4d41 3142  avifmif1miafMA1B
00000020: 0000 011b 6d65 7461 0000 0000 0000 0048  ....meta.......H

vs the netflix one:

# xxd ~/mimetype/testdata/avif.avif  | head 
00000000: 0000 001c 6674 7970 6d69 6631 0000 0000  ....ftypmif1....
00000010: 6d69 6631 6176 6966 6d69 6166 0001 8a01  mif1avifmiaf....
00000020: 6d64 6174 0000 0000 0000 0000 0a0b 0000  mdat............

So I am a bit confused now 😕

@gabriel-vasile
Copy link
Owner

gabriel-vasile commented Jul 13, 2021

This is tricky.
It seems like those images are created by a new encoder Netflix is working on. It's weird they use the .avif extension but the file has the HEIF signature.
This needs more investigation to see if the Netflix images are HEIF or AVIF. Please let me know if you find any clues.

some references:
https://netflixtechblog.com/introducing-svt-av1-a-scalable-open-source-av1-framework-c726cce3103a
https://netflixtechblog.com/svt-av1-an-open-source-av1-encoder-and-decoder-ad295d9b5ca2

@gabriel-vasile
Copy link
Owner

gabriel-vasile commented Jul 15, 2021

Considering ftypmif1 is not recommended for avif and both github.com/file/file and github.com/apache/tika consider ftypmif1 as heif, I think we should do the same.
Also, the license here claims the images belong to Netflix so we must follow some rules (give credit, include original license) in order to use them. I think it's easier to swap the test image with another one.
Let me know if I can help you or if anything is unclear.

@gabriel-vasile
Copy link
Owner

Closing this in favor of #210.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants