视频转 webp 动图

作者: GeorgeMR | 来源:发表于2019-07-01 13:32 被阅读3次

    视频转 webp 动图

    准备工作

    编译支持 webp 的 ffmpeg 库

    1. 下载 webp 源码进行编译

      ./configure --prefix=${INSTALL_DIR} \
                          --enable-libwebpmux \
                          --enable-libwebpdemux \ 
                          --enable-libwebpdecoder \ 
                          --enable-libwebpextras \
                          --enable-swap-16bit-csp \ 
                          --enable-static \
                          --disable-shared
      make clean
      make -j4
      make install
      

      INSTALL_DIR 为 webp 编译安装的路径

      编译出的文件:

      • bin: 编译出的可执行文件
      • include : 头文件
      • lib : 需要依赖的库

    参照谷歌关于 webp 编译的文档:Compiling the Utilities

    1. 编译 ffmpeg (支持webp encoder)

      FFMPEG_FLAGS="--prefix=${INSTALL_DIR} \
           --disable-shared \
           --enable-static \
           --disable-symver \
           --disable-doc \
           --disable-ffplay \
           --disable-ffprobe \
           --disable-ffserver \
           --enable-pthreads \
           --enable-libx264 \
           --enable-libfdk-aac \
           --enable-libwebp \
           --enable-version3  \
           --enable-gpl \
           --enable-nonfree \
           --enable-protocol=file "
           
      ./configure $FFMPEG_FLAGS --extra-cflags="-I${INSTALL_ROOT}/webp/include" --extra-ldflags="-L${INSTALL_ROOT}/webp/lib"
      

      起始没有指定 webp 的 pkgconfig,出现了如下错误:

      ERROR: libwebp not found using pkg-config
      

      ffmpeg 官方提示可以直接指定 webp 库的方式来绕过 pkgconfig:

      If you don't have pkg-config, you can use the configure option
      --pkg-config=true but
      you will have to provide the library yourself (--extra-libs=-lwebp or similar).
      

      这种方式在 Mac 上可以成功编译,但 linux 环境确导致另外一个问题:

      error while loading shared libraries: libwebp.so.7: cannot open shared object file: No such file or directory
      

      找不到webp对应库,所以只能指定pkgconfig

      export PKG_CONFIG_PATH="${INSTALL_ROOT}/webp/lib/pkgconfig"
      

      到此就成功编译出支持 webp 编码的 ffmpg 库
      修改:由于之前编译的 webp 库为动态库,导致找不到 pkg-config, 以及一些不必要的修改。在编译 webp 时指定 ''--enable-static \ --disable-shared'' , 编译为静态库.

    利用 ffmpeg 制作 webp 动图

    ffmpeg 命令:

    ffmpeg -ss 00:00:00 -t 2 -i input.mp4 -vcodec libwebp -lossless 0 -q:v 75 -loop 0 -an -vsync 0 -vf scale=318:568,fps=5 out.webp
    

    制作 animated webp 命令参数说明:

    • -lossless 无损压缩规范。默认值:0(1为可逆压缩)
    • compression_level 指定压缩比率。0~6,数值越高,高压缩编码所需的时间越长
    • qscale(q:v) 指定压缩质量。
    • preset 预置,默认为 default
      • none 不使用任何预设
      • default 自动指定
      • picture 肖像照片
      • photo 风景照片
      • drawing 绘制
      • icon 多彩与小尺寸
      • text 文本 字符居中
    • loop 动画循环 0-无限

    调整生成动图大小和fps,可以使用 scale、fps 参数

    相关文章

      网友评论

        本文标题:视频转 webp 动图

        本文链接:https://www.haomeiwen.com/subject/zacgcctx.html