changeset 32793:0adeebe4e561

Fractional part of time stamp in OSD. Add the -osd-fractions option to optionally show the fractional part of the time stamp in the OSD. Patch by Christian, herr.mitterlehner gsmpaaiml com
author cigaes
date Thu, 10 Feb 2011 19:20:36 +0000
parents 31ce0bd110d5
children 77d81e27a176
files DOCS/man/de/mplayer.1 DOCS/man/en/mplayer.1 cfg-mplayer.h mplayer.c
diffstat 4 files changed, 66 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/DOCS/man/de/mplayer.1	Thu Feb 10 13:50:28 2011 +0000
+++ b/DOCS/man/de/mplayer.1	Thu Feb 10 19:20:36 2011 +0000
@@ -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äherte Framezahl an.
+Die angezeigte Framezahl ist nicht exakt, sondern nur genähert.
+Für variable FPS ist die Näherung weit von der tatsächlichen Framezahl
+entfernt.
+.RE
+.PD 1
+.
+.TP
 .B \-osdlevel <0\-3> (nur bei MPlayer)
 Gibt den Modus an, in dem das OSD startet:
 .PD 0
--- a/DOCS/man/en/mplayer.1	Thu Feb 10 13:50:28 2011 +0000
+++ b/DOCS/man/en/mplayer.1	Thu Feb 10 19:20:36 2011 +0000
@@ -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
--- a/cfg-mplayer.h	Thu Feb 10 13:50:28 2011 +0000
+++ b/cfg-mplayer.h	Thu Feb 10 19:20:36 2011 +0000
@@ -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},
--- a/mplayer.c	Thu Feb 10 13:50:28 2011 +0000
+++ b/mplayer.c	Thu Feb 10 19:20:36 2011 +0000
@@ -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";
@@ -1570,6 +1572,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)
@@ -1580,15 +1583,38 @@
             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;