[MPlayer-dev-eng] [PATCH] Fractional part of time stamp in OSD

Christian herr.mitterlehner at gsmpaaiml.com
Sat Jan 29 07:22:46 CET 2011


Hello,

On Fri, Jan 28, 2011 at 05:45:12PM +0100, Nicolas George wrote:
> Le nonidi 9 pluviôse, an CCXIX, Christian a écrit :
> > Attached patch allows to optionally also show the fractional part of the
> > time stamp in the OSD.
> 
> Seems potentially useful.
> 
> > +.B \-osd-fractions <0\-2>
>            ^
> You forgot that one.

Fixed in both
DOCS/man/en/mplayer.1
DOCS/man/de/mplayer.1
 
> > +show approximated frame count within current second. This frame count is not
> > +accurate but only an approximation. For variable fps, the approximation is 
> > +known to be far off the correct frame count.
> 
> I think the rule is tu start sentences on new lines.

Fixed in both
DOCS/man/en/mplayer.1
DOCS/man/de/mplayer.1

> >  [ diff vor German man-page ]
>
> My German is too rusty for me to give advice on that part.

If you prefer to have a patch without the German man-page, just let me know.

> > +                snprintf(fractions_text, 5, "%4.2f", mpctx->sh_video->pts - pts);
>                                             ^
> Potential desync between one part of the code and the other. Better use
> sizeof.

Fixed.

> > +                fractions_text_start++; //This is to skip beyond the leading 0 in eg 0.12
> 
> That seems awkward. Couldn't you use "%02d" and
> (int)(diff * 100 + 0.5) % 100?

Fixed.

> > +            } else if (osd_fractions==2)
> > +                //print fractions by estimating the frame count within the second
> > +                //
> > +                //rounding or cutting off numbers after the decimal point causes problems
> > +                //because of float's precision and movies, whose first frame is not exactly at timestamp 0
> > +                //Therefore, we add 0.2 and cut off at the decimal point, which proved as good heuristic
> > +                snprintf(fractions_text, 4, ".%02d", (int) ( ( mpctx->sh_video->pts - pts ) * mpctx->sh_video->fps + 0.2 ) );
> 
> Nitpick: your lines are too long, 

Reformatted to 78 columns.

> [...]
> Also, I fear a multiline comment before a brace-less if/else [...]

Fixed.

Attached, you'll find the revised version of the patch.

Kind regards,
Christian
-------------- next part --------------
Index: DOCS/man/en/mplayer.1
===================================================================
--- DOCS/man/en/mplayer.1	(Revision 32825)
+++ DOCS/man/en/mplayer.1	(Arbeitskopie)
@@ -2426,6 +2426,23 @@
 Set the duration of the OSD messages in ms (default: 1000).
 .
 .TP
+.B \-osd\-fractions <0\-2>
+Set how fractions of seconds of the current timestamp are printed on the OSD:
+.PD 0
+.RSs
+.IPs 0
+do not display fractions (default)
+.IPs 1
+show the first two decimals
+.IPs 2
+show approximated frame count within current second.
+This frame count is not accurate but only an approximation.
+For variable fps, the approximation is known to be far off the correct frame
+count.
+.RE
+.PD 1
+.
+.TP
 .B \-osdlevel <0\-3> (MPlayer only)
 Specifies which mode the OSD should start in.
 .PD 0
Index: DOCS/man/de/mplayer.1
===================================================================
--- DOCS/man/de/mplayer.1	(Revision 32825)
+++ DOCS/man/de/mplayer.1	(Arbeitskopie)
@@ -2416,6 +2416,24 @@
 Setzt die Anzeigedauer der OSD-Meldungen in ms (Standard: 1000).
 .
 .TP
