|
Lines 1-284
Link Here
|
| 1 |
Patch by lu_zero |
|
|
| 2 |
https://bugs.gentoo.org/show_bug.cgi?id=439606 |
| 3 |
upstream svn rev. 13335 contains similar changes. |
| 4 |
no need to upstream this patch. |
| 5 |
|
| 6 |
diff -burN CMakeModules/FindFFmpeg.cmake CMakeModules/FindFFmpeg.cmake |
| 7 |
--- CMakeModules/FindFFmpeg.cmake 2011-04-19 13:40:22.000000000 +0200 |
| 8 |
+++ CMakeModules/FindFFmpeg.cmake 2012-11-22 13:59:28.303401170 +0100 |
| 9 |
@@ -131,20 +131,16 @@ |
| 10 |
SET(FFMPEG_FOUND "YES") |
| 11 |
|
| 12 |
SET(FFMPEG_INCLUDE_DIRS |
| 13 |
- ${FFMPEG_LIBAVFORMAT_INCLUDE_DIRS} ${FFMPEG_LIBAVFORMAT_INCLUDE_DIRS}/libavformat |
| 14 |
- ${FFMPEG_LIBAVDEVICE_INCLUDE_DIRS} ${FFMPEG_LIBAVDEVICE_INCLUDE_DIRS}/libavdevice |
| 15 |
- ${FFMPEG_LIBAVCODEC_INCLUDE_DIRS} ${FFMPEG_LIBAVCODEC_INCLUDE_DIRS}/libavcodec |
| 16 |
- ${FFMPEG_LIBAVUTIL_INCLUDE_DIRS} ${FFMPEG_LIBAVUTIL_INCLUDE_DIRS}/libavutil |
| 17 |
+ ${FFMPEG_LIBAVFORMAT_INCLUDE_DIRS} |
| 18 |
+ ${FFMPEG_LIBAVDEVICE_INCLUDE_DIRS} |
| 19 |
+ ${FFMPEG_LIBAVCODEC_INCLUDE_DIRS} |
| 20 |
+ ${FFMPEG_LIBAVUTIL_INCLUDE_DIRS} |
| 21 |
) |
| 22 |
|
| 23 |
IF (FFMPEG_STDINT_INCLUDE_DIR) |
| 24 |
SET(FFMPEG_INCLUDE_DIRS |
| 25 |
${FFMPEG_INCLUDE_DIRS} |
| 26 |
${FFMPEG_STDINT_INCLUDE_DIR} |
| 27 |
- ${FFMPEG_STDINT_INCLUDE_DIR}/libavformat |
| 28 |
- ${FFMPEG_STDINT_INCLUDE_DIR}/libavdevice |
| 29 |
- ${FFMPEG_STDINT_INCLUDE_DIR}/libavcodec |
| 30 |
- ${FFMPEG_STDINT_INCLUDE_DIR}/libavutil |
| 31 |
) |
| 32 |
ENDIF() |
| 33 |
|
| 34 |
diff -burN src/osgPlugins/ffmpeg/FFmpegDecoderAudio.cpp src/osgPlugins/ffmpeg/FFmpegDecoderAudio.cpp |
| 35 |
--- src/osgPlugins/ffmpeg/FFmpegDecoderAudio.cpp 2011-04-19 13:40:22.000000000 +0200 |
| 36 |
+++ src/osgPlugins/ffmpeg/FFmpegDecoderAudio.cpp 2012-11-22 15:03:53.668601596 +0100 |
| 37 |
@@ -89,7 +89,7 @@ |
| 38 |
// m_context->flags |= CODEC_FLAG_TRUNCATED; |
| 39 |
|
| 40 |
// Open codec |
| 41 |
- if (avcodec_open(m_context, p_codec) < 0) |
| 42 |
+ if (avcodec_open2(m_context, p_codec, NULL) < 0) |
| 43 |
throw std::runtime_error("avcodec_open() failed"); |
| 44 |
} |
| 45 |
|
| 46 |
Binary files src/osgPlugins/ffmpeg/.FFmpegDecoderAudio.cpp.swp and src/osgPlugins/ffmpeg/.FFmpegDecoderAudio.cpp.swp differ |
| 47 |
diff -burN src/osgPlugins/ffmpeg/FFmpegDecoder.cpp src/osgPlugins/ffmpeg/FFmpegDecoder.cpp |
| 48 |
--- src/osgPlugins/ffmpeg/FFmpegDecoder.cpp 2011-07-15 12:25:12.000000000 +0200 |
| 49 |
+++ src/osgPlugins/ffmpeg/FFmpegDecoder.cpp 2012-11-22 15:59:39.569775078 +0100 |
| 50 |
@@ -64,21 +64,12 @@ |
| 51 |
|
| 52 |
OSG_NOTICE<<"Attempting to stream "<<filename<<std::endl; |
| 53 |
|
| 54 |
- AVFormatParameters formatParams; |
| 55 |
- memset(&formatParams, 0, sizeof(AVFormatParameters)); |
| 56 |
AVInputFormat *iformat; |
| 57 |
+ AVDictionary *options = NULL; |
| 58 |
|
| 59 |
- formatParams.channel = 0; |
| 60 |
- formatParams.standard = 0; |
| 61 |
-#if 1 |
| 62 |
- formatParams.width = 320; |
| 63 |
- formatParams.height = 240; |
| 64 |
-#else |
| 65 |
- formatParams.width = 640; |
| 66 |
- formatParams.height = 480; |
| 67 |
-#endif |
| 68 |
- formatParams.time_base.num = 1; |
| 69 |
- formatParams.time_base.den = 30; |
| 70 |
+ av_dict_set(&options, "video_size", "320x240", 0); |
| 71 |
+ |
| 72 |
+ av_dict_set(&options, "framerate", "1/30", 0); |
| 73 |
|
| 74 |
std::string format = "video4linux2"; |
| 75 |
iformat = av_find_input_format(format.c_str()); |
| 76 |
@@ -92,7 +83,7 @@ |
| 77 |
OSG_NOTICE<<"Failed to find input format: "<<format<<std::endl; |
| 78 |
} |
| 79 |
|
| 80 |
- int error = av_open_input_file(&p_format_context, filename.c_str(), iformat, 0, &formatParams); |
| 81 |
+ int error = avformat_open_input(&p_format_context, filename.c_str(), iformat, &options); |
| 82 |
if (error != 0) |
| 83 |
{ |
| 84 |
std::string error_str; |
| 85 |
@@ -110,21 +101,21 @@ |
| 86 |
default: error_str = "Unknown error"; break; |
| 87 |
} |
| 88 |
|
| 89 |
- throw std::runtime_error("av_open_input_file() failed : " + error_str); |
| 90 |
+ throw std::runtime_error("avformat_open_input() failed : " + error_str); |
| 91 |
} |
| 92 |
} |
| 93 |
else |
| 94 |
{ |
| 95 |
AVInputFormat* av_format = (parameters ? parameters->getFormat() : 0); |
| 96 |
- AVFormatParameters* av_params = (parameters ? parameters->getFormatParameter() : 0); |
| 97 |
- if (av_open_input_file(&p_format_context, filename.c_str(), av_format, 0, av_params) !=0 ) |
| 98 |
+ AVDictionary* av_options = (parameters ? parameters->getOptions() : NULL); |
| 99 |
+ if (avformat_open_input(&p_format_context, filename.c_str(), av_format, &av_options) !=0 ) |
| 100 |
throw std::runtime_error("av_open_input_file() failed"); |
| 101 |
} |
| 102 |
|
| 103 |
m_format_context.reset(p_format_context); |
| 104 |
|
| 105 |
// Retrieve stream info |
| 106 |
- if (av_find_stream_info(p_format_context) < 0) |
| 107 |
+ if (avformat_find_stream_info(p_format_context, NULL) < 0) |
| 108 |
throw std::runtime_error("av_find_stream_info() failed"); |
| 109 |
|
| 110 |
m_duration = double(m_format_context->duration) / AV_TIME_BASE; |
| 111 |
@@ -134,7 +125,7 @@ |
| 112 |
m_clocks.reset(m_start); |
| 113 |
|
| 114 |
// Dump info to stderr |
| 115 |
- dump_format(p_format_context, 0, filename.c_str(), false); |
| 116 |
+ av_dump_format(p_format_context, 0, filename.c_str(), false); |
| 117 |
|
| 118 |
// Find and open the first video and audio streams (note that audio stream is optional and only opened if possible) |
| 119 |
|
| 120 |
@@ -292,7 +283,7 @@ |
| 121 |
// Read the next frame packet |
| 122 |
if (av_read_frame(m_format_context.get(), &packet) < 0) |
| 123 |
{ |
| 124 |
- if (url_ferror(m_format_context->pb) == 0) |
| 125 |
+ if (m_format_context->pb->eof_reached == 0) |
| 126 |
end_of_stream = true; |
| 127 |
else |
| 128 |
throw std::runtime_error("av_read_frame() failed"); |
| 129 |
Binary files src/osgPlugins/ffmpeg/.FFmpegDecoder.cpp.swp and src/osgPlugins/ffmpeg/.FFmpegDecoder.cpp.swp differ |
| 130 |
diff -burN src/osgPlugins/ffmpeg/FFmpegDecoder.hpp src/osgPlugins/ffmpeg/FFmpegDecoder.hpp |
| 131 |
--- src/osgPlugins/ffmpeg/FFmpegDecoder.hpp 2011-04-19 13:40:22.000000000 +0200 |
| 132 |
+++ src/osgPlugins/ffmpeg/FFmpegDecoder.hpp 2012-11-22 15:59:18.895774005 +0100 |
| 133 |
@@ -46,8 +46,8 @@ |
| 134 |
{ |
| 135 |
if (_ptr) |
| 136 |
{ |
| 137 |
- OSG_NOTICE<<"Calling av_close_input_file("<<_ptr<<")"<<std::endl; |
| 138 |
- av_close_input_file(_ptr); |
| 139 |
+ OSG_NOTICE<<"Calling avformat_close_input("<<_ptr<<")"<<std::endl; |
| 140 |
+ avformat_close_input(&_ptr); |
| 141 |
} |
| 142 |
_ptr = 0; |
| 143 |
} |
| 144 |
@@ -151,8 +151,7 @@ |
| 145 |
|
| 146 |
inline double FFmpegDecoder::creation_time() const |
| 147 |
{ |
| 148 |
- if(m_format_context) return m_format_context->timestamp; |
| 149 |
- else return HUGE_VAL; |
| 150 |
+ return HUGE_VAL; |
| 151 |
} |
| 152 |
|
| 153 |
inline double FFmpegDecoder::duration() const |
| 154 |
diff -burN src/osgPlugins/ffmpeg/FFmpegDecoderVideo.cpp src/osgPlugins/ffmpeg/FFmpegDecoderVideo.cpp |
| 155 |
--- src/osgPlugins/ffmpeg/FFmpegDecoderVideo.cpp 2011-04-19 13:40:22.000000000 +0200 |
| 156 |
+++ src/osgPlugins/ffmpeg/FFmpegDecoderVideo.cpp 2012-11-22 16:01:30.906780849 +0100 |
| 157 |
@@ -83,7 +83,7 @@ |
| 158 |
m_context = stream->codec; |
| 159 |
|
| 160 |
// Trust the video size given at this point |
| 161 |
- // (avcodec_open seems to sometimes return a 0x0 size) |
| 162 |
+ // (avcodec_open2 seems to sometimes return a 0x0 size) |
| 163 |
m_width = m_context->width; |
| 164 |
m_height = m_context->height; |
| 165 |
findAspectRatio(); |
| 166 |
@@ -105,8 +105,8 @@ |
| 167 |
// m_context->flags |= CODEC_FLAG_TRUNCATED; |
| 168 |
|
| 169 |
// Open codec |
| 170 |
- if (avcodec_open(m_context, m_codec) < 0) |
| 171 |
- throw std::runtime_error("avcodec_open() failed"); |
| 172 |
+ if (avcodec_open2(m_context, m_codec, NULL) < 0) |
| 173 |
+ throw std::runtime_error("avcodec_open2() failed"); |
| 174 |
|
| 175 |
// Allocate video frame |
| 176 |
m_frame.reset(avcodec_alloc_frame()); |
| 177 |
Binary files src/osgPlugins/ffmpeg/.FFmpegDecoderVideo.cpp.swp and src/osgPlugins/ffmpeg/.FFmpegDecoderVideo.cpp.swp differ |
| 178 |
diff -burN src/osgPlugins/ffmpeg/FFmpegParameters.cpp src/osgPlugins/ffmpeg/FFmpegParameters.cpp |
| 179 |
--- src/osgPlugins/ffmpeg/FFmpegParameters.cpp 2011-07-15 12:25:12.000000000 +0200 |
| 180 |
+++ src/osgPlugins/ffmpeg/FFmpegParameters.cpp 2012-11-22 17:20:09.019025477 +0100 |
| 181 |
@@ -8,7 +8,7 @@ |
| 182 |
#if LIBAVCODEC_VERSION_MAJOR >= 53 |
| 183 |
extern "C" |
| 184 |
{ |
| 185 |
- #include <parseutils.h> |
| 186 |
+ #include <libavutil/parseutils.h> |
| 187 |
} |
| 188 |
#define av_parse_video_frame_size av_parse_video_size |
| 189 |
#define av_parse_video_frame_rate av_parse_video_rate |
| 190 |
@@ -19,7 +19,7 @@ |
| 191 |
|
| 192 |
extern "C" |
| 193 |
{ |
| 194 |
- #include <pixdesc.h> |
| 195 |
+ #include <libavutil/pixdesc.h> |
| 196 |
} |
| 197 |
|
| 198 |
inline PixelFormat osg_av_get_pix_fmt(const char *name) { return av_get_pix_fmt(name); } |
| 199 |
@@ -34,14 +34,15 @@ |
| 200 |
|
| 201 |
|
| 202 |
FFmpegParameters::FFmpegParameters() : |
| 203 |
- m_format(0) |
| 204 |
-{ |
| 205 |
- memset(&m_parameters, 0, sizeof(m_parameters)); |
| 206 |
-} |
| 207 |
+ m_format(0), |
| 208 |
+ m_options(NULL) |
| 209 |
+{} |
| 210 |
|
| 211 |
|
| 212 |
FFmpegParameters::~FFmpegParameters() |
| 213 |
-{} |
| 214 |
+{ |
| 215 |
+ av_dict_free(&m_options); |
| 216 |
+} |
| 217 |
|
| 218 |
|
| 219 |
void FFmpegParameters::parse(const std::string& name, const std::string& value) |
| 220 |
@@ -59,40 +60,19 @@ |
| 221 |
} |
| 222 |
else if (name == "pixel_format") |
| 223 |
{ |
| 224 |
- m_parameters.pix_fmt = osg_av_get_pix_fmt(value.c_str()); |
| 225 |
+ av_dict_set(&m_options, "pixel_format", value.c_str(), 0); |
| 226 |
} |
| 227 |
else if (name == "frame_size") |
| 228 |
{ |
| 229 |
- int frame_width = 0, frame_height = 0; |
| 230 |
- if (av_parse_video_frame_size(&frame_width, &frame_height, value.c_str()) < 0) |
| 231 |
- { |
| 232 |
- OSG_NOTICE<<"Failed to apply frame size: "<<value.c_str()<<std::endl; |
| 233 |
- return; |
| 234 |
- } |
| 235 |
- if ((frame_width % 2) != 0 || (frame_height % 2) != 0) |
| 236 |
- { |
| 237 |
- OSG_NOTICE<<"Frame size must be a multiple of 2: "<<frame_width<<"x"<<frame_height<<std::endl; |
| 238 |
- return; |
| 239 |
- } |
| 240 |
- m_parameters.width = frame_width; |
| 241 |
- m_parameters.height = frame_height; |
| 242 |
+ av_dict_set(&m_options, "video_size", value.c_str(), 0); |
| 243 |
} |
| 244 |
else if (name == "frame_rate") |
| 245 |
{ |
| 246 |
- AVRational frame_rate; |
| 247 |
- if (av_parse_video_frame_rate(&frame_rate, value.c_str()) < 0) |
| 248 |
- { |
| 249 |
- OSG_NOTICE<<"Failed to apply frame rate: "<<value.c_str()<<std::endl; |
| 250 |
- return; |
| 251 |
- } |
| 252 |
- m_parameters.time_base.den = frame_rate.num; |
| 253 |
- m_parameters.time_base.num = frame_rate.den; |
| 254 |
+ av_dict_set(&m_options, "framerate", value.c_str(), 0); |
| 255 |
} |
| 256 |
else if (name == "audio_sample_rate") |
| 257 |
{ |
| 258 |
- int audio_sample_rate = 44100; |
| 259 |
- std::stringstream ss(value); ss >> audio_sample_rate; |
| 260 |
- m_parameters.sample_rate = audio_sample_rate; |
| 261 |
+ av_dict_set(&m_options, "sample_rate", value.c_str(), 0); |
| 262 |
} |
| 263 |
} |
| 264 |
|
| 265 |
diff -burN src/osgPlugins/ffmpeg/FFmpegParameters.hpp src/osgPlugins/ffmpeg/FFmpegParameters.hpp |
| 266 |
--- src/osgPlugins/ffmpeg/FFmpegParameters.hpp 2011-04-19 13:40:22.000000000 +0200 |
| 267 |
+++ src/osgPlugins/ffmpeg/FFmpegParameters.hpp 2012-11-22 15:23:27.490662455 +0100 |
| 268 |
@@ -21,14 +21,14 @@ |
| 269 |
bool isFormatAvailable() const { return m_format!=NULL; } |
| 270 |
|
| 271 |
AVInputFormat* getFormat() { return m_format; } |
| 272 |
- AVFormatParameters* getFormatParameter() { return &m_parameters; } |
| 273 |
+ AVDictionary* getOptions() { return m_options; } |
| 274 |
|
| 275 |
void parse(const std::string& name, const std::string& value); |
| 276 |
|
| 277 |
protected: |
| 278 |
|
| 279 |
AVInputFormat* m_format; |
| 280 |
- AVFormatParameters m_parameters; |
| 281 |
+ AVDictionary* m_options; |
| 282 |
}; |
| 283 |
|
| 284 |
|