• OsgOsg利用ffmpeg实现加载mp4(未实现)No29ffmpegLoadMP4


    相关资料

    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
  • 相关阅读:
    Windows Server 2019 mmc无法创建单元
    .NET 设置IE代理
    检测WebService是否存在
    C#读取图片像素
    23种设计模式之简单工厂
    WinForm笔记一:文本框只允许输入数字
    ADO.NET笔记(一)XML导入导出和数据库
    winform中文本框的一些案例
    C#中的二进制序列化和Json序列化
    文件流操作(FileStream,StreamReader,StreamWriter)
  • 原文地址:https://www.cnblogs.com/FKdelphi/p/16591778.html
Copyright © 2020-2023  润新知