[MPlayer-dev-eng] Re: [PATCH]H264 over rtsp

Carl Eugen Hoyos cehoyos at ag.or.at
Sat May 13 14:47:35 CEST 2006


Carl Eugen Hoyos <cehoyos <at> ag.or.at> writes:

> 
> Hi Ross!

[...]

> While I think of something less ugly, could you look at this small patch? I
> think frame rate guessing doesn't work without it.

Sadly, I received no comment about my one-line patch that fixed this stream (at
least when used with -rtsp-stream-over-tcp - I can't test anything else):
rtsp://neotest.qtv.apple.com/secure/jan/mwsf05/macworld_650_3.mov

I attached an improved version which waits for confirmation of the calculated
framerate, and also works for H264 streams containing B-Frames.
Their PTS look, for example, like this (15fps, 1 B Frame):
0.000000, 0.133333, 0.066667, 0.266667, 0.200001, 0.400001, ...

It fixes frame rate recognition for:
rtsp://neotest.qtv.apple.com/secure/jan/mwsf05/macworld_350_3.mov (14fps)
rtsp://neotest.qtv.apple.com/secure/jan/mwsf05/macworld_100_3.mov (8fps)

Any comments?

Thank you, Carl Eugen Hoyos

Index: libmpdemux/demux_rtp_codec.cpp
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/demux_rtp_codec.cpp,v
retrieving revision 1.8
diff -u -r1.8 demux_rtp_codec.cpp
--- libmpdemux/demux_rtp_codec.cpp      23 Sep 2005 22:35:03 -0000      1.8
+++ libmpdemux/demux_rtp_codec.cpp      13 May 2006 12:45:15 -0000
@@ -4,6 +4,7 @@
 #include "demux_rtp_internal.h"
 extern "C" {
 #include "stheader.h"
+#include "math.h"
 }

 static void
@@ -221,19 +222,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
-      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;
-      return;
+      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