0

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?

Community
  • 1
  • 1
Nav
  • 19,885
  • 27
  • 92
  • 135
  • A related page for using the dev builds: http://stackoverflow.com/questions/11701635/use-ffmpeg-in-visual-studio. Believe me, it's a lot easier to write a program with the answer in this link than in the answer below, because the answer below necessitates loading a DLL function and using it as functionname_proc – Nav Nov 09 '12 at 06:17

1 Answers1

3

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;
  }
pogorskiy
  • 4,705
  • 1
  • 22
  • 21
  • Thanks. As of now, I'm getting an `unresolved external symbol` error for `avformat_open_input`. Is your code meant to include the `lib` files too? Because I was trying to get the task accomplished purely with the ffmpeg DLL's of the shared build (wouldn't mind knowing how to do it with the dev builds either. I was running into some errors when I tried with the dev builds) – Nav Nov 07 '12 at 08:34
  • Typically use a static library (ffmpeg\lib\libavformat.dll.a) to access the dynamic runtime libraries. If for some reason it's impossible, try to use 'GetProcAddress(hInstLibrary, "avformat_open_input")' function, as shown here http://msdn.microsoft.com/en-us/library/windows/desktop/ms686944(v=vs.85).aspx – pogorskiy Nov 07 '12 at 08:45
  • The unresolved external symbol error I was getting was in the line I had used GetProcAddress. I'm using the inttypes.h file downloaded from http://code.google.com/p/msinttypes/downloads/list because common.h needs it. Even when I include the libs, I get this `Error 1 error LNK2019: unresolved external symbol "void __cdecl av_register_all(void)" (?av_register_all@@YAXXZ) referenced in function _main F:\Projects\VisualStudio\ffmpegTestProgram\ffmpegTestProgram\main.obj` – Nav Nov 07 '12 at 09:03
  • Tried your program (after removing `stdafx`, converting `_TCHAR` to `char` and `_tmain` to `main`). It built successfully. Thank you so very much! :) I just hope I'd be able to use the API's to get the rgb values into a char array, as I originally wanted. – Nav Nov 07 '12 at 09:21