英文:
How to create a MP4 video from scratch?
问题
我正在尝试使用Go编写一个将GIF转换为MP4的服务。
对于GIF,Go语言内置了一个名为"image/gif"的包,其中包含了解码GIF的工具。
但是并没有类似的包可以用于处理MP4文件。
因此,我考虑自己创建MP4文件。
在解码GIF之后,我可以访问其图像和参数,比如延迟时间。所以,如果我能找到一种"MP4文件模板"的方法,我可以利用这些信息来创建一个MP4文件,对吗?
英文:
I'm trying to write a service with Go that converts GIF to MP4.
For GIF there's a builtin package "image/gif" which contains tools for decoding a GIF.
But no such package exists for MP4.
So I'm considering creating the MP4 file myself.
After decoding a GIF, I have access to its images and parameters like delay, so if I figure out something like a "template for MP4 file", I can use these information to create one, right?
答案1
得分: 2
Mp4不是唯一的视频数据标准,现在有几十个被称为MPEG-4的标准。但是,如果你说的是.Mp4,大多数情况下指的是某种容器中的H.264编码。
正确实现H.264(以便像现成的解决方案一样快速和稳定)是非常困难的工作,需要高级计算机科学技能、专业的编程技能、对H.264相关标准的专业知识以及大量的时间。你可以在ITU网站上找到的草案有671页,并且引用了其他几个(或几十个?)标准。
还有一个坏消息:标准的草案并不是当前的标准,你需要购买它。
H.264实现的一些方面包括帧数据压缩、熵编码、纠错码、视频滤镜和色彩配置文件。这些都是非常复杂的事情。
那么为什么不尝试使用ffmpeg呢?
你可以使用"os/exec"包执行ffmpeg可执行文件:
out, err := exec.Command("ffmpeg", "-f", "gif", "-i", gifFileName, mp4FileName).Output()
或者尝试使用go的ffmpeg绑定库https://github.com/giorgisio/goav
使用现成的解决方案将节省你数年的工作时间
英文:
Mp4 is not the one universal standard of video data. It's dozens of standards called MPEG-4 now. But if you mean .Mp4 most times you mean H.264 in some container.
Proper implementation of H.264 (that will work as fast and as stable that ready-made solutions) is very hard work that requires advanced computer science skills, expert programming skills, expert knowledge of the H.264-related standards, and a lot of time. The draft that you can find on ITU site contains 671 pages and it's referenced to few (or dozens?) other standards.
And another bad news: draft of standard is not the current standard. You need to buy it.
Some of aspects of realization of H.264: frame data compression, entropy coding, code correction, video filters, color profiles. It's really complicated things, all of them.
So why not have try to use the ffmpeg?
You can execute ffmpeg executable with "os/exec" package:
out, err := exec.Command("ffmpeg", "-f", "gif", "-i", gifFileName, mp4FileName).Output()
Or even try use ffmpeg bindings for go https://github.com/giorgisio/goav
The use of ready-made solutions will save years of your work
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论