LoadFFMpegLibraries fails for a specific path

RVMedia support and discussion (components for displaying and controlling IP cameras, webcams, video conferencing, video chats, recording audio and video files)
Post Reply
panlab_mf
Posts: 35
Joined: Wed Feb 06, 2019 9:55 am

LoadFFMpegLibraries fails for a specific path

Post by panlab_mf »

Hi all,

Im trying to load the ffmpegs x64 libraries from a sub folder of my application, for instance, '.\bin64\', using the LoadFFMpegLibraries(). But it fails what ever I do the call.

I'm using the "ffmpeg" demo project. So, if I copy the dlls into the same direcoty as the final executable, the default mechanism to load the dlls works properly. But if I move the dll's into a subfolder and them call to LoadFFMpegLibraries('.\bin64\'), it fails for no reason.

[spoiler]
unit MainFrm;
//...
initialization
FFMpegDirectory := '.\bin32\';
LoadFFMpegLibraries(FFMpegDirectory);
end.
[/spoiler]

Have you any sugestion/idea why is this happening?

Thanks.
panlab_mf
Posts: 35
Joined: Wed Feb 06, 2019 9:55 am

Re: LoadFFMpegLibraries fails for a specific path

Post by panlab_mf »

Hi all,

After a few research about DLL loading. I've tryed to help the default mechanism to find out the dll into the subfolder, changing the PATH enviroemtn variablelike this:

[spoiler]initialization
if not init_ffmpeg then
begin
sEnvPath := GetEnvironmentVariable('PATH');
sEnvPath := '.\bin32\' + ';' + sEnvPath;
SetEnvironmentVariable('PATH', PWideChar(sEnvPath));
LoadFFMpegLibraries('');
end;
end.
[/spoiler]

This way I'm able to load all the dlls from a subfolder. Now my goal is to avoid to use this trick by understanding the dependencies between these DLLs. May be changing the order...

[spoiler]
dll_av_format := GetFFMpegLib(av_format, MaxVersion_av_format);
dll_av_codec := GetFFMpegLib(av_codec, MaxVersion_av_codec);
dll_av_util := GetFFMpegLib(av_util, MaxVersion_av_util);
dll_sws_lib := GetFFMpegLib(sws_lib, MaxVersion_sws_lib);
dll_swr_lib := GetFFMpegLib(swr_lib, MaxVersion_swr_lib);
[/spoiler]

we can finally load the dlls in one single step without having to modify the PATH.

Best regards,
panlab_mf
Posts: 35
Joined: Wed Feb 06, 2019 9:55 am

Re: LoadFFMpegLibraries fails for a specific path

Post by panlab_mf »

Hi all

Using "Dependency Walker" v2.2.6000 that's what I've found:
  • avcodec-58:
    • swresample-3
    • avutil-56
  • avformat-58:
    • avcodec-58
    • avutil-56
  • avutil-56:
  • swresample-3:
    • avutil-56
  • swscale-3:
    • avutil-56
So, it seems than the right order to load the dlls could be:
  • avutil-56,
  • swscale-3,
  • swresample-3,
  • avcodec-58,
  • avformat-58.
The hard thing is how we can find the right module name (GetFFMpegLib) if we cannot load it because of the dependencies.

Best regards,
Sergey Tkachenko
Site Admin
Posts: 17557
Joined: Sat Aug 27, 2005 10:28 am
Contact:

Re: LoadFFMpegLibraries fails for a specific path

Post by Sergey Tkachenko »

I think the best solution would be switching the current directory to the FFmpeg directory, load libraries, then switch the current directory back.
Post Reply