Osg-Osg利用ffmpeg实现加载mp4(未实现)No29-ffmpegLoadMP4

相关资料

https://blog.csdn.net/FreeSouthS/article/details/118764606

https://www.cnblogs.com/k5bg/p/13813070.html

我没实现,不知道是不是我用的osg库中没有这个插件

实例代码

.pro

 1 QT       += core gui widgets
 2 QT       += opengl
 3 TARGET = TestOsgQt
 4 TEMPLATE = app
 5 DEFINES += QT_DEPRECATED_WARNINGS
 6 
 7 QMAKE_CXXFLAGS_RELEASE = $$QMAKE_CFLAGS_RELEASE_WITH_DEBUGINFO
 8 QMAKE_LFLAGS_RELEASE = $$QMAKE_LFLAGS_RELEASE_WITH_DEBUGINFO
 9 
10 
11 CONFIG += c++11
12 
13 SOURCES += \
14         main.cpp
15 
16 HEADERS +=
17 
18 OsgDir = D:\\Gitee\\osg365R
19 CONFIG(release, debug|release) {
20         LIBS += -L$${OsgDir}/lib/ -losgDB -losgViewer -lOpenThreads -losgAnimation -losg \
21                                   -losgEarth -losgEarthAnnotation -losgEarthFeatures -losgEarthSymbology -losgEarthUtil \
22                                   -losgQOpenGL -losgUtil -losgText -losgTerrain -losgSim \
23                                   -losgShadow -losgParticle -losgManipulator -losgGA -losgFX \
24                                   -losgWidget
25 } else {
26         LIBS += -L$${OsgDir}/debug/lib/ -losgDBd -losgViewerd -lOpenThreadsd -losgAnimationd -losgd \
27                                   -losgEarthd -losgEarthAnnotationd -losgEarthFeaturesd -losgEarthSymbologyd -losgEarthUtild \
28                                   -losgQOpenGLd -losgUtild -losgTextd -losgTerraind -losgSimd \
29                                   -losgShadowd -losgParticled -losgManipulatord -losgGAd -losgFXd \
30 }
31 
32 LIBS += -lOpenGL32
33 LIBS += -lGlU32
34 
35 INCLUDEPATH += $${OsgDir}/include
36 DEPENDPATH += $${OsgDir}/include
View Code

main.cpp

 1 #include <osgViewer/Viewer>
 2 #include <osgDB/ReadFile>
 3 #include <osg/Geode>
 4 #include <osg/ImageStream>
 5 #include <osg/Texture2D>
 6 
 7 osg::Node* createAPlane()
 8 {
 9     osg::Geode* gnode = new osg::Geode;
10     gnode->getOrCreateStateSet()->setMode(GL_LIGHTING, osg::StateAttribute::OFF|osg::StateAttribute::OVERRIDE);
11 
12     osg::Geometry* geom = new osg::Geometry;
13     gnode->addDrawable(geom);
14 
15     //顶点
16     osg::Vec3Array* vertex = new osg::Vec3Array;
17     geom->setVertexArray(vertex);
18 
19     //纹理
20     osg::Vec2Array* coord = new osg::Vec2Array;
21     geom->setTexCoordArray(0, coord);
22 
23     //压入四个顶点构成一个面,我这个视频是1260x788的,比例很奇葩
24     vertex->push_back(osg::Vec3(0.0, 0.0, 0.0));
25     coord->push_back(osg::Vec2(0.0, 0.0));
26 
27     vertex->push_back(osg::Vec3(1920.0, 0.0, 0.0));
28     coord->push_back(osg::Vec2(1.0, 0.0));
29 
30     vertex->push_back(osg::Vec3(1920.0, 0.0, 1080.0));
31     coord->push_back(osg::Vec2(1.0, 1.0));
32 
33     vertex->push_back(osg::Vec3(0.0, 0.0, 1080.0));
34     coord->push_back(osg::Vec2(0.0, 1.0));
35 
36     geom->addPrimitiveSet(new osg::DrawArrays(GL_QUADS, 0, 4));
37 
38     //读取纹理
39     osgDB::Registry::instance()->addFileExtensionAlias("mp4", "ffmpeg");
40     osg::Image* image = osgDB::readImageFile("D:/Gitee/OsgTestQt/src/No29/1.mp4");
41 
42     //转换成图片流,然后播放
43     osg::ImageStream* imagestream = dynamic_cast<osg::ImageStream*>(image);
44     if (imagestream)
45     {
46         imagestream->play();
47     }
48 
49     osg::Texture2D* texture = new osg::Texture2D(image);
50     texture->setResizeNonPowerOfTwoHint(false);
51     texture->setFilter(osg::Texture::MIN_FILTER, osg::Texture::LINEAR);
52     texture->setWrap(osg::Texture::WRAP_S, osg::Texture::CLAMP_TO_EDGE);
53     texture->setWrap(osg::Texture::WRAP_T, osg::Texture::CLAMP_TO_EDGE);
54 
55     geom->getOrCreateStateSet()->setTextureAttributeAndModes(0,
56         texture,
57         osg::StateAttribute::ON);
58 
59     return gnode;
60 }
61 
62 int main()
63 {
64     osgViewer::Viewer viewer;
65     viewer.setSceneData(createAPlane());
66     return viewer.run();
67 }
View Code

 

 

posted on 2022-08-16 15:38  疯狂delphi  阅读(64)  评论(0编辑  收藏  举报

导航