locked
'DLL Initialization Failed' when loading FFmpeg DLLs in Win8 app RRS feed

  • Question

  • Hello. I'm a first-time poster and relatively new to WinRT programming. My goal (for now) is to implement a simple video player built on FFmpeg (rather than Windows Media Foundation, for WTV / MPEG-2 / etc. support) as a Windows 8 app. I understand that this probably won't pass App Store certification, but I'd like to try it anyway.

    I've managed to compile, link and run sample code which uses FFmpeg with Visual C++ 2012 as a 'console application' with no special support from the Win32 API. I'm currently attempting to bring this sample code into a Direct2D (XAML) template application. Here's what I've done:

    • created a new Direct2D (XAML) project in MSVS 2012, named 'ffmpeg-metro' 
    • downloaded the most recent 32-bit build of FFmpeg shared DLLs, import libraries and header files
    • added the include path, the import library (.lib) path, and all dependencies to the project configuration
    • included each 32-bit DLL within the project, setting each 'Content' property to 'true' to ensure they're copied into the app correctly
    • added the following code to App.xaml.cpp:
    extern "C" {
    #include <libavformat/avformat.h> }
    
    /* ... */
    
    App::App() {
      InitializeComponent();
      Suspending += ref new SuspendingEventHandler(this, &App::OnSuspending);
      av_register_all(); /* initialize FFmpeg codecs - symbol comes from avcodec-54.dll */
    }

    The project builds correctly, but at runtime when debugging, the application fails to activate. Here's the debug output provided by MSVS 2012:

    'ffmpeg-metro.exe' (Win32): Loaded 'C:\Users\lucas\code\ffmpeg-metro\x64\Debug\ffmpeg-metro\AppX\ffmpeg-metro.exe'. Symbols loaded.
    'ffmpeg-metro.exe' (Win32): Loaded 'C:\Windows\System32\ntdll.dll'. Symbols loaded.
    'ffmpeg-metro.exe' (Win32): Loaded 'C:\Windows\System32\kernel32.dll'. Symbols loaded.
    'ffmpeg-metro.exe' (Win32): Loaded 'C:\Windows\System32\KernelBase.dll'. Symbols loaded.
    'ffmpeg-metro.exe' (Win32): Loaded 'C:\Windows\System32\d2d1.dll'. Symbols loaded.
    'ffmpeg-metro.exe' (Win32): Loaded 'C:\Windows\System32\d3d11.dll'. Symbols loaded.
    'ffmpeg-metro.exe' (Win32): Loaded 'C:\Windows\System32\dxgi.dll'. Symbols loaded.
    'ffmpeg-metro.exe' (Win32): Loaded 'C:\Windows\System32\ole32.dll'. Symbols loaded.
    'ffmpeg-metro.exe' (Win32): Loaded 'C:\Windows\System32\DWrite.dll'. Symbols loaded.
    'ffmpeg-metro.exe' (Win32): Loaded 'C:\Users\lucas\code\ffmpeg-metro\x64\Debug\ffmpeg-metro\AppX\avformat-54.dll'. Module was built without symbols.
    'ffmpeg-metro.exe' (Win32): Loaded 'C:\Program Files\WindowsApps\Microsoft.VCLibs.110.00.Debug_11.0.50727.1_x64__8wekyb3d8bbwe\vccorlib110d.dll'. Symbols loaded.
    'ffmpeg-metro.exe' (Win32): Loaded 'C:\Program Files\WindowsApps\Microsoft.VCLibs.110.00.Debug_11.0.50727.1_x64__8wekyb3d8bbwe\msvcp110d.dll'. Symbols loaded.
    'ffmpeg-metro.exe' (Win32): Loaded 'C:\Program Files\WindowsApps\Microsoft.VCLibs.110.00.Debug_11.0.50727.1_x64__8wekyb3d8bbwe\msvcr110d.dll'. Symbols loaded.
    'ffmpeg-metro.exe' (Win32): Loaded 'C:\Windows\System32\combase.dll'. Symbols loaded.
    'ffmpeg-metro.exe' (Win32): Loaded 'C:\Windows\System32\msvcrt.dll'. Symbols loaded.
    'ffmpeg-metro.exe' (Win32): Loaded 'C:\Windows\System32\user32.dll'. Symbols loaded.
    'ffmpeg-metro.exe' (Win32): Loaded 'C:\Windows\System32\gdi32.dll'. Symbols loaded.
    'ffmpeg-metro.exe' (Win32): Loaded 'C:\Windows\System32\rpcrt4.dll'. Symbols loaded.
    'ffmpeg-metro.exe' (Win32): Loaded 'C:\Windows\System32\sechost.dll'. Symbols loaded.
    'ffmpeg-metro.exe' (Win32): Loaded 'C:\Windows\System32\advapi32.dll'. Symbols loaded.
    'ffmpeg-metro.exe' (Win32): Loaded 'C:\Windows\System32\avifil32.dll'. Symbols loaded.
    'ffmpeg-metro.exe' (Win32): Loaded 'C:\Windows\System32\winmm.dll'. Symbols loaded.
    'ffmpeg-metro.exe' (Win32): Loaded 'C:\Windows\System32\ws2_32.dll'. Symbols loaded.
    'ffmpeg-metro.exe' (Win32): Loaded 'C:\Users\lucas\code\ffmpeg-metro\x64\Debug\ffmpeg-metro\AppX\avcodec-54.dll'. Module was built without symbols.
    'ffmpeg-metro.exe' (Win32): Loaded 'C:\Users\lucas\code\ffmpeg-metro\x64\Debug\ffmpeg-metro\AppX\avutil-52.dll'. Module was built without symbols.
    'ffmpeg-metro.exe' (Win32): Loaded 'C:\Windows\System32\oleaut32.dll'. Symbols loaded.
    'ffmpeg-metro.exe' (Win32): Loaded 'C:\Windows\System32\msacm32.dll'. Symbols loaded.
    'ffmpeg-metro.exe' (Win32): Loaded 'C:\Windows\System32\msvfw32.dll'. Symbols loaded.
    'ffmpeg-metro.exe' (Win32): Loaded 'C:\Windows\System32\winmmbase.dll'. Symbols loaded.
    'ffmpeg-metro.exe' (Win32): Loaded 'C:\Windows\System32\nsi.dll'. Symbols loaded.
    'ffmpeg-metro.exe' (Win32): Loaded 'C:\Windows\System32\shell32.dll'. Symbols loaded.
    'ffmpeg-metro.exe' (Win32): Loaded 'C:\Windows\System32\comctl32.dll'. Symbols loaded.
    'ffmpeg-metro.exe' (Win32): Loaded 'C:\Windows\System32\shlwapi.dll'. Symbols loaded.
    'ffmpeg-metro.exe' (Win32): Loaded 'C:\Windows\System32\imm32.dll'. Symbols loaded.
    'ffmpeg-metro.exe' (Win32): Loaded 'C:\Windows\System32\msctf.dll'. Symbols loaded.
    The thread 0x1a80 has exited with code -1073741502 (0xc0000142).
    The program '[9252] ffmpeg-metro.exe' has exited with code -1073741502 (0xc0000142) 'DLL Initialization Failed'.
    

    The DLLs are being copied in an accessible location, and Dependency Walker shows that they do not require any unusual dependencies: advapi32.dll, kernel32.dll, msvcrt.dll, user32.dll and avutil-52.dll, which is also correctly copied into the app directory and depends on the same system libraries. (I'd post a screenshot but my account isn't verified yet.)

    Furthermore, replacing the call to av_register_all() with the following code shows no errors in loading the DLL, and the application behaves normally:

    HINSTANCE hnd = LoadPackagedLibrary(L"avcodec-54.dll", 0);
    OutputDebugStringW(GetLastError().ToString()->Data()); /* outputs "0" */

    I'm probably missing something important. Can anyone help me out?

    Wednesday, October 31, 2012 7:17 PM

Answers

  • Hi,

    Generally speaking, we need migrate Win32 codes to Windows Runtime components. Because of some Win32 API cannot be used in C++/CX. If your DLL contains these API, you can not pass the WACK test and cannot be summited to Windows Store.

    You can follow this sample codes to play a different encoding video files.
    Media extensions sample
    http://code.msdn.microsoft.com/windowsapps/Media-extensions-sample-7b466096

    Best regards,
    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by lucas-j Friday, November 2, 2012 6:26 AM
    Thursday, November 1, 2012 7:43 AM

All replies

  • Hi,

    Generally speaking, we need migrate Win32 codes to Windows Runtime components. Because of some Win32 API cannot be used in C++/CX. If your DLL contains these API, you can not pass the WACK test and cannot be summited to Windows Store.

    You can follow this sample codes to play a different encoding video files.
    Media extensions sample
    http://code.msdn.microsoft.com/windowsapps/Media-extensions-sample-7b466096

    Best regards,
    Jesse


    Jesse Jiang [MSFT]
    MSDN Community Support | Feedback to us

    • Marked as answer by lucas-j Friday, November 2, 2012 6:26 AM
    Thursday, November 1, 2012 7:43 AM
  • Thanks Mr. Jiang. Although I'm still unsure why exactly the FFmpeg DLLs fail to load outright, I've checked the app with WACK and apparently there's far too many disallowed Win32 API symbols to work around, and trying to handle the various complexities of media playback myself would've been out of the scope of this project anyway.

    I was unaware Media Foundation allowed custom extensions. I'm currently trying to integrate libmpeg2 / liba52dec into this sample Windows 8 app, and I am having much more success. Thanks again for the suggestion.

    Friday, November 2, 2012 9:50 AM
  • Lucas--I've been looking at building a similar app--have you made any progress using libmpeg2 that you could share?

    Ric Lewis

    Friday, January 18, 2013 11:08 PM
  • Hi Ric,

    I've finally managed to get some free time to clean up and publish my integration of libmpeg2. It's available on Github: github.com/lucas-j/libmpeg2-winrt

    Hopefully this helps.

    • Proposed as answer by slyi Tuesday, March 19, 2013 3:23 PM
    Tuesday, March 19, 2013 3:08 AM