c++ - 使用 VLC smem

标签 c++ visual-studio opencv libvlc

我正在尝试做类似这篇文章的事情: Get frame from video with libvlc smem and convert it to opencv Mat. (c++)

我不太明白这部分的代码:

 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 。这是什么意思?它从哪里获取数据?

我正在使用文件对话框获取我的文件。我可以将该文件传递给视频数据吗?

最佳答案

与其使用 VLC 的 smem 输出驱动程序,我建议通过 mediaplayer 直接与 libvlc 交互。接口(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);

关于c++ - 使用 VLC smem,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32825363/

相关文章:

c++ - 设置 opengl View 和投影转换

C++ 不同 -> 和 "."

visual-studio - Visual Studio 2012 'Publish Profile' 到 Windows Server 2008 - 'Destination not compatible' 错误

opencv - opencv上使用 'find'命令生成采集文件报错

c++ - 旧版本的 boost.test 问题

c++ - C++中同一类的类成员的静态初始化

c# - Visual Studio 打字问题

visual-studio - 如何修复 MSSQLLocalDB?

python - 在opencv中应用sobel和laplacian滤波器后图像的边缘检测

c++ - OpenCV 通过子矩阵改变矩阵