Mercurial > mplayer.hg
comparison libmpdemux/demux_rtp_codec.cpp @ 21983:a6b624360aef
better autodetection of framerate in case of h264; it works correctly with b-frames.
Patch by Eugen Hoyos (cehoyos ag or at)
author | nicodvb |
---|---|
date | Tue, 23 Jan 2007 22:26:13 +0000 |
parents | e86bb13ec44b |
children | c9214f2c30c4 |
comparison
equal
deleted
inserted
replaced
21982:fa66a03e8920 | 21983:a6b624360aef |
---|---|
2 ////////// and the "LIVE555 Streaming Media" libraries: | 2 ////////// and the "LIVE555 Streaming Media" libraries: |
3 | 3 |
4 #include "demux_rtp_internal.h" | 4 #include "demux_rtp_internal.h" |
5 extern "C" { | 5 extern "C" { |
6 #include <limits.h> | 6 #include <limits.h> |
7 #include <math.h> | |
7 #include "stheader.h" | 8 #include "stheader.h" |
8 } | 9 } |
9 | 10 |
10 static void | 11 static void |
11 needVideoFrameRate(demuxer_t* demuxer, MediaSubsession* subsession); // forward | 12 needVideoFrameRate(demuxer_t* demuxer, MediaSubsession* subsession); // forward |
245 // Keep looking at incoming frames until we see two with different, | 246 // Keep looking at incoming frames until we see two with different, |
246 // non-zero "pts" timestamps: | 247 // non-zero "pts" timestamps: |
247 unsigned char* packetData; unsigned packetDataLen; | 248 unsigned char* packetData; unsigned packetDataLen; |
248 float lastPTS = 0.0, curPTS; | 249 float lastPTS = 0.0, curPTS; |
249 unsigned const maxNumFramesToWaitFor = 300; | 250 unsigned const maxNumFramesToWaitFor = 300; |
251 int lastfps = 0; | |
250 for (unsigned i = 0; i < maxNumFramesToWaitFor; ++i) { | 252 for (unsigned i = 0; i < maxNumFramesToWaitFor; ++i) { |
251 if (!awaitRTPPacket(demuxer, d_video, packetData, packetDataLen, curPTS)) { | 253 if (!awaitRTPPacket(demuxer, d_video, packetData, packetDataLen, curPTS)) { |
252 break; | 254 break; |
253 } | 255 } |
254 | 256 |
255 if (curPTS > lastPTS && lastPTS != 0.0) { | 257 if (curPTS != lastPTS && lastPTS != 0.0) { |
256 // Use the difference between these two "pts"s to guess the frame rate. | 258 // Use the difference between these two "pts"s to guess the frame rate. |
257 // (should really check that there were no missing frames inbetween)##### | 259 // (should really check that there were no missing frames inbetween)##### |
258 // Guess the frame rate as an integer. If it's not, use "-fps" instead. | 260 // Guess the frame rate as an integer. If it's not, use "-fps" instead. |
259 fps = (int)(1/(curPTS-lastPTS) + 0.5); // rounding | 261 fps = (int)(1/fabs(curPTS-lastPTS) + 0.5); // rounding |
262 if (fps == lastfps) { | |
260 fprintf(stderr, "demux_rtp: Guessed the video frame rate as %d frames-per-second.\n\t(If this is wrong, use the \"-fps <frame-rate>\" option instead.)\n", fps); | 263 fprintf(stderr, "demux_rtp: Guessed the video frame rate as %d frames-per-second.\n\t(If this is wrong, use the \"-fps <frame-rate>\" option instead.)\n", fps); |
261 sh_video->fps = fps; | 264 sh_video->fps = fps; |
265 sh_video->frametime=1.0f/fps; | |
262 return; | 266 return; |
267 } | |
268 if (fps>lastfps) lastfps = fps; | |
263 } | 269 } |
264 lastPTS = curPTS; | 270 lastPTS = curPTS; |
265 } | 271 } |
266 fprintf(stderr, "demux_rtp: Failed to guess the video frame rate\n"); | 272 fprintf(stderr, "demux_rtp: Failed to guess the video frame rate\n"); |
267 } | 273 } |