Historique des modifications - Message

Message #6508

Sujet: C++ lecture video via ffmpeg


Type Date Auteur Contenu
Dernière modification 16-08-2009 08:49:28 Magun
petit update du machin wink





SVideo.hSVideo.cppCGUIVideo.hCGUIVideo.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#ifndef _SVIDEO_H_
#define _SVIDEO_H_

/** * * * * * * * * * * * * * * * * * * * * * * * * *
    *                                               *
    *           created by Ovan or Magun            *
    *   compile with : lavformat,lavcodec,lavutil   *
    *        and other library defined last         *
    *                                               *
    *                 conctact me :                 *
    *                www.irrlicht.fr                *
    *            www.immortal-galaxy.com            *
    *                                               *
    * * * * * * * * * * * * * * * * * * * * * * * * * **/

#include <stdint.h>
#if defined WIN32 || defined WIN64 || defined _WIN32_ || defined _WIN64_
    #define WINDOWS
#endif

struct AVFormatContext;
struct AVCodecContext;
struct AVCodec;
struct AVPicture;
struct AVFrame;

namespace interne
{
    namespace _interface { class CGUIVideo; }
    struct SVideo
    {
        public :
            SVideo();
            SVideo(char*file,bool sound = false);
            ~SVideo();
            bool open( char *file, bool sound);
            void play( bool p = true ), stop(), setLoop(bool b = false);
            bool restart(), isPlay(), isLoop();

            int     getWindowFPS(),         getVideoFPS();
            double  getOriginalFPS();       //! get video file fps info
            int     getFrame(),             getTotalFrame();
            int     getTime(),              getTotalTime();//!
            void    goToFrame(int frm);
            void    goToTime(int sec = 0, int min = 0, int h = 0);
            //! file info ... update ffmpeg for use this
            char   *getAuthor(),      *getAlbum();
            char   *getTitle(),       *getCopyright();
            char   *getComment(),     *getGenre();
            int     getYear(),         getTrack();

            bool makeFrame();
            signed int width, height;
        private :
            friend class _interface::CGUIVideo;
            char *file;

            AVFrame *Frame,*FrameRGB;
            AVFormatContext *FormatCtx;
            AVCodecContext  *videoCodecCtx ,*audioCodecCtx ,*dataCodecCtx;
            AVCodec         *videoCodec    ,*audioCodec    ,*dataCodec;

            uint8_t *buffer;

            double videoFPS;
            int  nFrm, frame, numBytes, windowFPS;
            int  videoStream, audioStream, dataStream;
            bool drawFrame, Sound, Play, Replay, writeConsol;
    };
}
#endif

avec un code d'exemple pour les fégniants comme moi :

GameIntro.h

Code c++ :

#ifndef _GAME_INTRO_H_
#define _GAME_INTRO_H_

#include "CGUIVideo.h"
namespace interne
{
    namespace _interface
    {
        class GameIntro
        {
            public:
                GameIntro(irr::IrrlichtDevice*,char*,bool rsz = false);
                virtual ~GameIntro();
                virtual bool externalEvent(irr::SEvent event);
                bool draw();

                SVideo vi;
                CGUIVideo *intro;
            protected:
                bool resize_for_render;
                irr::IrrlichtDevice *device;
                irr::core::dimension2d<irr::u32> current_render_size;
        };
    }
}
#endif // _GAME_INTRO_H_

GameIntro.cpp

Code c++ :

#include "GameIntro.h"

using namespace irr;
using namespace video;
using namespace core;

namespace interne
{
    namespace _interface
    {
        GameIntro::GameIntro(irr::IrrlichtDevice*dev,char*video_file,bool rsz) : device(dev)
        {
            current_render_size = device->getVideoDriver()->getScreenSize();
            resize_for_render = rsz;
            vi.open(video_file,true); vi.play(true);
            intro = new _interface::CGUIVideo(&vi);
            intro->setVideoDriver(device->getVideoDriver(),device->getTimer());
            device->getVideoDriver()->setTextureCreationFlag(ETCF_CREATE_MIP_MAPS, false);
            if(resize_for_render) device->getVideoDriver()->OnResize(dimension2d<u32>(vi.width,vi.height));
        }
        GameIntro::~GameIntro()
        {
            vi.stop();
            //delete vi;
            delete intro;
            if(resize_for_render) device->getVideoDriver()->OnResize(current_render_size);
            device->getVideoDriver()->setTextureCreationFlag(ETCF_CREATE_MIP_MAPS, true);
        }
        bool GameIntro::externalEvent(SEvent event)
        {
            if(event.EventType == EET_MOUSE_INPUT_EVENT && event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP && intro)
            { return true; }
            if (event.EventType == EET_KEY_INPUT_EVENT && event.KeyInput.PressedDown == false && intro)
            {
                switch(event.KeyInput.Key)
                {
                    case KEY_ESCAPE: case KEY_DELETE: case KEY_RETURN: case KEY_SPACE:
                    return true; break; default: break;
                }
            }
            return false;
        }
        bool GameIntro::draw()
        {
            if(intro && intro->refreshByTime() && device->run())
            {
                device->getVideoDriver()->draw2DImage(intro->draw(), position2d<s32>(0,0));
                return false;
            }
            return true;
        }
    }
}

