root/OpenSceneGraph/trunk/src/osgPlugins/directshow/ReaderWriterDirectShow.cpp @ 10798

Revision 10798, 3.2 kB (checked in by robert, 4 years ago)

From Cedric Pinson, "Here an update of the directshow plugin. It fixes issues with
synchronization, improve capture device support.

here how to use it to display a capture device:

osg::Options* options = new osg::Options;
options->setPluginStringData("captureWantedWidth", "800");
options->setPluginStringData("captureWantedHeight", "600");
options->setPluginStringData("captureWantedFps", "30");
options->setPluginStringData("captureVideoDevice", "USB Video Device" );
options->setPluginStringData("captureSoundDevice", "");
then
osgDB::readImageFile("capture.directshow", options)
you can use a graphedit application to list devices available in
directshow.

for classic avi file you just need to do a
osgDB::readImageFile("file.avi.directshow");
You will need of course to install the codec needed by directshow to
read the avi files.

I recommand this tool http://avicodec.duby.info/, that check which
video/sound codec is needed to play an avi file.

You can test it with the osgmovie example.
"

Line 
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 2009 Tharsis Software
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 *
13 * Authors:
14 *         Cedric Pinson <cedric.pinson@plopbyte.net>
15*/
16
17
18#include <osgDB/Registry>
19#include <osgDB/FileNameUtils>
20#include <osgDB/FileUtils>
21
22#include "DirectShowTexture"
23
24
25class ReaderWriterDirectShow : public osgDB::ReaderWriter
26{
27public:
28
29    ReaderWriterDirectShow()
30    {
31    }
32
33    virtual ~ReaderWriterDirectShow()
34    {
35    }
36
37    virtual const char * className() const
38    {
39        return "ReaderWriterDirectShow";
40    }
41
42    virtual ReadResult readImage(const std::string & filename, const osgDB::ReaderWriter::Options * options) const
43    {
44        const std::string ext = osgDB::getLowerCaseFileExtension(filename);
45        if (ext=="directshow") return readImage(osgDB::getNameLessExtension(filename),options);
46        return readImageStream(filename, options);
47    }
48   
49    ReadResult readImageStream(const std::string& filename, const osgDB::ReaderWriter::Options * options) const
50    {
51        osg::notify(osg::INFO) << "ReaderWriterFFmpeg::readImage " << filename << std::endl;
52        const std::string path = osgDB::containsServerAddress(filename) ?
53            filename :
54            osgDB::findDataFile(filename, options);
55
56        osg::ref_ptr<DirectShowImageStream> image_stream(new DirectShowImageStream);
57
58        if (path.empty()) // try with capture
59        {
60            std::map<std::string,std::string> map;
61            if (options)
62            {
63                map["captureWantedWidth"] = options->getPluginStringData("captureWantedWidth");
64                map["captureWantedHeight"] = options->getPluginStringData("captureWantedHeight");
65                map["captureWantedFps"] = options->getPluginStringData("captureWantedFps");
66                map["captureVideoDevice"] = options->getPluginStringData("captureVideoDevice");
67                map["captureSoundDevice"] = options->getPluginStringData("captureSoundDevice");
68                map["captureSoundDeviceNbChannels"] = options->getPluginStringData("captureSoundDeviceNbChannels");
69            }
70            if (filename != "capture")
71            {
72                if (!options || (options && options->getPluginStringData("captureVideoDevice").empty()))
73                     map["captureVideoDevice"] = filename;
74            }
75            image_stream->setOptions(map);
76
77            if (! image_stream->openCaptureDevices())
78                return ReadResult::FILE_NOT_HANDLED;
79            return image_stream.release();
80        }
81
82        if (! image_stream->openFile(filename))
83            return ReadResult::FILE_NOT_HANDLED;
84
85        return image_stream.release();
86    }
87
88private:
89
90};
91
92
93
94REGISTER_OSGPLUGIN(directshow, ReaderWriterDirectShow)
Note: See TracBrowser for help on using the browser.