使用VLC smem [英] working with VLC smem

查看:148
本文介绍了使用VLC smem的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试做这样的事情: 从视频中获取帧与libvlc smem并将其转换为opencv Mat. (c ++)

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
      );

video-data=%lld.这是什么意思?它从哪里获取数据?

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?

推荐答案

而不是使用VLC的smem输出驱动程序,我建议通过libvlc进行交互. /www.videolan.org/developers/vlc/doc/doxygen/html/group__libvlc__media__player.html"rel =" noreferrer> mediaplayer 界面:

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);

这篇关于使用VLC smem的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