0

I am trying to read frames from a network stream using libvlc and then apply some processing on these frames using opencv. This is the code that I am using to retrieve frames:

struct ctx
{
    IplImage* image;
    HANDLE mutex;
    uchar*    pixels;
};

void *lock(void *data, void**p_pixels)
{
    struct ctx *ctx = (struct ctx*)data;
    WaitForSingleObject(ctx->mutex, INFINITE);
    *p_pixels = ctx->pixels; 
    return NULL;

}
void display(void *data, void *id)
{
    (void) data;
    assert(id == NULL);
}
void unlock(void *data, void *id, void *const *p_pixels){
    struct ctx *ctx = (struct ctx*)data;
    // VLC just rendered the video, but we can also render stuff 
    uchar *pixels = (uchar*)*p_pixels;
    cvShowImage("image", ctx->image);
    ReleaseMutex(ctx->mutex);
    assert(id == NULL); // picture identifier, not needed here 
}

int main()
{
    cvNamedWindow("image", CV_WINDOW_AUTOSIZE);
    libvlc_media_t* media = NULL;
    libvlc_media_player_t* mediaPlayer = NULL;
    //char const* vlc_argv[] = {"--plugin-path", "C:\\Users\\Oscar\\Documents\\libvlc\\vlc-1.1.4"};
    libvlc_instance_t* instance = libvlc_new(0,NULL);
    mediaPlayer = libvlc_media_player_new(instance);
    media = libvlc_media_new_location(instance, "rtsp://134.202.84.79:554/user=a&password=abcdef&channel=6&stream=0.sdp/");

    struct ctx* context = ( struct ctx* )malloc( sizeof( *context ) );
    context->mutex = CreateMutex(NULL, FALSE,NULL);
    //context->image = cvCreateImage(cvSize(libvlc_video_get_height(mediaPlayer), libvlc_video_get_width(mediaPlayer)), IPL_DEPTH_8U, 4);

    context->image = cvCreateImage(cvSize(640,480), IPL_DEPTH_8U, 4);
    context->pixels = (unsigned char *)context->image->imageData;

    libvlc_media_player_set_media( mediaPlayer, media);
    libvlc_video_set_callbacks(mediaPlayer, lock, unlock, display, context);
    libvlc_video_set_format(mediaPlayer, "RV32", 640, 480, 640*4);
    libvlc_media_player_play(mediaPlayer);


    while(true)
    {
        if (waitKey(30)==27)
        {
            break;
        }
    }
    return 0;
}

The problem is that this works fine when working in debug mode but when I switch to release mode, it says:

The procedure entry point cvCreateImage could not be located in the dynamic link library libvlc.dll.

I also tried changing the linker optimization flags but the problem is still here.

2 Answers 2

0

I just had a similar problem with glut (my application trying to find a glut-procedure in libVLC.dll).

While I don't know what causes this problem, I was able to resolve it in the following way:

instead of using the .lib files that came with VLC, I followed these steps on how to generate a lib from a dll file.

Using this lib solved the problem for me, even though I don't know why it would occur in the first place.

0

I seem to have fixed it. In another post about VS 2008 compile issues (in debug everything works great. Switch over and build everything in Release mode and it crashes on the line). I noticed that they had been adjusting the /OPT linker flag from /OPT:REF to /OPT:NOREF and it seemed to fix a different issue that they were having.

  1. Open the project's Property Pages dialog box. For details, see Settings> Visual C++ Project Properties.
  2. Select the Linker folder.
  3. Select the Command Line property page.
  4. Enter the option in Additional Options: /OPT:NOREF

Microsoft docs:

REF | NOREF /OPT:REF eliminates functions and/or data that are never referenced while > /OPT:NOREF keeps functions and/or data that are never referenced.

LINK removes unreferenced packaged functions by default. An object contains packaged functions (COMDATs) if it has been compiled with the /Gy option. This optimization is called transitive COMDAT elimination. To override this default and keep unreferenced COMDATs in the program, specify /OPT:NOREF. You can use the /INCLUDE option to override the removal of a specific symbol.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.