ffmpegwebp

ffmpeg: Convert video file to separate WebP images


I want to covert the input video file to a set of WebP images: one for each frame.

I'm trying to use the common video-to-images pattern:

ffmpeg -i input.mp4 -f image2 frame%04d.webp

But all I get is a single animated file frame0001.webp

Is there any param to force ffmpeg to generate a separate file for each frame?


Solution

  • I think this does what you want:

    ffmpeg -i YOURINPUT -codec libwebp frame-%03d.webp
    

    You can get a list of all coders that relate to WEBP (along with the key to the symbols at the top) like this:

    ffmpeg -v warning -codecs | grep -Ei "=|webp"
    
     D..... = Decoding supported
     .E.... = Encoding supported
     ..V... = Video codec
     ..A... = Audio codec
     ..S... = Subtitle codec
     ..D... = Data codec
     ..T... = Attachment codec
     ...I.. = Intra frame-only codec
     ....L. = Lossy compression
     .....S = Lossless compression
    
     DEVILS webp                 WebP (encoders: libwebp_anim libwebp)
    

    That tells you that there are two encoders, namely libwebp_anim and libwebp, so that's how I decided to use libwebp because it doesn't do animation, unlike libwebp_anim.

    Once you know the encoder you want to use, you can find the options it supports like this:

    ffmpeg -v warning -h encoder=libwebp  
       
    Encoder libwebp [libwebp WebP image]:
        General capabilities: dr1 
        Threading capabilities: none
        Supported pixel formats: bgra yuv420p yuva420p
    libwebp encoder AVOptions:
      -lossless          <int>        E..V....... Use lossless mode (from 0 to 1) (default 0)
      -preset            <int>        E..V....... Configuration preset (from -1 to 5) (default none)
         none            -1           E..V....... do not use a preset
         default         0            E..V....... default preset
         picture         1            E..V....... digital picture, like portrait, inner shot
         photo           2            E..V....... outdoor photograph, with natural lighting
         drawing         3            E..V....... hand or line drawing, with high-contrast details
         icon            4            E..V....... small-sized colorful images
         text            5            E..V....... text-like
      -cr_threshold      <int>        E..V....... Conditional replenishment threshold (from 0 to INT_MAX) (default 0)
      -cr_size           <int>        E..V....... Conditional replenishment block size (from 0 to 256) (default 16)
      -quality           <float>      E..V....... Quality (from 0 to 100) (default 75)