【问题标题】:working with VLC smem使用 VLC smem
【发布时间】:2015-09-28 14:21:05
【问题描述】:

我正在尝试做类似这篇文章的事情: 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。这是什么意思?它从哪里获取数据?

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

【问题讨论】:

标签: c++ visual-studio opencv libvlc


【解决方案1】:

我建议通过mediaplayer接口直接与libvlc交互,而不是使用VLC的smem输出驱动:

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

【讨论】:

  • tnx 回复。对不起,但我不是很多 C++ 用户,所以我有一些简单的(我猜)问题:D。什么是 user_data ?你的意思是 *planes=user_data->img;而不是 *plane=user_data->img; ?什么 return ,你的函数不是 void 吗?你能给我一个更完整的代码吗?
  • user_data 只是一个指向任何你的数据的指针;是的,它应该是*planes;不,该函数返回void*(指向未指定类型的指针);不,我cannot
  • 此方法仅在您使用 gem 插件 时有效。你必须使用 pixBlock 。我不认为这是必要的,因为 libvlc 能够做到这一点。您可以将视频保存到图像序列。你可以拍快照。所以你可以从 libvlc 中的视频中提取图片,但我不知道如何。
  • 你要求一个完整的例子,我提供了一个来自现实世界的例子;它嵌入在另一个框架(Gem)中; libvlc-API 的使用非常简单
  • tnx 。我想到了 。这确实是个好方法,但是这样你就找不到视频的宽度和高度,你必须使用预定义的宽度和高度。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2021-02-03
  • 2013-01-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-07
相关资源
最近更新 更多