FFmpeg 可以用作库而不是独立程序吗?
我想向我正在编写的程序添加视频转换功能。 FFmpeg 执行此操作的命令行界面只是 ffmpeg -i InputFile OutputFile,但是有没有办法将其用作库,所以我可以执行类似 ffmpeg_convert(InputFile, OutputFile )?
我希望我不必直接使用 libavcodec,因为我想象它会比在格式之间转换的一行函数复杂得多。如果 FFmpeg 不能轻易地进行改造来做到这一点,是否有另一个基于它的库可以做到这一点?我听说过 libvlc,但这似乎只公开了视频播放 API,而不是视频转换。
I'd like to add video conversion capabilities to a program I'm writing. FFmpeg's command line interface for doing this is simply ffmpeg -i InputFile OutputFile
, but is there a way to make use of it as a library, so I can do something like ffmpeg_convert(InputFile, OutputFile)
?
I'm hoping I won't have to use libavcodec directly, as I imagine it will be far more complex than a one-line function to convert between formats. If FFmpeg can't be easily retrofitted to do this, is there perhaps another library based on it that does? I've heard of libvlc, but that seems to only expose a video playing API, not video conversion.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要 libavcodec 和 libavformat。 常见问题解答告诉您:
FFmpeg 文档指南可以在 ffmpeg.org/documentation.html 找到,包括 开发人员指南。我建议查看 libavformat/output-example.c 或 ffmpeg 命令行实用程序本身的源代码。
You need
libavcodec
andlibavformat
. The FAQ tells you:The FFmpeg documentation guide can be found at ffmpeg.org/documentation.html, including the Developer's guide. I suggest looking at
libavformat/output-example.c
or perhaps the source of theffmpeg
command line utility itself.如果您只想将 ffmpeg 作为函数而不是系统调用进行调用,则可以非常轻松地做到这一点。
在 ffmpeg.c 中,更改:
然后在调用 ffmpeg 函数时并传入一个模仿命令行的数组。为了使它更容易使用函数来创建 argc、argv 变量。
If you just wanted to make a call to ffmpeg as function rather than a system call, you can do that pretty easily.
In ffmpeg.c, change:
Then in your call the ffmpeg function and pass in an array that mimics the command line. To make it even easier use a function to create the argc, argv variables.
是的,您必须使用 libavcodec 和 libavformat。我认为你应该阅读 ffmpeg 源代码中的 ffplay.c 。我认为您从该文件开始会更容易。
Yes you have to use libavcodec and libavformat. I think you should read about ffplay.c inside ffmpeg source code. I think it would be easier for you to start with that file.