lovell / avif-cli

Command line utility to convert images to AVIF
Apache License 2.0
175 stars 18 forks source link

mp4 to animated avif #5

Open dylannirvana opened 3 years ago

dylannirvana commented 3 years ago

Can this be used to convert an mp4 to an animated avif?

lovell commented 3 years ago

No, sadly not, sorry.

I would be interested to know a bit more about the context/scenario where using an AVIF image sequence might be considered more appropriate or a better fit than using an mp4 video.

dylannirvana commented 3 years ago

Here you go https://www.bmi.com/award-shows/r-and-b-hip-hop-2021/ [https://www.bmi.com/images/news/2021/RB-HH_2021_16-9news.jpg]https://www.bmi.com/award-shows/r-and-b-hip-hop-2021/ 2021 BMI R&B/Hip-Hop Awardshttps://www.bmi.com/award-shows/r-and-b-hip-hop-2021/ BMI is excited to celebrate the exceptional songwriters, producers and music publishers whose music has changed the game and raised the bar for R&B and Hip-Hop. It’s our thrill to reveal the winners of the Song of the Year, Songwriter of the Year, Producer of the Year and Publisher of the Year, and to salute our top producers and recognize the 35 most-performed R&B/Hip-Hop songs of the past year. www.bmi.com

Icarian Records & Publishing Tel +1 917-582-9369 Website https://dylannirvana.comhttps://dylannirvana.com/ SoundCloud https://soundcloud.com/dylannirvana Disco Library https://library.dylannirvana.com/

Dylan Nirvana. “Like Elvis Costello. Morrissey meets Motörhead” - The Village Voice.


From: Lovell Fuller @.> Sent: Friday, October 8, 2021 10:12 AM To: lovell/avif-cli @.> Cc: Dylan Nirvana @.>; Author @.> Subject: Re: [lovell/avif-cli] mp4 to animated avif (#5)

No, sadly not, sorry.

I would be interested to know a bit more about the context/scenario where using an AVIF image sequence might be considered more appropriate or a better fit than using an mp4 video.

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHubhttps://github.com/lovell/avif-cli/issues/5#issuecomment-938676185, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AB7VTGPO7MJAMHVQIAEYCB3UF334LANCNFSM5FTTYOXQ. Triage notifications on the go with GitHub Mobile for iOShttps://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Androidhttps://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

dylannirvana commented 3 years ago

Our use case (I didn't invent it, but I did inherit it) is taking mp4s and converting them to animated WEBP and animated AVIF. Because of the file size and quality advantages of AVIF, this workflow makes sense, considering how commonplace the animated GIF is.

I am looking to accomplish this in a script so that it can be done programmatically. The ffmpeg library has code for WEBP https://ffmpeg.org/ffmpeg-all.html#libwebp but not for AVIF, which is expected to experience widespread adoption. The only service I found that does this is https://ezgif.com/video-to-avif. And I have contacted them to see if they would make their code available. But it seems like you are very close to this yourself.

lovell commented 3 years ago

Thanks for the example. I don't see any mp4 files on the BMI awards page, am I missing something?

dylannirvana commented 3 years ago

The opening animation is a AVIF/WEBP depending on your browser. It is in a <picture> tag, with a source set to choose media type and max-width.

lovell commented 3 years ago

Ah, thanks, I opened the page in Chrome and see it now.

I'm still unsure why an embedded <video autoplay loop muted ...> wouldn't be preferable here. It will probably have a smaller file size, be more CPU efficient (especially on mobile), be more accessible, be more respectful of people's autoplay settings etc.

ghost commented 2 years ago

https://codelabs.developers.google.com/codelabs/avif#5

It's possible.

coreyward commented 1 year ago

To chime in about a use case: browsers do not have native support for alpha transparency in H264/MP4 videos, so more esoteric formats are required (HEVC/H265 encoded Quicktime for Safari, and VP9 encoded WebM for everyone else). Since H265 requires licensing and x265 (the HEVC version of the massively popular freeware library called x264) does not support alpha transparency, options for producing well-optimized versions of alpha-channel .mov files for Safari are limited.

In these situations, a small animated AVIF image can be a better tradeoff, even though it's not going to benefit from hardware-accelerated playback or have built-in playback controls.

lovell commented 1 year ago

@coreyward seethru used to be a solution to the alpha transparency problem, but I'm unsure if it's still suitable.

ThatOneCalculator commented 1 year ago

Any chance that we could also see APNG to animated AVIF?

lovell commented 1 year ago

Animated AVIF (sequence) output is dependent on https://github.com/strukturag/libheif/issues/377

Animated APNG input is dependent on https://github.com/randy408/libspng/issues/4

Both are then dependent on the subsequent exposure of these features in libvips and sharp.

gustawdaniel commented 1 month ago

It is a little offtiopc but I want to make if helpful for people that also working with animated avif and found this issue.

This library don't support animated avif. I tried to convert gif to avif.

Current state

npx avif --input cat-jump.gif --output avif-cat-jump.avif

dont work. Gives static image.

https://ezgif.com

works

magick convert

works for some formats but not avif

ffmpeg -i cat-jump.gif -c:v av1_nvenc -preset fast output.avif

it end with invalid file

 feh output.avif                                               
feh WARNING: output.avif - Does not look like an image (magic bytes missing)

or

fileinfo output.avif 
Error in findFileFormatStream: truncated file
Leptonica Error in pixReadHeader: unknown format in file: output.avif
Error in writeImageFileInfo: failure to read header of output.avif

but if we split it on 2 steps and convert gif -> mp4 -> avif, then it works

ffmpeg -hwaccel nvdec -i cat-jump.gif -c:v h264_nvenc -preset fast -an output.mp4
ffmpeg -i output.mp4 -c:v libaom-av1 -cpu-used 8 output.avif
mediainfo output.avif                                       
General
Complete name                            : output.avif
Format                                   : avis
Codec ID                                 : avis (avis/avif/msf1/iso8/mif1/miaf/MA1B)
File size                                : 103 KiB

Video
ID                                       : 1
Format                                   : AV1
Format/Info                              : AOMedia Video 1
Codec ID                                 : av01
Width                                    : 640 pixels
Height                                   : 358 pixels
Display aspect ratio                     : 16:9
Color space                              : YUV
Bit depth                                : 8 bits
Color range                              : Limited
Matrix coefficients                      : BT.470 System B/G

Image
ID                                       : 1
Format                                   : AV1
Format/Info                              : AOMedia Video 1
Format profile                           : Main@L2.1
Codec ID                                 : av01
Width                                    : 640 pixels
Height                                   : 358 pixels
Display aspect ratio                     : 16:9
Color space                              : YUV
Chroma subsampling                       : 4:2:0
Bit depth                                : 8 bits
Stream size                              : 131 KiB
Color range                              : Limited
Matrix coefficients                      : BT.470 System B/G
Codec configuration box                  : av1C+av1C

I attaching gif on which I tested it.

Thanks to this approach I was able to compress from 700 to 100 K

du -h cat-jump.gif output.mp4 output.avif 
704K    cat-jump.gif
716K    output.mp4
104K    output.avif

cat-jump