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

知识改变命运,撸码使我快乐,2020继续游走在开源界<br/>
点赞再看,养成习惯<br/>
给我来个Star吧, 点击了解下基于SpringBoot的组件化接口服务落地解决方案

推荐阅读

简介

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

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

环境支持

在安装Gifify以前首先咱们须要先安装它所须要的运行环境:node

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

安装

能够经过npm直接安装Gifify,以下所示:git

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文件名便可,以下所示:github

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

当咱们看到提示信息Generating GIF, please wait...时,说明已经开始转换了,由于视频文件的大小有差别,因此转换所须要的时间也全部不一样。spring

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

image

GIF截取

若是你只须要转换视频中的一个时间段,咱们能够经过指定--from--to参数来配置,以下所示:npm

➜ 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,以下所示:api

➜ 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接口服务架构师
相关文章
相关标签/搜索