Search code examples
cffmpegmpegogglibavcodec

Can FFmpeg be used as a library, instead of a standalone program?


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.


Solution

  • You need libavcodec and libavformat. The FAQ tells you:

    4.1 Are there examples illustrating how to use the FFmpeg libraries, particularly libavcodec and libavformat?

    Yes. Check the doc/examples directory in the source repository, also available online at: https://github.com/FFmpeg/FFmpeg/tree/master/doc/examples.

    Examples are also installed by default, usually in $PREFIX/share/ffmpeg/examples.

    Also you may read the Developers Guide of the FFmpeg documentation. Alternatively, examine the source code for one of the many open source projects that already incorporate FFmpeg at (projects.html).

    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 the ffmpeg command line utility itself.