Code c++ :

        device->getCursorControl()->setVisible(false);
        intro = new _interface::GameIntro(device,"data/intro.data",true);
        while(device->run() && intro)
        {
            driver->beginScene(true, true, SColor(0,0,0,0));
            if(intro->draw()) break;
            driver->endScene();
        }
        if(intro) delete intro; //if is deleted with event manager
        intro = NULL;
        device->getCursorControl()->setVisible(true);

pour utiliser les evenements sans changer de "callback ?" passer par GameIntro->externalEvent(event); ( event = le "const SEvent &" du OnEvent pour les nulls ), biensur ses coder pour mon projet donc a modifier a vos besoin ^^

je croix qu'il y a une erreur dans le code, il date un peut il me semble, sa sorte de ma clées usb .... si quelqu'un teste et que sa marche pas trop, dite j'editerais wink
dsl je poste pas d'archive pour tester, et euh oui j'ai constater que sa plantais a la convertion de certain type de video avec irrlicht ...
merci en passant a la personne qui a fait "int img_convert..." !, a demande j'ai un makefile pour linux de cette même personne smile

ps : pas de correcteur orthographique, sorry tongue
ps : avoir une geforce 6150 LE mini, avec un petit gain de 9fps tongue
Création du message 12-06-2009 18:49:41 Magun
petit update du machin wink





SVideo.hSVideo.cppCGUIVideo.hCGUIVideo.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#ifndef _SVIDEO_H_
#define _SVIDEO_H_

/** * * * * * * * * * * * * * * * * * * * * * * * * *
    *                                               *
    *           created by Ovan or Magun            *
    *   compile with : lavformat,lavcodec,lavutil   *
    *        and other library defined last         *
    *                                               *
    *                 conctact me :                 *
    *                www.irrlicht.fr                *
    *            www.immortal-galaxy.com            *
    *                                               *
    * * * * * * * * * * * * * * * * * * * * * * * * * **/

#include <stdint.h>
#if defined WIN32 || defined WIN64 || defined _WIN32_ || defined _WIN64_
    #define WINDOWS
#endif

struct AVFormatContext;
struct AVCodecContext;
struct AVCodec;
struct AVPicture;
struct AVFrame;

namespace interne
{
    namespace _interface { class CGUIVideo; }
    struct SVideo
    {
        public :
            SVideo();
            SVideo(char*file,bool sound = false);
            ~SVideo();
            bool open( char *file, bool sound);
            void play( bool p = true ), stop(), setLoop(bool b = false);
            bool restart(), isPlay(), isLoop();

            int     getWindowFPS(),         getVideoFPS();
            double  getOriginalFPS();       //! get video file fps info
            int     getFrame(),             getTotalFrame();
            int     getTime(),              getTotalTime();//!
            void    goToFrame(int frm);
            void    goToTime(int sec = 0, int min = 0, int h = 0);
            //! file info ... update ffmpeg for use this
            char   *getAuthor(),      *getAlbum();
            char   *getTitle(),       *getCopyright();
            char   *getComment(),     *getGenre();
            int     getYear(),         getTrack();

            bool makeFrame();
            signed int width, height;
        private :
            friend class _interface::CGUIVideo;
            char *file;

            AVFrame *Frame,*FrameRGB;
            AVFormatContext *FormatCtx;
            AVCodecContext  *videoCodecCtx ,*audioCodecCtx ,*dataCodecCtx;
            AVCodec         *videoCodec    ,*audioCodec    ,*dataCodec;

            uint8_t *buffer;

            double videoFPS;
            int  nFrm, frame, numBytes, windowFPS;
            int  videoStream, audioStream, dataStream;
            bool drawFrame, Sound, Play, Replay, writeConsol;
    };
}
#endif

