技術ノート
公開

gifを動画(WebM形式)に変換

gifを背景透過のまま高品質で動画(WebM形式)に変換

GIFWebMFFmpegUbuntu
実行環境OSUbuntu 24.04.4 LTSPlatformWSL2fastfetch2.62.1
実行環境の詳細
Fastfetch output for the Ubuntu 24.04.4 LTS WSL2 environment
OS
Ubuntu 24.04.4 LTS
Platform
WSL2
Host
Windows Subsystem for Linux - Ubuntu-24.04 (2.6.2.0)
Kernel
Linux 6.6.87.2-microsoft-standard-WSL2
Shell
zsh 5.9
Terminal
Windows Terminal
CPU
AMD Ryzen 7 5700G
GPU
AMD Radeon(TM) Graphics [Integrated]
Memory
31.03 GiB
Disk
1006.85 GiB - ext4
Arch
x86_64 / amd64
WM
WSLg 1.0.71 (Wayland)
Display
3440x1440, 60 Hz
Local IP
192.168.0.216/24
Locale
C.UTF-8
fastfetch
2.62.1
ffmpeg -i input.gif -c:v libvpx-vp9 -pix_fmt yuva420p -lossless 1 output.webm

curl -OL https://i0.hdslb.com/bfs/new_dyn/10820d15c8c5e97f786d952cf1990645104349118.gif
ffmpeg -i 10820d15c8c5e97f786d952cf1990645104349118.gif -c:v libvpx-vp9 -pix_fmt yuva420p -lossless 1 10820d15c8c5e97f786d952cf1990645104349118.webm
表示↑
<video controls autoplay loop muted playsinline>
  <source
    src="/10820d15c8c5e97f786d952cf1990645104349118.webm"
    type="video/webm"
  />
</video>

メモ

ffmpeg -hide_banner -h muxer=webm
出力
Muxer webm [WebM]:
    Common extensions: webm.
    Mime type: video/webm.
    Default video codec: vp9.
    Default audio codec: opus.
    Default subtitle codec: webvtt.
matroska/webm muxer AVOptions:
  -reserve_index_space <int>        E.......... reserve a given amount of space (in bytes) at the beginning of the file for the index (cues) (from 0 to INT_MAX) (default 0)
  -cues_to_front     <boolean>    E.......... move Cues (the index) to the front by shifting data if necessary (default false)
  -cluster_size_limit <int>        E.......... store at most the provided amount of bytes in a cluster (from -1 to INT_MAX) (default -1)
  -cluster_time_limit <int64>      E.......... store at most the provided number of milliseconds in a cluster (from -1 to I64_MAX) (default -1)
  -dash              <boolean>    E.......... create a WebM file conforming to WebM DASH specification (default false)
  -dash_track_number <int>        E.......... track number for the DASH stream (from 1 to INT_MAX) (default 1)
  -live              <boolean>    E.......... write files assuming it is a live stream (default false)
  -allow_raw_vfw     <boolean>    E.......... allow raw VFW mode (default false)
  -flipped_raw_rgb   <boolean>    E.......... store raw RGB bitmaps in VFW mode in bottom-up mode (default false)
  -write_crc32       <boolean>    E.......... write a CRC32 element inside every Level 1 element (default true)
  -default_mode      <int>        E.......... control how a track's FlagDefault is inferred (from 0 to 2) (default passthrough)
     infer           0            E.......... for each track type, mark each track of disposition default as default; if none exists, mark the first track as default
     infer_no_subs   1            E.......... for each track type, mark each track of disposition default as default; for audio and video: if none exists, mark the first track as default
     passthrough     2            E.......... use the disposition flag as-is


Exiting with exit code 0

ffmpeg -hide_banner -encoders | grep -ni vp9
出力
133: V....D libvpx-vp9           libvpx VP9 (codec vp9)
134: V....D vp9_vaapi            VP9 (VAAPI) (codec vp9)
135: V..... vp9_qsv              VP9 video (Intel Quick Sync Video acceleration) (codec vp9)

ffmpeg -hide_banner -h encoder=libvpx-vp9
出力
Encoder libvpx-vp9 [libvpx VP9]:
    General capabilities: dr1 delay threads
    Threading capabilities: other
    Supported pixel formats: yuv420p yuva420p yuv422p yuv440p yuv444p yuv420p10le yuv422p10le yuv440p10le yuv444p10le yuv420p12le yuv422p12le yuv440p12le yuv444p12le gbrp gbrp10le gbrp12le
