[MPlayer-dev-eng] Allow framerate detection for avc1 over rtsp with b-frames

Carl Eugen Hoyos cehoyos at ag.or.at
Mon Jan 15 15:15:21 CET 2007


On 2007-01-13 00:23, Carl Eugen Hoyos wrote:
> Hi!
> 
> Attached patch allows framerate detection for avc1 in X-QT over rtsp (and 
also 
> H264 over rtsp) if the stream contains b-frames.
> Can be tested with the following links:
> 
rtsp://a2047.v1411b.c1411.g.vq.akamaistream.net/5/2047/1411/2_h264_650/1a1a1ae454c430950065de4cbb2f94c226950c7ae655b61a48a91475e243acda3dac194879adde0f/8848125_2_650.mov
> 
rtsp://a2047.v1413b.c1413.g.vq.akamaistream.net/5/2047/1413/2_h264_110/1a1a1ae656c632970267e04ebd3196c428970e7ce857b81c4aab1677e445aedc3fae1b4a7bafe013/sept_2006_3_110.mov
> 
rtsp://a2047.v1412b.c1412.g.vq.akamaistream.net/5/2047/1412/2_h264_350/1a1a1ae555c531960166df4dbc3095c327960d7be756b71b49aa1576e344addb3ead1a497aaedf11/wwdc_2006_2_350.mov
> 
> If needed, I will send a cosmetical patch after this one is applied.

New patch because demux_rtp_codec.cpp changed.

Carl Eugen
-------------- next part --------------
Index: libmpdemux/demux_rtp_codec.cpp
===================================================================
--- libmpdemux/demux_rtp_codec.cpp	(Revision 21934)
+++ libmpdemux/demux_rtp_codec.cpp	(Arbeitskopie)
@@ -4,6 +4,7 @@
 #include "demux_rtp_internal.h"
 extern "C" {
 #include <limits.h>
+#include <math.h>
 #include "stheader.h"
 }
 
@@ -247,19 +248,24 @@
   unsigned char* packetData; unsigned packetDataLen;
   float lastPTS = 0.0, curPTS;
   unsigned const maxNumFramesToWaitFor = 300;
+  int lastfps = 0;
   for (unsigned i = 0; i < maxNumFramesToWaitFor; ++i) {
     if (!awaitRTPPacket(demuxer, d_video, packetData, packetDataLen, curPTS)) {
       break;
     }
 
-    if (curPTS > lastPTS && lastPTS != 0.0) {
+    if (curPTS != lastPTS && lastPTS != 0.0) {
       // Use the difference between these two "pts"s to guess the frame rate.
       // (should really check that there were no missing frames inbetween)#####
       // Guess the frame rate as an integer.  If it's not, use "-fps" instead.
-      fps = (int)(1/(curPTS-lastPTS) + 0.5); // rounding
+      fps = (int)(1/fabs(curPTS-lastPTS) + 0.5); // rounding
+        if (fps == lastfps) {
       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);
       sh_video->fps = fps;
+      sh_video->frametime=1.0f/fps;
       return;
+        }
+      if (fps>lastfps) lastfps = fps;
     }
     lastPTS = curPTS;
   }


More information about the MPlayer-dev-eng mailing list