Search code examples
c++visual-studioopencvmms

Read mms stream for open cv


Is there a way to read an mms stream, with open cv, for direct analyze?

I'm trying to do a small project with c++. and I don't know how to plug the mms to the opencv.

I guess ill need to add a library to the visual studio.

There is only video on the mms stream im reading:

mms://s3ewm.castup.net/991450009-52.wmv?ct=IL&rg=BZ&aid=145&tkn=20120201230602&ts=0&cu=FC1B06E9-7ABE-4B1C-9B2A-7A5C6019E99F

Update:

I found this link: Microsoft msdn


Solution

  • here someone did get the mms with vlc package.

    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(2,vlc_argv);
       mediaPlayer = libvlc_media_player_new(instance);
       media = libvlc_media_new_path(instance, "mms://81.89.49.210/musicbox");
    
       struct ctx* context = ( struct ctx* )malloc( sizeof( *context ) );
       context->mutex = CreateMutex(NULL, FALSE,NULL);
       context->image = cvCreateImage(cvSize(VIDEO_WIDTH, VIDEO_HEIGHT), 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", VIDEO_WIDTH, VIDEO_HEIGHT, VIDEO_WIDTH*4);
       libvlc_media_player_play(mediaPlayer);
    
    
       while(1)
       {
       }
       return 0;
    }