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

Revision 9968, 2.9 kB (checked in by robert, 6 years ago)

Added support for adding .ffmpeg to filenames to force selection of ffmpeg plugin

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.");
32
[9968]33        supportsExtension("ffmpeg", "");
[9816]34        supportsExtension("avi", "");
35        supportsExtension("flv", "");
36        supportsExtension("mov", "");
[9838]37        supportsExtension("ogg", "Theora movie format");
[9816]38        supportsExtension("mpg", "Mpeg movie format");
39        supportsExtension("mpv", "Mpeg movie format");
[9965]40        supportsExtension("wmv", "Windows Media Video format");
41        supportsExtension("mkv", "Matroska");
[9816]42
43        // Register all FFmpeg formats/codecs
44        av_register_all();
45    }
46
47    virtual ~ReaderWriterFFmpeg()
48    {
49
50    }
51
52    virtual const char * className() const
53    {
54        return "ReaderWriterFFmpeg";
55    }
56
57    virtual ReadResult readImage(const std::string & filename, const osgDB::ReaderWriter::Options * options) const
58    {
[9968]59        const std::string ext = osgDB::getLowerCaseFileExtension(filename);
60        if (ext=="ffmpeg") return readImage(osgDB::getNameLessExtension(filename),options);
61
[9865]62        if (filename.compare(0, 5, "/dev/")==0)
63        {
64            return readImageStream(filename, options);
65        }
66   
[9816]67        if (! acceptsExtension(ext))
68            return ReadResult::FILE_NOT_HANDLED;
69
[9854]70        const std::string path = osgDB::containsServerAddress(filename) ?
71            filename :
72            osgDB::findDataFile(filename, options);
[9816]73
74        if (path.empty())
75            return ReadResult::FILE_NOT_FOUND;
76
[9865]77        return readImageStream(filename, options);
78    }
79   
80    ReadResult readImageStream(const std::string& filename, const osgDB::ReaderWriter::Options * options) const
81    {
82        osg::notify(osg::INFO) << "ReaderWriterFFmpeg::readImage " << filename << std::endl;
[9816]83
84        osg::ref_ptr<osgFFmpeg::FFmpegImageStream> image_stream(new osgFFmpeg::FFmpegImageStream);
85
[9865]86        if (! image_stream->open(filename))
[9816]87            return ReadResult::FILE_NOT_HANDLED;
88
89        return image_stream.release();
90    }
91
92private:
93
94};
95
96
97
98REGISTER_OSGPLUGIN(ffmpeg, ReaderWriterFFmpeg)
Note: See TracBrowser for help on using the browser.