| 1 | |
|---|
| 2 | |
|---|
| 3 | |
|---|
| 4 | |
|---|
| 5 | |
|---|
| 6 | |
|---|
| 7 | |
|---|
| 8 | |
|---|
| 9 | |
|---|
| 10 | |
|---|
| 11 | |
|---|
| 12 | |
|---|
| 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 | |
|---|
| 24 | |
|---|
| 25 | class ReaderWriterFFmpeg : public osgDB::ReaderWriter |
|---|
| 26 | { |
|---|
| 27 | public: |
|---|
| 28 | |
|---|
| 29 | ReaderWriterFFmpeg() |
|---|
| 30 | { |
|---|
| 31 | supportsProtocol("http","Read video/audio from http using ffmpeg."); |
|---|
| 32 | supportsProtocol("rtsp","Read video/audio from rtsp using ffmpeg."); |
|---|
| 33 | |
|---|
| 34 | supportsExtension("ffmpeg", ""); |
|---|
| 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"); |
|---|
| 48 | |
|---|
| 49 | |
|---|
| 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 | { |
|---|
| 65 | const std::string ext = osgDB::getLowerCaseFileExtension(filename); |
|---|
| 66 | if (ext=="ffmpeg") return readImage(osgDB::getNameLessExtension(filename),options); |
|---|
| 67 | |
|---|
| 68 | if (filename.compare(0, 5, "/dev/")==0) |
|---|
| 69 | { |
|---|
| 70 | return readImageStream(filename, options); |
|---|
| 71 | } |
|---|
| 72 | |
|---|
| 73 | if (! acceptsExtension(ext)) |
|---|
| 74 | return ReadResult::FILE_NOT_HANDLED; |
|---|
| 75 | |
|---|
| 76 | const std::string path = osgDB::containsServerAddress(filename) ? |
|---|
| 77 | filename : |
|---|
| 78 | osgDB::findDataFile(filename, options); |
|---|
| 79 | |
|---|
| 80 | if (path.empty()) |
|---|
| 81 | return ReadResult::FILE_NOT_FOUND; |
|---|
| 82 | |
|---|
| 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; |
|---|
| 89 | |
|---|
| 90 | osg::ref_ptr<osgFFmpeg::FFmpegImageStream> image_stream(new osgFFmpeg::FFmpegImageStream); |
|---|
| 91 | |
|---|
| 92 | if (! image_stream->open(filename)) |
|---|
| 93 | return ReadResult::FILE_NOT_HANDLED; |
|---|
| 94 | |
|---|
| 95 | return image_stream.release(); |
|---|
| 96 | } |
|---|
| 97 | |
|---|
| 98 | private: |
|---|
| 99 | |
|---|
| 100 | }; |
|---|
| 101 | |
|---|
| 102 | |
|---|
| 103 | |
|---|
| 104 | REGISTER_OSGPLUGIN(ffmpeg, ReaderWriterFFmpeg) |
|---|