将动画GIF转换为linux服务器上的视频,同时保持帧速率 [英] convert animated gif to video on linux server while preserving frame rate

查看:463
本文介绍了将动画GIF转换为linux服务器上的视频,同时保持帧速率的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在linux服务器上以编程方式将动画GIF转换为视频(例如h264 @ mp4)?



我需要这个来处理用户生成的内容,作为几种定义的视频格式输出;因此可能的是,用户可能想要处理动画GIF文件。我已经有一套工作的PHP脚本,可以使用avconv将视频文件转码为特定格式(如vpx @ webm和h264 @ mp4,缩放到特定的分辨率),但是以前我需要视频输入。



通常的方法似乎是提取gif的框架,然后对其进行编码,如

  convert file。 gif文件%03d.png 
avconv -i文件%03d.png file.mp4

但是,这会丢弃由gif文件中的暂停信息确定的帧速率。可以使用-r定义一个帧速率到avconv,但是




  • 这不符合帧之间的暂停,因为它们可以不同第一帧100ms暂停,第二帧250ms暂停,第三帧100ms暂停,...)

  • 作为输入来自用户,它甚至可能会有所不同,因为一些gif可能有5fps和其他30fps



我注意到,avconv本身能够处理gif,因此可能会尊重正确的暂停,但是当我做在如何将GIF转换为Mp4是有可能的? a>)

  avconv -i file.gif -r 30 file.mp4 

avconv只会采用gif的第一帧,而至少会将视频文件检测到:


$ b $时间:00:00:00.04,开始:0.000000,比特率:N / A
流#0.0:视频:gif,pal8,640x480,25 tbn

(例如gif'file.gif'有15个帧,每个都有100ms pause => 1.5s持续时间,循环)




  • 我缺少什么?有什么问题吗?

  • 这个用例可能有更好的工具吗?

  • 什么是大网站,例如9gag用于将上传的GIF转码为视频?


解决方案

另一个Avconv错误(YAAB) / h2>

ffmpeg 有更好的GIF解复用支持(和改进的GIF编码)。我建议您从 c> ccon> 中获取 ffmpeg (来自FFmpeg的真实数据;不是来自Libav的旧charlatan)。 静态构建很容易,或者您当然可以

示例



  ffmpeg -i in.gif -c:v libx264 -pix_fmt yuv420p -movflags + faststart out.mp4 

查看 FFmpeg Wiki:H.264编码指南了解更多示例。


how do I convert an animated gif to a video (e.g. h264@mp4) programmatically on a linux server?

I need this to process user generated content which should be output as several defined video formats; therefore its possible, that users may want to process animated gif files. I already have a set of working php scripts to transcode videofiles to specific formats (like vpx@webm and h264@mp4, scaled to specific resolutions) using avconv, but herefore I need video input.

Usual ways seem to be to extract the frames of the gif and then encode it, like

convert file.gif file%03d.png 
avconv -i file%03d.png file.mp4

But this discards the frame rate, determined by the pause-informations within the gif-file. Its possible to define a framerate to avconv with -r, but

  • this does not respect the pause between frames, as they can differ (like 1st frame 100ms pause, 2nd frame 250ms pause, 3rd frame 100ms pause, ...)
  • as the input comes from users, it may even vary, as some gifs may have 5fps and others 30fps

I noticed that avconv is able to process gifs by itself and therefore may respect the correct pauses, but when I do (like similarily described in How to convert GIF to Mp4 is it possible?)

avconv -i file.gif -r 30 file.mp4

avconv will only take the first frame of the gif, while it detects the file at least as video:

Duration: 00:00:00.04, start: 0.000000, bitrate: N/A
  Stream #0.0: Video: gif, pal8, 640x480, 25 tbn

(example gif 'file.gif' has 15 frames, each with 100ms pause => 1.5s duration, looping)

  • What am I missing? Whats going wrong?
  • Are there probably better tools for this use case?
  • What are big sites like e.g. 9gag using to transcode uploaded gifs to video?

解决方案

Yet Another Avconv Bug (YAAB)

ffmpeg has better GIF demuxing support (and improved GIF encoding). I recommend ditching avconv and getting ffmpeg (the real one from FFmpeg; not the old charlatan from Libav). A static build is easy, or you can of course compile.

Example

ffmpeg -i in.gif -c:v libx264 -pix_fmt yuv420p -movflags +faststart out.mp4

See the FFmpeg Wiki: H.264 Encoding Guide for more examples.

这篇关于将动画GIF转换为linux服务器上的视频,同时保持帧速率的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