美文网首页spring boot
无意间发现一个好用的视频转换gif图片的开源框架

无意间发现一个好用的视频转换gif图片的开源框架

作者: 恒宇少年 | 来源:发表于2020-08-05 09:56 被阅读0次

    知识改变命运,撸码使我快乐,2020继续游走在开源界

    点赞再看,养成习惯

    给我来个Star吧,点击了解下基于SpringBoot的组件化接口服务落地解决方案

    推荐阅读

    简介

    Gifify是一款工具类的开源框架,可以将任何视频文件转换为优化的动画GIF。

    有些时候我们需要将视频转换为动画GIF图,可以更生动形象的描述我们想要说明的事物以及框架的使用方式,它对于程序员来说是一个不可或缺的工具之一。

    环境支持

    在安装Gifify之前首先我们需要先安装它所需要的运行环境:

    • Node.jsbrew install node
    • FFmpegbrew install ffmpeg
    • ImageMagickbrew install imagemagick
    • giflossybrew install giflossy

    安装

    可以通过npm直接安装Gifify,如下所示:

    npm install -g gifify
    

    命令行参数

    下面是Gifify所支持的命令行参数列表。

    ➜  ~ gifify -h
    Usage: gifify [options] [file]
    
    Options:
      -V, --version           output the version number
      --colors <n>            Number of colors, up to 255, defaults to 80 (default: 80)
      --compress <n>          Compression (quality) level, from 0 (no compression) to 100, defaults to 40 (default: 40)
      --from <position>       Start position, hh:mm:ss or seconds, defaults to 0
      --fps <n>               Frames Per Second, defaults to 10 (default: 10)
      -o, --output <file>     Output file, defaults to stdout
      --resize <W:H>          Resize output, use -1 when specifying only width or height. `350:100`, `400:-1`, `-1:200`
      --reverse               Reverses movie
      --speed <n>             Movie speed, defaults to 1 (default: 1)
      --subtitles <filepath>  Subtitle filepath to burn to the GIF
      --text <string>         Add some text at the bottom of the movie
      --to <position>         End position, hh:mm:ss or seconds, defaults to end of movie
      --no-loop               Will show every frame once without looping
      -h, --help              output usage information
    

    视频转换为GIF

    我使用Mac自带的屏幕录制软件QuickTime Player录制了一个测试视频,根据上面的命令行参数来看如果我们不做一些其他的自定义,只添加-o、--output输出的gif文件名即可,如下所示:

    ➜ gifify 屏幕录制2020-08-05\ 上午8.58.01.mov --output example.gif
    Generating GIF, please wait...
    

    当我们看到提示信息Generating GIF, please wait...时,说明已经开始转换了,因为视频文件的大小有差异,所以转换所需要的时间也所有不同。

    自动创建的example.gif文件与转换的视频文件在同一目录下。

    image

    GIF截取

    如果你只需要转换视频中的一个时间段,我们可以通过指定--from--to参数来配置,如下所示:

    ➜ gifify 屏幕录制2020-08-05\ 上午8.58.01.mov --output example.gif --from 00:00:10 --to 00:00:15
    

    GIF压缩

    Gifify默认压缩比例为40%,压缩后的Gif图可能会比较模糊,我们可以通过--compress参数来修改压缩比例,0表示无压缩,取值范围为0~100,如下所示:

    ➜ gifify 屏幕录制2020-08-05\ 上午8.58.01.mov --output example.gif --from 00:00:10 --to 00:00:12 --compress 0
    

    总结

    Gifify还有很多隐藏的功能,比如在GIF图片上添加文字描述,缩放视频比例,反转视频等功能,赶快去发掘它的隐藏功能吧。

    作者个人 博客
    使用开源框架 ApiBoot 助你成为Api接口服务架构师

    相关文章

      网友评论

        本文标题:无意间发现一个好用的视频转换gif图片的开源框架

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