设为首页 收藏本站
查看: 393|回复: 0

[经验分享] 在Linux上将视频转换成动态gif图片 (附:ffmpeg和ImageMagick安装方法)

[复制链接]

尚未签到

发表于 2016-3-29 08:45:58 | 显示全部楼层 |阅读模式
  虽然曾经被认为是过时的艺术形式,但动态GIF图片现在复苏了。如果你还没有留意到,不少在线分享和社交网络网站都开始支持动态GIF图片,例如,Tumblr,Flickr,Google+和Facebook的部分地方。由于在消费和共享上的容易,GIF的动画已经成为主流互联网文化的一部分了。
  
  所以,你们中的一些人会好奇怎样才能生成这样的动态GIF图片。已经有各种各样专门用来生成动态GIF图片的在线或离线工具。另一种选择是创建一副动态GIF图片时关闭现有的视频剪辑。在这个教程中,我会描述在Linux上如何将一段视频文件转换成一副动态GIF图片
  
  作为一个更有用的例子,让我展示如何将一个YouTube视频转换成一副动态GIF图片

 

第一步:下载YouTube视频
  
  首先,下载一个你想要转换的YouTube视频。你可以使用youtube-dl这个工具将YouTube视频保存为MP4文件。假设你把你最爱的YouTube视频保存为"funny.mp4"。(译注:对于墙内的同学,请无视YT吧,自行去好人楼主那里寻找一个MP4吧,;-})

 

第二步:从视频中解压视频帧
  
  接下来,在Linux系统上安装FFmpeg,我会用这个工具去解压从视频中解压出视频帧。
  
  下面的指令会解压出独立的视频帧,将它们保存为GIF图片。确保使用诸如("out%04d.gif")的输出文件格式。这样,独立的帧就被合适地命名并保存。

ffmpeg -t <时长> -ss <hh:mm:ss格式的开始位置> -i <视频文件> out%04d.gif
  
  例如,如果你想解压输入视频的视频帧,从第10秒开始,每5秒一帧,请运行下列命令。

$ ffmpeg -t 5 -ss 00:00:10 -i funny.mp4 out%04d.gif
  
  在完成FFmpeg之后,你会看到一组创建出来的GIF文件,它们被命名为"out[\d+].gif"。

 

第三步:合并视频帧进一副动态GIF
  
  下面这一步要合并单个的GIF文件成一副动态GIF图片。为此,你可以使用ImageMagick。
  
  首先,如果你还没有的话,在Linux系统上安装ImageMagick。

convert -delay <帧数>x<每秒帧数> -loop 0 out*gif <输出文件>
  
  在这个命令中,"-delay"是控制动态速度的选项。这个选项表示在显示下一帧画面前需要等待的秒数:帧数/每秒帧数 。"-loop 0"选项表示动画的无限次循环。如果你愿意,你可以指定"-loop N"让动画只重复N次。
  
  例如,为了生成一副每秒20帧和循环无数次的动态GIF图片,使用如下命令。

$ convert -delay 1x20 -loop 0 out*.gif animation.gif
 

第四步(可选):减少动态GIF的大小
  
  最后这一步(可选)是通过使用ImageMagick的GIF优化功能来减少生成的GIF文件的大小。
  
  使用下列命令去减少GIF大小。

convert -layers Optimize animation.gif animation_small.gif
  
  现在你已经准备好在你的社交网络上分享制作完成的GIF图片。下面是一副我从一个可爱的YouTube视频中生成的GIF样例图片。
  
  享受技术带来的乐趣吧!:-)
  
DSC0000.gif

  
  via: http://xmodulo.com/2013/11/convert-video-animated-gif-image-linux.html
  译者:KayGuoWhu 校对:wxy
  原文由 LCTT 原创翻译,Linux中国 荣誉推出
  原文地址:http://linux.cn/thread/12298/1/1/

 

1. 安装ffmpeg
  

Install FFmpeg in Ubuntu
  
  Either click this link or run this command in the terminal to install FFmpeg.

sudo apt-get install ffmpeg
 

Install FFmpeg in Fedora
  
  FFmpeg can be directly installed from the repos. Just run the following command.

su -c 'yum install ffmpeg'
 

Install FFmpeg in any Linux system from source
  
  This howto will be helpful to all the linuxers who either want to have a fully customized installation of FFmpeg or are having some trouble in installing the default package from the distro repos or want to try the latest release.
  
  First of all you will have to download the latest source from the main website. Now, untar it.

tar -xvjf ffmpeg-0.5.tar.bz2
 

Install FFmpeg with default options
  
  once you are done with this, in order to install FFmpeg with the default config and options run

./configure
  
  from within the FFmpeg source directory. When the configuration script finishes compile it by running make

make
  
  If the compile finishes without any errors run 'make install' as root to install FFmpeg

su -c 'make install'
 

Install FFmpeg with customized settings
  
  If you want to install FFmpeg by customizing some installation options then you can pass some special parameter while running configure script. Run the following command to find out various options available while running configure script.

./configure --help
  
  This will show you various options to customize the default installation. Most of the time the default installation will work for you but there is one option which most of us might need freqeuntly. It is
  
  --enable-libmp3lame: This one is a must if you want to work with mp3. Encoding mp3 won't be possible without it.
  
  Although in order to make this option work you will need lame installed. You will get the warning at the time of configuring it. This can be done by installing the library "libmp3lame". You can either install it directly from the repos.

sudo apt-get install libmp3lame0
  
  or, you can install libmp3lame directly from the source from their website.
  
  Once you are done with 'lame's' installation. this run configure again, if successful run 'make' and then 'make install ' as root.
  
  原文:http://linuxers.org/tutorial/how-install-ffmpeg-linux
  

2. 安装ImageMagick
  
  ImageMagick is a suite of command line utilities for image conversion and editing. As one of the most popular image editing software suite, ImageMagick can support almost all kinds of raster image types including GIF, JPEG, PDF, PNG, Postscript, SVG, and TIFF.

 

Install ImageMagick on Debian, Ubuntu or Linux Mint
  
  ImageMagick is included in a base repository of Debian-based systems. So simply use apt-get command.

sudo apt-get install imagemagick
 

Install ImageMagick on Fedora, CentOS or RHEL
  
  ImageMagick is also part of standard RedHat-based systems. Thus installation is straightforward with yum command.

sudo yum install ImageMagick
 

Install ImageMagick on OpenSUSE
  
  Installation of ImageMagick is straightforward on OpenSUSE with the use of zypper command.

sudo zypper install imagemagick
  
  原文:http://xmodulo.com/2013/03/how-to-save-youtube-videos-on-linux.html
  

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.iyunv.com/thread-196965-1-1.html 上篇帖子: 【转】11 个很少人知道但很有用的 Linux 命令 下篇帖子: Linux HugePage for MySQL Server(MySQL中大页的使用)
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表