+.B \-osd\-fractions <0\-2>
+Setzt die Art der Anzeige von Nachkommastellen des aktuellen Zeitstempels im 
+OSD:
+.PD 0
+.RSs
+.IPs 0
+keine Anzeige der Nachkommastellen (Standard)
+.IPs 1
+zeige die ersten beiden Nachkommastellen
+.IPs 2
+zeige gen?rte Framezahl an.
+Die angezeigte Framezahl ist nicht exakt, sondern nur gen?rt.
+F?iable FPS ist die N?rung weit von der tats?lichen Framezahl
+entfernt.
+.RE
+.PD 1
+.
+.TP
 .B \-osdlevel <0\-3> (nur bei MPlayer)
 Gibt den Modus an, in dem das OSD startet:
 .PD 0
Index: mplayer.c
===================================================================
--- mplayer.c	(Revision 32825)
+++ mplayer.c	(Arbeitskopie)
@@ -212,6 +212,8 @@
 // if nonzero, hide current OSD contents when GetTimerMS() reaches this
 unsigned int osd_visible;
 int osd_duration = 1000;
+int osd_fractions = 0; // determines how fractions of seconds are displayed
+                       // on OSD
 
 int term_osd = 1;
 static char* term_osd_esc = "\x1b[A\r\x1b[K";
@@ -1569,6 +1571,7 @@
             int len = demuxer_get_time_length(mpctx->demuxer);
             int percentage = -1;
             char percentage_text[10];
+            char fractions_text[4];
             int pts = demuxer_get_current_time(mpctx->demuxer);
 
             if (mpctx->osd_show_percentage)
@@ -1579,15 +1582,37 @@
             else
                 percentage_text[0] = 0;
 
+            if (osd_fractions==1) {
+                //print fractions as sub-second timestamp
+                snprintf(fractions_text, sizeof(fractions_text), ".%02d", 
+		      (int)( (mpctx->sh_video->pts - pts)* 100 + 0.5) % 100);
+            } else if (osd_fractions==2) {
+                //print fractions by estimating the frame count within the
+	        //second
+
+                //rounding or cutting off numbers after the decimal point
+	        //causes problems because of float's precision and movies,
+	        //whose first frame is not exactly at timestamp 0. Therefore,
+	        //we add 0.2 and cut off at the decimal point, which proved
+	        //as good heuristic
+                snprintf(fractions_text, sizeof(fractions_text), ".%02d", 
+			 (int) ( ( mpctx->sh_video->pts - pts ) * 
+				 mpctx->sh_video->fps + 0.2 ) );
+            } else {
+                //do not print fractions
+                fractions_text[0] = 0;
+            }
+
             if (osd_level == 3)
                 snprintf(osd_text_timer, 63,
-                         "%c %02d:%02d:%02d / %02d:%02d:%02d%s",
+                         "%c %02d:%02d:%02d%s / %02d:%02d:%02d%s",
                          mpctx->osd_function,pts/3600,(pts/60)%60,pts%60,
-                         len/3600,(len/60)%60,len%60,percentage_text);
+                         fractions_text,len/3600,(len/60)%60,len%60,
+                         percentage_text);
             else
-                snprintf(osd_text_timer, 63, "%c %02d:%02d:%02d%s",
+                snprintf(osd_text_timer, 63, "%c %02d:%02d:%02d%s%s",
                          mpctx->osd_function,pts/3600,(pts/60)%60,
-                         pts%60,percentage_text);
+                         pts%60,fractions_text,percentage_text);
         } else
             osd_text_timer[0]=0;
 
Index: cfg-mplayer.h
===================================================================
--- cfg-mplayer.h	(Revision 32825)
+++ cfg-mplayer.h	(Arbeitskopie)
@@ -235,6 +235,7 @@
 #endif
     {"osdlevel", &osd_level, CONF_TYPE_INT, CONF_RANGE, 0, 3, NULL},
     {"osd-duration", &osd_duration, CONF_TYPE_INT, CONF_MIN, 0, 0, NULL},
+    {"osd-fractions", &osd_fractions, CONF_TYPE_INT, CONF_RANGE, 0, 2, NULL},
 #ifdef CONFIG_MENU
     {"menu", &use_menu, CONF_TYPE_FLAG, CONF_GLOBAL, 0, 1, NULL},
     {"nomenu", &use_menu, CONF_TYPE_FLAG, CONF_GLOBAL, 1, 0, NULL},


More information about the MPlayer-dev-eng mailing list