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

This commit is contained in:
Robert Osfield
2009-04-11 06:16:37 +00:00
parent bc39983030
commit 562f84668f
3 changed files with 43 additions and 14 deletions

View File

@@ -2,12 +2,13 @@
#include "FFmpegDecoder.hpp"
#include <osg/Notify>
#include <osgDB/FileNameUtils>
#include <cassert>
#include <limits>
#include <stdexcept>
#include <string.h>
#include <iostream>
namespace osgFFmpeg {
@@ -64,19 +65,38 @@ bool FFmpegDecoder::open(const std::string & filename)
formatParams.time_base.num = 1;
formatParams.time_base.den = 30;
iformat = av_find_input_format("video4linux2");
std::string format = "video4linux2";
iformat = av_find_input_format(format.c_str());
if (iformat)
{
osg::notify(osg::NOTICE)<<"Found input format"<<std::endl;
osg::notify(osg::NOTICE)<<"Found input format: "<<format<<std::endl;
}
else
{
osg::notify(osg::NOTICE)<<"Failed to find input_format"<<std::endl;
osg::notify(osg::NOTICE)<<"Failed to find input format: "<<format<<std::endl;
}
if (av_open_input_file(&p_format_context, filename.c_str(), iformat, 0, &formatParams) != 0)
throw std::runtime_error("av_open_input_file() failed");
int error = av_open_input_file(&p_format_context, filename.c_str(), iformat, 0, &formatParams);
if (error != 0)
{
std::string error_str;
switch (error)
{
//case AVERROR_UNKNOWN: error_str = "AVERROR_UNKNOWN"; break; // same value as AVERROR_INVALIDDATA
case AVERROR_IO: error_str = "AVERROR_IO"; break;
case AVERROR_NUMEXPECTED: error_str = "AVERROR_NUMEXPECTED"; break;
case AVERROR_INVALIDDATA: error_str = "AVERROR_INVALIDDATA"; break;
case AVERROR_NOMEM: error_str = "AVERROR_NOMEM"; break;
case AVERROR_NOFMT: error_str = "AVERROR_NOFMT"; break;
case AVERROR_NOTSUPP: error_str = "AVERROR_NOTSUPP"; break;
case AVERROR_NOENT: error_str = "AVERROR_NOENT"; break;
case AVERROR_PATCHWELCOME: error_str = "AVERROR_PATCHWELCOME"; break;
default: error_str = "Unknown error"; break;
}
throw std::runtime_error("av_open_input_file() failed : " + error_str);
}
}
else
{

View File

@@ -6,6 +6,9 @@
extern "C"
{
#define __STDC_CONSTANT_MACROS
#ifdef WIN32
#include <errno.h> // for error codes defined in avformat.h
#endif
#include <stdint.h>
#include <avcodec.h>
#include <avformat.h>

View File

@@ -29,16 +29,22 @@ public:
ReaderWriterFFmpeg()
{
supportsProtocol("http","Read video/audio from http using ffmpeg.");
supportsProtocol("rtsp","Read video/audio from rtsp using ffmpeg.");
supportsExtension("ffmpeg", "");
supportsExtension("avi", "");
supportsExtension("flv", "");
supportsExtension("mov", "");
supportsExtension("ogg", "Theora movie format");
supportsExtension("mpg", "Mpeg movie format");
supportsExtension("mpv", "Mpeg movie format");
supportsExtension("wmv", "Windows Media Video format");
supportsExtension("mkv", "Matroska");
supportsExtension("avi", "");
supportsExtension("flv", "Flash video");
supportsExtension("mov", "Quicktime");
supportsExtension("ogg", "Theora movie format");
supportsExtension("mpg", "Mpeg movie format");
supportsExtension("mpv", "Mpeg movie format");
supportsExtension("wmv", "Windows Media Video format");
supportsExtension("mkv", "Matroska");
supportsExtension("mjpeg", "Motion JPEG");
supportsExtension("mp4", "MPEG-4");
supportsExtension("sav", "MPEG-4");
supportsExtension("3gp", "MPEG-4");
supportsExtension("sdp", "MPEG-4");
// Register all FFmpeg formats/codecs
av_register_all();