Skip to content

Instantly share code, notes, and snippets.

@provegard
Last active December 21, 2015 15:28

Revisions

  1. provegard revised this gist Aug 24, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion HowToUse_Dll.cpp
    Original file line number Diff line number Diff line change
    @@ -56,7 +56,7 @@ int main (int argc, Char *argv[])
    //Initializing MediaInfo
    MediaInfo MI;

    MI.Option("ParseSpeed", "0");
    MI.Option(__T("ParseSpeed"), __T("0"));

    //Preparing to fill MediaInfo with a buffer
    MI.Open_Buffer_Init(F_Size, 0);
  2. provegard created this gist Aug 24, 2013.
    100 changes: 100 additions & 0 deletions HowToUse_Dll.cpp
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,100 @@
    /* Copyright (c) MediaArea.net SARL. All Rights Reserved.
    *
    * Use of this source code is governed by a BSD-style license that can
    * be found in the License.html file in the root of the source tree.
    */

    //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
    // Linux: g++ -o howtouse HowToUse_Dll.cpp -lmediainfo -lzen -ldl
    // Windows: cl /Fehowtouse.exe HowToUse_Dll.cpp
    //+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

    #ifdef MEDIAINFO_LIBRARY
    #include "MediaInfo/MediaInfo.h" //Staticly-loaded library (.lib or .a or .so)
    #define MediaInfoNameSpace MediaInfoLib;
    #else //MEDIAINFO_LIBRARY
    #include "MediaInfoDLL/MediaInfoDLL.h" //Dynamicly-loaded library (.dll or .so)
    #define MediaInfoNameSpace MediaInfoDLL;
    #endif //MEDIAINFO_LIBRARY
    #include <iostream>
    #include <iomanip>
    using namespace MediaInfoNameSpace;

    #ifdef __MINGW32__
    #ifdef _UNICODE
    #define _itot _itow
    #else //_UNICODE
    #define _itot itoa
    #endif //_UNICODE
    #endif //__MINGW32


    //***************************************************************************
    // By buffer example
    //***************************************************************************

    //---------------------------------------------------------------------------
    //Note: you can replace file operations by your own buffer management class
    #include <stdio.h>

    int main (int argc, Char *argv[])
    {
    //From: preparing an example file for reading
    FILE* F=fopen("test2.mov", "rb"); //You can use something else than a file
    if (F==0)
    return 1;

    //From: preparing a memory buffer for reading
    unsigned char* From_Buffer=new unsigned char[7*188]; //Note: you can do your own buffer
    size_t From_Buffer_Size; //The size of the read file buffer

    //From: retrieving file size
    fseek(F, 0, SEEK_END);
    long F_Size=ftell(F);
    fseek(F, 0, SEEK_SET);

    //Initializing MediaInfo
    MediaInfo MI;

    MI.Option("ParseSpeed", "0");

    //Preparing to fill MediaInfo with a buffer
    MI.Open_Buffer_Init(F_Size, 0);

    //The parsing loop
    int totalRead = 0;
    do
    {
    //Reading data somewhere, do what you want for this.
    From_Buffer_Size=fread(From_Buffer, 1, 7*188, F);
    totalRead += From_Buffer_Size;
    printf("Read %ld bytes.\n", From_Buffer_Size);

    //Sending the buffer to MediaInfo
    size_t Status=MI.Open_Buffer_Continue(From_Buffer, From_Buffer_Size);
    if (Status&0x08) //Bit3=Finished
    break;

    //Testing if there is a MediaInfo request to go elsewhere
    MediaInfo_int64u seekPos = MI.Open_Buffer_Continue_GoTo_Get();
    if (seekPos!=(MediaInfo_int64u)-1)
    {
    printf("Seeking to offset %lld.", seekPos);
    fseek(F, (long)seekPos, SEEK_SET); //Position the file
    MI.Open_Buffer_Init(F_Size, ftell(F)); //Informing MediaInfo we have seek
    }
    }
    while (From_Buffer_Size>0);
    printf("Done, read %d bytes in total.\n", totalRead);
    //Finalizing
    MI.Open_Buffer_Finalize(); //This is the end of the stream, MediaInfo must finnish some work

    //Get() example
    String To_Display=MI.Get(Stream_General, 0, __T("Format"));

    #ifdef _UNICODE
    std::wcout << To_Display << std::endl;
    #else
    std::cout << To_Display << std::endl;
    #endif
    }