Using ffMPEG on Windows with only the DLL's?

2019-02-16 02:53发布

问题:

What I actually want is to store frames of a video into a char array, using ffMPEG.
Constraint is to use only MSVC. Not allowed to use the Windows building tweak due to maintainability issues.

So considered using the shared build to accomplish the task. It consists of only DLL's. No lib files, so I tried loading one of the DLL's using HINSTANCE hInstLibrary = LoadLibrary("avcodec-54.dll"); and it works. But I couldn't find the interfaces of this DLL published anywhere. Could anyone help with this? How do I know which functions of the DLL I can call and what parameters I can pass it so that I can get the video frames?

回答1:

Use the public interface of ffmpeg from

ffmpegdir/include/libavcodec/
ffmpegdir/include/libavformat/
etc.

for example, to open a file for reading, use avformat_open_input from ffmpegdir/include/libavformat/avformat.h

AVFormatContext * ctx= NULL;
int err = avformat_open_input(&ctx, file_name, NULL, NULL);

You can get the latest builds of ffmpeg from http://ffmpeg.zeranoe.com/builds/

Public header files can be found in dev builds (http://ffmpeg.zeranoe.com/builds/win32/dev/).

UPD: Here is a working example (no additional static linking)

#include "stdafx.h"
#include <windows.h>
#include <libavformat/avformat.h>

typedef int (__cdecl *__avformat_open_input)(AVFormatContext **, const char *, AVInputFormat *, AVDictionary **);
typedef void (__cdecl *__av_register_all)(void);

int _tmain(int argc, _TCHAR* argv[])
{
    const char * ffp = "f:\\Projects\\Temp\\testFFMPEG\\Debug\\avformat-54.dll";
    HINSTANCE hinstLib = LoadLibraryA(ffp);
    __avformat_open_input __avformat_open_input_proc  = (__avformat_open_input)GetProcAddress(hinstLib, "avformat_open_input");

    __av_register_all __av_register_all_proc = (__av_register_all)GetProcAddress(hinstLib, "av_register_all");
    __av_register_all_proc();

    ::AVFormatContext * ctx = NULL;
    int err = __avformat_open_input_proc(&ctx, "g:\\Media\\The Sneezing Baby Panda.flv", NULL, NULL);
    return 0;
  }