root/OpenSceneGraph/trunk/src/osgPlugins/ffmpeg/ReaderWriterFFmpeg.cpp @ 9865

Revision 9865, 2.0 kB (checked in by robert, 6 years ago)

Added quick proof of concept for live video streaming under linux

RevLine 
[9816]1
2#include <osgDB/Registry>
3#include <osgDB/FileNameUtils>
4#include <osgDB/FileUtils>
5
6#include "FFmpegHeaders.hpp"
7#include "FFmpegImageStream.hpp"
8
9
10
11/** Implementation heavily inspired by http://www.dranger.com/ffmpeg/ */
12
13class ReaderWriterFFmpeg : public osgDB::ReaderWriter
14{
15public:
16
17    ReaderWriterFFmpeg()
18    {
19        supportsExtension("avi", "");
20        supportsExtension("flv", "");
21        supportsExtension("mov", "");
[9838]22        supportsExtension("ogg", "Theora movie format");
[9816]23        supportsExtension("mpg", "Mpeg movie format");
24        supportsExtension("mpv", "Mpeg movie format");
25        supportsExtension("wmv", "");
26
27        // Register all FFmpeg formats/codecs
28        av_register_all();
29    }
30
31    virtual ~ReaderWriterFFmpeg()
32    {
33
34    }
35
36    virtual const char * className() const
37    {
38        return "ReaderWriterFFmpeg";
39    }
40
41    virtual ReadResult readImage(const std::string & filename, const osgDB::ReaderWriter::Options * options) const
42    {
[9865]43        if (filename.compare(0, 5, "/dev/")==0)
44        {
45            return readImageStream(filename, options);
46        }
47   
[9816]48        const std::string ext = osgDB::getLowerCaseFileExtension(filename);
49        if (! acceptsExtension(ext))
50            return ReadResult::FILE_NOT_HANDLED;
51
[9854]52        const std::string path = osgDB::containsServerAddress(filename) ?
53            filename :
54            osgDB::findDataFile(filename, options);
[9816]55
56        if (path.empty())
57            return ReadResult::FILE_NOT_FOUND;
58
[9865]59        return readImageStream(filename, options);
60    }
61   
62    ReadResult readImageStream(const std::string& filename, const osgDB::ReaderWriter::Options * options) const
63    {
64        osg::notify(osg::INFO) << "ReaderWriterFFmpeg::readImage " << filename << std::endl;
[9816]65
66        osg::ref_ptr<osgFFmpeg::FFmpegImageStream> image_stream(new osgFFmpeg::FFmpegImageStream);
67
[9865]68        if (! image_stream->open(filename))
[9816]69            return ReadResult::FILE_NOT_HANDLED;
70
71        return image_stream.release();
72    }
73
74private:
75
76};
77
78
79
80REGISTER_OSGPLUGIN(ffmpeg, ReaderWriterFFmpeg)
Note: See TracBrowser for help on using the browser.