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

mp4 to animated avif #5

Closed
dylannirvana opened this issue Oct 8, 2021 · 14 comments
Closed

mp4 to animated avif #5

dylannirvana opened this issue Oct 8, 2021 · 14 comments
Labels
question Further information is requested

Comments

@dylannirvana
Copy link

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

@lovell
Copy link
Owner

lovell commented Oct 8, 2021

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.

@lovell lovell added the question Further information is requested label Oct 8, 2021
@dylannirvana
Copy link
Author

dylannirvana commented Oct 8, 2021 via email

@dylannirvana
Copy link
Author

dylannirvana commented Oct 13, 2021

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
Copy link
Owner

lovell commented Oct 13, 2021

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

@dylannirvana
Copy link
Author

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
Copy link
Owner

lovell commented Oct 13, 2021

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
Copy link

ghost commented Dec 3, 2021

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

It's possible.

@coreyward
Copy link

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
Copy link
Owner

lovell commented Nov 14, 2022

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

@ThatOneCalculator
Copy link

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

@lovell
Copy link
Owner

lovell commented Mar 16, 2023

Animated AVIF (sequence) output is dependent on strukturag/libheif#377

Animated APNG input is dependent on randy408/libspng#4

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

@gustawdaniel
Copy link

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

  • gif to webm -> gives green screen
  • gif to webp -> works
  • gif to apng -> gives green screen
  • gif to avif -> gives static image
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                           : [email protected]
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

@oep42

This comment was marked as off-topic.

@lovell
Copy link
Owner

lovell commented Nov 14, 2024

Closing as this issue is attracting LLM slop. Please see the issues linked to in #5 (comment)

@lovell lovell closed this as completed Nov 14, 2024
Repository owner locked and limited conversation to collaborators Nov 14, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

6 participants