1

I'm trying to do something like this post : Get frame from video with libvlc smem and convert it to opencv Mat. (c++)

I can't quite understand the code in this part :

 sprintf(smem_options
      , "#transcode{vcodec=RV24}:smem{"
         "video-prerender-callback=%lld,"
         "video-postrender-callback=%lld,"
         "video-data=%lld,"
         "no-time-sync},"
      , (long long int)(intptr_t)(void*)&cbVideoPrerender
      , (long long int)(intptr_t)(void*)&cbVideoPostrender //This would normally be useful data, 100 is just test data
      , (long long int)200 //Test data
      );

It says video-data=%lld . What does it mean? Where is it taking data from?

I am getting my file using a file dialog . Can I pass that file to video-data?

Community
  • 1
  • 1
user2798392
  • 77
  • 1
  • 10

1 Answers1

5

rather than using the smem output driver of VLC, i would suggest to interact directly with libvlc, via the mediaplayer interface:

/* user_data is the pointer we passed to `video_set_callbacks()` */
void*lock_frame(void*user_data, void**planes) {
   /* make '*plane* point to a memory you want the video-data rendered to */
  *planes=user_data->img;
  return user_data->pic;
}
void unlock_frame(void *user_data, void *picture, void *const *planes) {
   /* image rendered into (*planes)==user_data->img; */
}

unsigned format_callback(void**user_data_ptr; char*chroma, unsigned *width, unsigned *height, unsigned *pitches, unsigned *lines) {
   mydata_t*user_data=(mydata_t*)(*user_data_ptr);

   /* set the output format to RGBA */
   memcpy(chroma, "RV32", 4); /* 'RV32' is 'RGBA'
   /* leave dimensions intact, but store them
    * now's the time to resize user_data->img to hold that much memory
    */
   user_data->width =*width;
   user_data->height=*height;
   *pitches=(*width)*4; /* 4 is the pixel size for RGBA */
   *lines=*height;

   return 1;
}


vlc_inst=libvlc_new (0, 0);
libvlc_media_t*media = libvlc_media_new_location (vlc_inst, location);
libvlc_media_player_t*mplayer=libvlc_media_player_new_from_media(media);
libvlc_video_set_callbacks(mplayer,
                         lock_frame, unlock_frame,
                         0, user_data);
libvlc_video_set_format_callbacks(data->m_mediaplayer, format_callback,0);

libvlc_media_player_play(mplayer);

/* the media-player will call 
 *  - format_callback() with a format suggestion which you can adjust to your needs
 *  - lock_frame()/unlock_frame() whenever a new frame has arrived.
 * once you are done, call: */

libvlc_media_player_stop(mplayer);
libvlc_release(vlc_inst);
umläute
  • 28,885
  • 9
  • 68
  • 122
  • tnx for reply . sorry but i'm not much c++ user so i have some simple (i guess) questions :D . what is user_data ? do you mean *planes=user_data->img; instead of *plane=user_data->img; ?what return does , isn't your function void ? can you provide me with a more completed code please . – user2798392 Sep 28 '15 at 16:07
  • `user_data` is just a pointer to any of *your* data; yes, it should have read `*planes`; no, the function returns `void*` (a pointer to an unspecified type); no, I [cannot](https://github.com/umlaeute/Gem/tree/master/plugins/videoVLC) – umläute Sep 28 '15 at 17:27
  • this method only works if u use **gem plugin**. u have to use **pixBlock** . i don't think that's necessary because libvlc is able to do that . u can save a video to image sequence . u can take snapshot . so u can extract picture from video in libvlc , but i dunno how . – user2798392 Sep 30 '15 at 15:56
  • you asked for a complete example and i provided one from real world; which is embedded in another framework (Gem); the use of the *libvlc-API* is really straightforward – umläute Sep 30 '15 at 18:04
  • tnx for that . i figured it out . this is really good way but in this way u cannot find video width and height and u have to use predefined width and height . – user2798392 Oct 03 '15 at 11:19
  • @user2798392 actually you can use the native width/height by using `libvlc_video_set_format_callbacks()`; i've updated my simple example – umläute Oct 04 '15 at 17:17
  • this is great . it works . but another little issue . the height in format_callback has margin or something and its not real height of my video . – user2798392 Oct 05 '15 at 12:39
  • btw, if an answer has helped you, you migh consider *upvoting* and/or *accepting* it – umläute Oct 05 '15 at 15:09