osg播放视频需要依赖ffmpeg库,ffmpeg现在已经到5.X,最新版本的ffmpeg无法编译出osgdb_ffmpeg插件,建议使用3.4.2以前版本。
std::string libName = osgDB::Registry::instance()->createLibraryNameForExtension("ffmpeg");
osgDB::Registry::LoadStatus status = osgDB::Registry::instance()->loadLibrary(libName);
osgDB::Registry::instance()->addFileExtensionAlias("mp4", "ffmpeg");
osg::ref_ptr<osg::Image> image = osgDB::readRefImageFile("23.mp4");
osg::ref_ptr<osgDB::ReaderWriter> rwter = osgDB::Registry::instance()->getReaderWriterForExtension("ffmpeg");
osgDB::ReaderWriter::ReadResult rr = rwter->readImage("rtsp://192.168.0.1:8080/h264/ch1/main/av_stream");
osg::ref_ptr<osg::Image> image = rr.getImage();