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

Revision 10030, 3.3 kB (checked in by robert, 5 years ago)

From Jean Sebastien Guay, added error reporting handling of wider range of video formats.

RevLine 
[9885]1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under 
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version.  The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 * OpenSceneGraph Public License for more details.
12*/
[9816]13
14#include <osgDB/Registry>
15#include <osgDB/FileNameUtils>
16#include <osgDB/FileUtils>
17
18#include "FFmpegHeaders.hpp"
19#include "FFmpegImageStream.hpp"
20
21
22
23/** Implementation heavily inspired by http://www.dranger.com/ffmpeg/ */
24
25class ReaderWriterFFmpeg : public osgDB::ReaderWriter
26{
27public:
28
29    ReaderWriterFFmpeg()
30    {
[9885]31        supportsProtocol("http","Read video/audio from http using ffmpeg.");
[10030]32        supportsProtocol("rtsp","Read video/audio from rtsp using ffmpeg.");
[9885]33
[9968]34        supportsExtension("ffmpeg", "");
[10030]35        supportsExtension("avi",    "");
36        supportsExtension("flv",    "Flash video");
37        supportsExtension("mov",    "Quicktime");
38        supportsExtension("ogg",    "Theora movie format");
39        supportsExtension("mpg",    "Mpeg movie format");
40        supportsExtension("mpv",    "Mpeg movie format");
41        supportsExtension("wmv",    "Windows Media Video format");
42        supportsExtension("mkv",    "Matroska");
43        supportsExtension("mjpeg""Motion JPEG");
44        supportsExtension("mp4",    "MPEG-4");
45        supportsExtension("sav",    "MPEG-4");
46        supportsExtension("3gp",    "MPEG-4");
47        supportsExtension("sdp",    "MPEG-4");
[9816]48
49        // Register all FFmpeg formats/codecs
50        av_register_all();
51    }
52
53    virtual ~ReaderWriterFFmpeg()
54    {
55
56    }
57
58    virtual const char * className() const
59    {
60        return "ReaderWriterFFmpeg";
61    }
62
63    virtual ReadResult readImage(const std::string & filename, const osgDB::ReaderWriter::Options * options) const
64    {
[9968]65        const std::string ext = osgDB::getLowerCaseFileExtension(filename);
66        if (ext=="ffmpeg") return readImage(osgDB::getNameLessExtension(filename),options);
67
[9865]68        if (filename.compare(0, 5, "/dev/")==0)
69        {
70            return readImageStream(filename, options);
71        }
72   
[9816]73        if (! acceptsExtension(ext))
74            return ReadResult::FILE_NOT_HANDLED;
75
[9854]76        const std::string path = osgDB::containsServerAddress(filename) ?
77            filename :
78            osgDB::findDataFile(filename, options);
[9816]79
80        if (path.empty())
81            return ReadResult::FILE_NOT_FOUND;
82
[9865]83        return readImageStream(filename, options);
84    }
85   
86    ReadResult readImageStream(const std::string& filename, const osgDB::ReaderWriter::Options * options) const
87    {
88        osg::notify(osg::INFO) << "ReaderWriterFFmpeg::readImage " << filename << std::endl;
[9816]89
90        osg::ref_ptr<osgFFmpeg::FFmpegImageStream> image_stream(new osgFFmpeg::FFmpegImageStream);
91
[9865]92        if (! image_stream->open(filename))
[9816]93            return ReadResult::FILE_NOT_HANDLED;
94
95        return image_stream.release();
96    }
97
98private:
99
100};
101
102
103
104REGISTER_OSGPLUGIN(ffmpeg, ReaderWriterFFmpeg)
Note: See TracBrowser for help on using the browser.