From Wang Rui, "additional FFmpegParameters class in the ffmpeg plugin for setting parameters before opening the video file, which benefits from getPluginStringData() as shown in the ReaderWriter implementation.
Now we can use ffmpeg to render webcam video (using the vfwcap device) under Windows: osgmovie 0 -e ffmpeg -O "format=vfwcap frame_rate=25" The number 0 just indicates a default device number in ffmpeg. I think this can work under Linux, too, and should be a bit better than comparing the filename with a '/dev/' string. Just type: ./osgmovie /dev/yourcam -e ffmpeg -O "format=video4linux2 frame_rate=30 size=320x240""
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
|
||||
#include "FFmpegHeaders.hpp"
|
||||
#include "FFmpegImageStream.hpp"
|
||||
#include "FFmpegParameters.hpp"
|
||||
|
||||
#include <osgDB/Registry>
|
||||
#include <osgDB/FileNameUtils>
|
||||
@@ -49,6 +50,12 @@ public:
|
||||
supportsExtension("sav", "MPEG-4");
|
||||
supportsExtension("3gp", "MPEG-4");
|
||||
supportsExtension("sdp", "MPEG-4");
|
||||
|
||||
supportsOption("format", "Force setting input format (e.g. vfwcap for Windows webcam)");
|
||||
supportsOption("pixel_format", "Set pixel format");
|
||||
supportsOption("frame_size", "Set frame size (e.g. 320x240)");
|
||||
supportsOption("frame_rate", "Set frame rate (e.g. 25)");
|
||||
supportsOption("audio_sample_rate", "Set audio sampling rate (e.g. 44100)");
|
||||
|
||||
#ifdef USE_AV_LOCK_MANAGER
|
||||
// enable thread locking
|
||||
@@ -75,9 +82,16 @@ public:
|
||||
|
||||
if (filename.compare(0, 5, "/dev/")==0)
|
||||
{
|
||||
return readImageStream(filename, options);
|
||||
return readImageStream(filename, NULL);
|
||||
}
|
||||
|
||||
|
||||
osg::ref_ptr<osgFFmpeg::FFmpegParameters> parameters(new osgFFmpeg::FFmpegParameters);
|
||||
parseOptions(parameters.get(), options);
|
||||
if (parameters->isFormatAvailable())
|
||||
{
|
||||
return readImageStream(filename, parameters.get());
|
||||
}
|
||||
|
||||
if (! acceptsExtension(ext))
|
||||
return ReadResult::FILE_NOT_HANDLED;
|
||||
|
||||
@@ -88,22 +102,36 @@ public:
|
||||
if (path.empty())
|
||||
return ReadResult::FILE_NOT_FOUND;
|
||||
|
||||
return readImageStream(path, options);
|
||||
return readImageStream(path, parameters.get());
|
||||
}
|
||||
|
||||
ReadResult readImageStream(const std::string& filename, const osgDB::ReaderWriter::Options * options) const
|
||||
ReadResult readImageStream(const std::string& filename, osgFFmpeg::FFmpegParameters* parameters) const
|
||||
{
|
||||
OSG_INFO << "ReaderWriterFFmpeg::readImage " << filename << std::endl;
|
||||
|
||||
osg::ref_ptr<osgFFmpeg::FFmpegImageStream> image_stream(new osgFFmpeg::FFmpegImageStream);
|
||||
|
||||
if (! image_stream->open(filename))
|
||||
if (! image_stream->open(filename, parameters))
|
||||
return ReadResult::FILE_NOT_HANDLED;
|
||||
|
||||
return image_stream.release();
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
void parseOptions(osgFFmpeg::FFmpegParameters* parameters, const osgDB::ReaderWriter::Options * options) const
|
||||
{
|
||||
if (options && options->getNumPluginStringData()>0)
|
||||
{
|
||||
const FormatDescriptionMap& supportedOptList = supportedOptions();
|
||||
for (FormatDescriptionMap::const_iterator itr = supportedOptList.begin();
|
||||
itr != supportedOptList.end(); ++itr)
|
||||
{
|
||||
const std::string& name = itr->first;
|
||||
parameters->parse(name, options->getPluginStringData(name));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef USE_AV_LOCK_MANAGER
|
||||
static int lockMgr(void **mutex, enum AVLockOp op)
|
||||
|
||||
Reference in New Issue
Block a user