Lines 64-84
Link Here
|
64 |
|
64 |
|
65 |
OSG_NOTICE<<"Attempting to stream "<<filename<<std::endl; |
65 |
OSG_NOTICE<<"Attempting to stream "<<filename<<std::endl; |
66 |
|
66 |
|
67 |
AVFormatParameters formatParams; |
|
|
68 |
memset(&formatParams, 0, sizeof(AVFormatParameters)); |
69 |
AVInputFormat *iformat; |
67 |
AVInputFormat *iformat; |
|
|
68 |
AVDictionary *options = NULL; |
70 |
|
69 |
|
71 |
formatParams.channel = 0; |
70 |
av_dict_set(&options, "video_size", "320x240", 0); |
72 |
formatParams.standard = 0; |
71 |
|
73 |
#if 1 |
72 |
av_dict_set(&options, "framerate", "1/30", 0); |
74 |
formatParams.width = 320; |
|
|
75 |
formatParams.height = 240; |
76 |
#else |
77 |
formatParams.width = 640; |
78 |
formatParams.height = 480; |
79 |
#endif |
80 |
formatParams.time_base.num = 1; |
81 |
formatParams.time_base.den = 30; |
82 |
|
73 |
|
83 |
std::string format = "video4linux2"; |
74 |
std::string format = "video4linux2"; |
84 |
iformat = av_find_input_format(format.c_str()); |
75 |
iformat = av_find_input_format(format.c_str()); |
Lines 92-98
Link Here
|
92 |
OSG_NOTICE<<"Failed to find input format: "<<format<<std::endl; |
83 |
OSG_NOTICE<<"Failed to find input format: "<<format<<std::endl; |
93 |
} |
84 |
} |
94 |
|
85 |
|
95 |
int error = av_open_input_file(&p_format_context, filename.c_str(), iformat, 0, &formatParams); |
86 |
int error = avformat_open_input(&p_format_context, filename.c_str(), iformat, &options); |
96 |
if (error != 0) |
87 |
if (error != 0) |
97 |
{ |
88 |
{ |
98 |
std::string error_str; |
89 |
std::string error_str; |
Lines 110-130
Link Here
|
110 |
default: error_str = "Unknown error"; break; |
101 |
default: error_str = "Unknown error"; break; |
111 |
} |
102 |
} |
112 |
|
103 |
|
113 |
throw std::runtime_error("av_open_input_file() failed : " + error_str); |
104 |
throw std::runtime_error("avformat_open_input() failed : " + error_str); |
114 |
} |
105 |
} |
115 |
} |
106 |
} |
116 |
else |
107 |
else |
117 |
{ |
108 |
{ |
118 |
AVInputFormat* av_format = (parameters ? parameters->getFormat() : 0); |
109 |
AVInputFormat* av_format = (parameters ? parameters->getFormat() : 0); |
119 |
AVFormatParameters* av_params = (parameters ? parameters->getFormatParameter() : 0); |
110 |
AVDictionary* av_options = (parameters ? parameters->getOptions() : NULL); |
120 |
if (av_open_input_file(&p_format_context, filename.c_str(), av_format, 0, av_params) !=0 ) |
111 |
if (avformat_open_input(&p_format_context, filename.c_str(), av_format, &av_options) !=0 ) |
121 |
throw std::runtime_error("av_open_input_file() failed"); |
112 |
throw std::runtime_error("av_open_input_file() failed"); |
122 |
} |
113 |
} |
123 |
|
114 |
|
124 |
m_format_context.reset(p_format_context); |
115 |
m_format_context.reset(p_format_context); |
125 |
|
116 |
|
126 |
// Retrieve stream info |
117 |
// Retrieve stream info |
127 |
if (av_find_stream_info(p_format_context) < 0) |
118 |
if (avformat_find_stream_info(p_format_context, NULL) < 0) |
128 |
throw std::runtime_error("av_find_stream_info() failed"); |
119 |
throw std::runtime_error("av_find_stream_info() failed"); |
129 |
|
120 |
|
130 |
m_duration = double(m_format_context->duration) / AV_TIME_BASE; |
121 |
m_duration = double(m_format_context->duration) / AV_TIME_BASE; |
Lines 134-140
Link Here
|
134 |
m_clocks.reset(m_start); |
125 |
m_clocks.reset(m_start); |
135 |
|
126 |
|
136 |
// Dump info to stderr |
127 |
// Dump info to stderr |
137 |
dump_format(p_format_context, 0, filename.c_str(), false); |
128 |
av_dump_format(p_format_context, 0, filename.c_str(), false); |
138 |
|
129 |
|
139 |
// Find and open the first video and audio streams (note that audio stream is optional and only opened if possible) |
130 |
// Find and open the first video and audio streams (note that audio stream is optional and only opened if possible) |
140 |
|
131 |
|
Lines 292-298
Link Here
|
292 |
// Read the next frame packet |
283 |
// Read the next frame packet |
293 |
if (av_read_frame(m_format_context.get(), &packet) < 0) |
284 |
if (av_read_frame(m_format_context.get(), &packet) < 0) |
294 |
{ |
285 |
{ |
295 |
if (url_ferror(m_format_context->pb) == 0) |
286 |
if (m_format_context->pb->eof_reached == 0) |
296 |
end_of_stream = true; |
287 |
end_of_stream = true; |
297 |
else |
288 |
else |
298 |
throw std::runtime_error("av_read_frame() failed"); |
289 |
throw std::runtime_error("av_read_frame() failed"); |