avec un code d'exemple pour les fégniants comme moi :

GameIntro.h

Code c++ :

#ifndef _GAME_INTRO_H_
#define _GAME_INTRO_H_

#include "CGUIVideo.h"
namespace interne
{
    namespace _interface
    {
        class GameIntro
        {
            public:
                GameIntro(irr::IrrlichtDevice*,char*,bool rsz = false);
                virtual ~GameIntro();
                virtual bool externalEvent(irr::SEvent event);
                bool draw();

                SVideo vi;
                CGUIVideo *intro;
            protected:
                bool resize_for_render;
                irr::IrrlichtDevice *device;
                irr::core::dimension2d<irr::u32> current_render_size;
        };
    }
}
#endif // _GAME_INTRO_H_

GameIntro.cpp

Code c++ :

#include "GameIntro.h"

using namespace irr;
using namespace video;
using namespace core;

namespace interne
{
    namespace _interface
    {
        GameIntro::GameIntro(irr::IrrlichtDevice*dev,char*video_file,bool rsz) : device(dev)
        {
            current_render_size = device->getVideoDriver()->getScreenSize();
            resize_for_render = rsz;
            vi.open(video_file,true); vi.play(true);
            intro = new _interface::CGUIVideo(&vi);
            intro->setVideoDriver(device->getVideoDriver(),device->getTimer());
            device->getVideoDriver()->setTextureCreationFlag(ETCF_CREATE_MIP_MAPS, false);
            if(resize_for_render) device->getVideoDriver()->OnResize(dimension2d<u32>(vi.width,vi.height));
        }
        GameIntro::~GameIntro()
        {
            vi.stop();
            //delete vi;
            delete intro;
            if(resize_for_render) device->getVideoDriver()->OnResize(current_render_size);
            device->getVideoDriver()->setTextureCreationFlag(ETCF_CREATE_MIP_MAPS, true);
        }
        bool GameIntro::externalEvent(SEvent event)
        {
            if(event.EventType == EET_MOUSE_INPUT_EVENT && event.MouseInput.Event == EMIE_LMOUSE_LEFT_UP && intro)
            { return true; }
            if (event.EventType == EET_KEY_INPUT_EVENT && event.KeyInput.PressedDown == false && intro)
            {
                switch(event.KeyInput.Key)
                {
                    case KEY_ESCAPE: case KEY_DELETE: case KEY_RETURN: case KEY_SPACE:
                    return true; break; default: break;
                }
            }
            return false;
        }
        bool GameIntro::draw()
        {
            if(intro && intro->refreshByTime() && device->run())
            {
                device->getVideoDriver()->draw2DImage(intro->draw(), position2d<s32>(0,0));
                return false;
            }
            return true;
        }
    }
}

Code c++ :

        device->getCursorControl()->setVisible(false);
        intro = new _interface::GameIntro(device,"data/intro.data",true);
        while(device->run() && intro)
        {
            driver->beginScene(true, true, SColor(0,0,0,0));
            if(intro->draw()) break;
            driver->endScene();
        }
        if(intro) delete intro; //if is deleted with event manager
        intro = NULL;
        device->getCursorControl()->setVisible(true);

pour utiliser les evenements sans changer de "callback ?" passer par GameIntro->externalEvent(event); ( event = le "const SEvent &" du OnEvent pour les nulls ), biensur ses coder pour mon projet donc a modifier a vos besoin ^^

je croix qu'il y a une erreur dans le code, il date un peut il me semble, sa sorte de ma clées usb .... si quelqu'un teste et que sa marche pas trop, dite j'editerais wink
dsl je poste pas d'archive pour tester, et euh oui j'ai constater que sa plantais a la convertion de certain type de video avec irrlicht ...
merci en passant a la personne qui a fait "int img_convert..." !, a demande j'ai un makefile pour linux de cette même personne smile

ps : pas de correcteur orthographique, sorry tongue
ps : avoir une geforce 6150 LE mini, avec un petit gain de 9fps tongue

Retour

Options Liens officiels Caractéristiques Statistiques Communauté
Préférences cookies
Corrections
irrlicht
irrklang
irredit
irrxml
Propulsé par Django
xhtml 1.0
css 2.1
884 membres
1440 sujets
11337 messages
Dernier membre inscrit: Saidov17
190 invités en ligne
membre en ligne: -
RSS Feed