一直在文档中找不到,接口设计的也不大好。不过终于在stackoverflow上找到解决方案了。
原来在LIbVLC库实例化的时候就需要传递相关的参数。我的代码大致是这样实现:
1 const char * vlc_args[] = 2 { 3 "--sout=" 4 }; 5 6 if ((m_vlcInsatnce = libvlc_new(sizeof(vlc_args)/sizeof(vlc_args[0]), vlc_args)) == NULL) 7 { 8 std::cerr << "Could not init VLC" << std::endl; 9 exit(1); 10 } 11 12 13 //开始录制转换 14 QString sout = "#transcode{vcodec=mp4v,acodec=mpga,vb=800,ab=128,deinterlace}:duplicate{dst=file{dst=" + m_recordFile + "}}"; 15 16 17 libvlc_vlm_add_broadcast(m_vlcInsatnce, media_name, m_url.toStdString().c_str(), sout.toStdString().c_str(), 0, NULL, true, true); 18 libvlc_vlm_play_media(m_vlcInsatnce, media_name); 19 20 //这里可以加入一些时间,录制时间 21 //停止录制 22 libvlc_vlm_stop_media(m_vlcInsatnce, media_name); 23 libvlc_vlm_del_media(m_vlcInsatnce, media_name); 24 25 libvlc_vlm_release(m_vlcInsatnce);
详情可以参考我的Github上一个媒体播放器的代码:
https://github.com/AlexiaChen/MediaPlayer
references:
http://stackoverflow.com/questions/16515099/saving-a-stream-while-playing-it-using-libvlc
http://stackoverflow.com/questions/26464138/how-to-stream-raw-data-from-memory-using-libvlc-and-visual-studio-2008?rq=1
http://blog.csdn.net/xuplus/article/details/34081989