Restructed the call to avformat_open_input to provide more information.

This commit is contained in:
Robert Osfield 2013-11-06 09:20:35 +00:00
parent 2b3665f010
commit ef3a65b93f

View File

@ -62,6 +62,7 @@ bool FFmpegDecoder::open(const std::string & filename, FFmpegParameters* paramet
{ {
// Open video file // Open video file
AVFormatContext * p_format_context = 0; AVFormatContext * p_format_context = 0;
AVInputFormat *iformat = 0;
if (filename.compare(0, 5, "/dev/")==0) if (filename.compare(0, 5, "/dev/")==0)
{ {
@ -72,13 +73,11 @@ bool FFmpegDecoder::open(const std::string & filename, FFmpegParameters* paramet
OSG_NOTICE<<"Attempting to stream "<<filename<<std::endl; OSG_NOTICE<<"Attempting to stream "<<filename<<std::endl;
AVInputFormat *iformat; if (parameters)
#if 1 {
av_dict_set(parameters->getOptions(), "video_size", "320x240", 0);
#else
av_dict_set(parameters->getOptions(), "video_size", "640x480", 0); av_dict_set(parameters->getOptions(), "video_size", "640x480", 0);
#endif
av_dict_set(parameters->getOptions(), "framerate", "1:30", 0); av_dict_set(parameters->getOptions(), "framerate", "1:30", 0);
}
std::string format = "video4linux2"; std::string format = "video4linux2";
iformat = av_find_input_format(format.c_str()); iformat = av_find_input_format(format.c_str());
@ -92,6 +91,19 @@ bool FFmpegDecoder::open(const std::string & filename, FFmpegParameters* paramet
OSG_NOTICE<<"Failed to find input format: "<<format<<std::endl; OSG_NOTICE<<"Failed to find input format: "<<format<<std::endl;
} }
#endif
}
else
{
iformat = parameters ? parameters->getFormat() : 0;
AVIOContext* context = parameters ? parameters->getContext() : 0;
if (context != NULL)
{
p_format_context = avformat_alloc_context();
p_format_context->pb = context;
}
}
int error = avformat_open_input(&p_format_context, filename.c_str(), iformat, parameters->getOptions()); int error = avformat_open_input(&p_format_context, filename.c_str(), iformat, parameters->getOptions());
if (error != 0) if (error != 0)
{ {
@ -112,20 +124,6 @@ bool FFmpegDecoder::open(const std::string & filename, FFmpegParameters* paramet
throw std::runtime_error("av_open_input_file() failed : " + error_str); throw std::runtime_error("av_open_input_file() failed : " + error_str);
} }
#endif
}
else
{
AVInputFormat* iformat = (parameters ? parameters->getFormat() : 0);
AVIOContext* context = parameters->getContext();
if (context != NULL)
{
p_format_context = avformat_alloc_context();
p_format_context->pb = context;
}
if (avformat_open_input(&p_format_context, filename.c_str(), iformat, parameters->getOptions()) != 0)
throw std::runtime_error("av_open_input_file() failed");
}
m_format_context.reset(p_format_context); m_format_context.reset(p_format_context);