libvpx-vp9 encoder AVOptions:
  -lag-in-frames     <int>        E..V....... Number of frames to look ahead for alternate reference frame selection (from -1 to INT_MAX) (default -1)
  -arnr-maxframes    <int>        E..V....... altref noise reduction max frame count (from -1 to INT_MAX) (default -1)
  -arnr-strength     <int>        E..V....... altref noise reduction filter strength (from -1 to INT_MAX) (default -1)
  -arnr-type         <int>        E..V....... altref noise reduction filter type (from -1 to INT_MAX) (default -1)
     backward        1            E..V.......
     forward         2            E..V.......
     centered        3            E..V.......
  -tune              <int>        E..V....... Tune the encoding to a specific scenario (from -1 to INT_MAX) (default -1)
     psnr            0            E..V.......
     ssim            1            E..V.......
  -deadline          <int>        E..V....... Time to spend encoding, in microseconds. (from INT_MIN to INT_MAX) (default good)
     best            0            E..V.......
     good            1000000      E..V.......
     realtime        1            E..V.......
  -error-resilient   <flags>      E..V....... Error resilience configuration (default 0)
     default                      E..V....... Improve resiliency against losses of whole frames
     partitions                   E..V....... The frame partitions are independently decodable by the bool decoder, meaning that partitions can be decoded even though earlier partitions have been lost. Note that intra prediction is still done over the partition boundary.
  -max-intra-rate    <int>        E..V....... Maximum I-frame bitrate (pct) 0=unlimited (from -1 to INT_MAX) (default -1)
  -crf               <int>        E..V....... Select the quality for constant quality mode (from -1 to 63) (default -1)
  -static-thresh     <int>        E..V....... A change threshold on blocks below which they will be skipped by the encoder (from 0 to INT_MAX) (default 0)
  -drop-threshold    <int>        E..V....... Frame drop threshold (from INT_MIN to INT_MAX) (default 0)
  -noise-sensitivity <int>        E..V....... Noise sensitivity (from 0 to 4) (default 0)
  -undershoot-pct    <int>        E..V....... Datarate undershoot (min) target (%) (from -1 to 100) (default -1)
  -overshoot-pct     <int>        E..V....... Datarate overshoot (max) target (%) (from -1 to 1000) (default -1)
  -ts-parameters     <dictionary> E..V....... Temporal scaling configuration using a :-separated list of key=value parameters
  -auto-alt-ref      <int>        E..V....... Enable use of alternate reference frames (2-pass only) (from -1 to 6) (default -1)
  -cpu-used          <int>        E..V....... Quality/Speed ratio modifier (from -8 to 8) (default 1)
  -lossless          <int>        E..V....... Lossless mode (from -1 to 1) (default -1)
  -tile-columns      <int>        E..V....... Number of tile columns to use, log2 (from -1 to 6) (default -1)
  -tile-rows         <int>        E..V....... Number of tile rows to use, log2 (from -1 to 2) (default -1)
  -frame-parallel    <boolean>    E..V....... Enable frame parallel decodability features (default auto)
  -aq-mode           <int>        E..V....... adaptive quantization mode (from -1 to 4) (default -1)
     none            0            E..V....... Aq not used
     variance        1            E..V....... Variance based Aq
     complexity      2            E..V....... Complexity based Aq
     cyclic          3            E..V....... Cyclic Refresh Aq
     equator360      4            E..V....... 360 video Aq
  -level             <float>      E..V....... Specify level (from -1 to 6.2) (default -1)
  -row-mt            <boolean>    E..V....... Row based multi-threading (default auto)
  -tune-content      <int>        E..V....... Tune content type (from -1 to 2) (default -1)
     default         0            E..V....... Regular video content
     screen          1            E..V....... Screen capture content
     film            2            E..V....... Film content; improves grain retention
  -corpus-complexity <int>        E..V....... corpus vbr complexity midpoint (from -1 to 10000) (default -1)
  -enable-tpl        <boolean>    E..V....... Enable temporal dependency model (default auto)
  -min-gf-interval   <int>        E..V....... Minimum golden/alternate reference frame interval (from -1 to INT_MAX) (default -1)
  -speed             <int>        E..V.......  (from -16 to 16) (default 1)
  -quality           <int>        E..V.......  (from INT_MIN to INT_MAX) (default good)
     best            0            E..V.......
     good            1000000      E..V.......
     realtime        1            E..V.......
  -vp8flags          <flags>      E..V.......  (default 0)
     error_resilient              E..V....... enable error resilience
     altref                       E..V....... enable use of alternate reference frames (VP8/2-pass only)
  -arnr_max_frames   <int>        E..V....... altref noise reduction max frame count (from 0 to 15) (default 0)
  -arnr_strength     <int>        E..V....... altref noise reduction filter strength (from 0 to 6) (default 3)
  -arnr_type         <int>        E..V....... altref noise reduction filter type (from 1 to 3) (default 3)
  -rc_lookahead      <int>        E..V....... Number of frames to look ahead for alternate reference frame selection (from 0 to 25) (default 25)
  -sharpness         <int>        E..V....... Increase sharpness at the expense of lower PSNR (from -1 to 7) (default -1)


Exiting with exit code 0

ffmpeg -hide_banner -pix_fmts | grep -ni yuva420p
出力
42:IO... yuva420p               4             20      8-8-8-8
89:IO... yuva420p9be            4             22      9-9-9-9
90:IO... yuva420p9le            4             22      9-9-9-9
95:IO... yuva420p10be           4             25      10-10-10-10
96:IO... yuva420p10le           4             25      10-10-10-10
101:IO... yuva420p16be           4             40      16-16-16-16
102:IO... yuva420p16le           4             40      16-16-16-16

ffmpeg -i input.gif -c:v libvpx-vp9 -pix_fmt yuva420p -lossless 1 output.webm