Fixing Mplayer's Terminal Abuse, esp. for KDE and Windows

Mplayer updates the information about the amounts of frames it displayed, the played time, the remaining time, etc. every single time it displays a *frame*. This is not only completely unnecessary, it can unnecessarily hog several percent of your CPU in many terminal implementations, especially in current KDE 4 and Windows. The higher the frame rate, the more wasted CPU power.

On my netbook, the difference is 10% CPUand more with a 25 frames per second video - that's as much and more than mplayer uses for a simple Xvid video. And it could easily make the difference between a well playing file and one that's glitchy. (The CPU time is occupied by konsole 4.3.2 though, not by mplayer itself.)

The only way out would be -quiet. But then you wouldn't know what's going on anymore at all. That's why I had written and submitted roughly the following patch to fix this behavior. Unfortunately even after I made all the requested corrections, it was never applied without any reasons provided, or were there?. So I decided to publish it here so people at least know about it. But it also means unless I can convince someone here, you will have to compile mplayer and apply the patch yourself.

There are many guides how to compile mplayer. Before you start the compilation process, just copy this following block into a file quiet.patch and then apply it inside the svn directory with "patch -p0 < quiet.patch", then compile mplayer normally. You can now use the parameter -quiet-time. A value of 1 means a status message no more often than every 100 milliseconds (0,1 seconds). I think a good value is 5. You will notice that e.g. konsole uses less CPU during playback now. Enjoy the power of open source and let me know how it works for you!

Index: DOCS/man/en/mplayer.1
===================================================================
--- DOCS/man/en/mplayer.1 (Revision 29324)
+++ DOCS/man/en/mplayer.1 (Arbeitskopie)
@@ -732,6 +732,12 @@
handle carriage return (i.e.\& \\r).
.
.TP
+.B "\-quiet-time \ "
+Reduce console output updates to n per tenth of a second.
+Values of 5 or more work around slow terminals.
+See \-quiet for more.
+.
+.TP
.B \-priority (Windows and OS/2 only)
Set process priority for MPlayer according to the predefined
priorities available under Windows and OS/2.
Index: mplayer.c
===================================================================
--- mplayer.c (Revision 29324)
+++ mplayer.c (Arbeitskopie)
@@ -81,6 +81,7 @@
int slave_mode=0;
int player_idle_mode=0;
int quiet=0;
+int quiet_time=0;
int enable_mouse_movements=0;
float start_volume = -1;

@@ -1936,6 +1937,11 @@

static void adjust_sync_and_print_status(int between_frames, float timing_error)
{
+ static unsigned last_status_update=0;
+ unsigned now=GetTimerMS();
+ if (quiet_time && now >= (last_status_update + quiet_time * 100))
+ last_status_update=now;
+
current_module="av_sync";

if(mpctx->sh_audio){
@@ -1987,6 +1993,7 @@
c_total+=x;
}
if(!quiet)
+ if (!quiet_time || (last_status_update == now))
print_status(a_pts - audio_delay, AV_delay, c_total);
}

@@ -1994,6 +2001,7 @@
// No audio:

if (!quiet)
+ if (!quiet_time || (last_status_update == now))
print_status(0, 0, 0);
}
}
Index: cfg-common-opts.h
===================================================================
--- cfg-common-opts.h (Revision 29324)
+++ cfg-common-opts.h (Arbeitskopie)
@@ -8,6 +8,7 @@
// ------------------------- common options --------------------
{"quiet", &quiet, CONF_TYPE_FLAG, CONF_GLOBAL, 0, 1, NULL},
{"noquiet", &quiet, CONF_TYPE_FLAG, CONF_GLOBAL, 1, 0, NULL},
+ {"quiet-time", &quiet_time, CONF_TYPE_INT, CONF_RANGE, 0, 65536, NULL},
{"really-quiet", &verbose, CONF_TYPE_FLAG, CONF_GLOBAL|CONF_PRE_PARSE, 0, -10, NULL},
{"v", cfg_inc_verbose, CONF_TYPE_FUNC, CONF_GLOBAL|CONF_NOSAVE, 0, 0, NULL},
{"msglevel", msgl_config, CONF_TYPE_SUBCONFIG, CONF_GLOBAL, 0, 0, NULL},
Index: mencoder.c
===================================================================
--- mencoder.c (Revision 29324)
+++ mencoder.c (Arbeitskopie)
@@ -131,6 +131,7 @@
//void resync_audio_stream(sh_audio_t *sh_audio){}

int quiet=0;
+int quiet_time=0;
double video_time_usage=0;
double vout_time_usage=0;
double max_video_time_usage=0;
@@ -1420,8 +1421,14 @@
(int)demuxer->filepos,
(int)demuxer->movi_end);
#else
+ static unsigned last_status_update=0;
+ unsigned now=GetTimerMS();
+ if (quiet_time && now >= (last_status_update + quiet_time * 100))
+ last_status_update=now;
+
if(!quiet) {
if( mp_msg_test(MSGT_STATUSLINE,MSGL_V) ) {
+ if (!quiet_time || (last_status_update == now))
mp_msg(MSGT_STATUSLINE,MSGL_STATUS,"Pos:%6.1fs %6df (%2d%%) %3dfps Trem:%4dmin %3dmb A-V:%5.3f [%d:%d] A/Vms %d/%d D/B/S %d/%d/%d \r",
mux_v->timer, decoded_frameno, (int)(p*100),
(t>1) ? (int)(decoded_frameno/t+0.5) : 0,
@@ -1434,6 +1441,7 @@
duplicatedframes, badframes, skippedframes
);
} else
+ if (!quiet_time || (last_status_update == now))
mp_msg(MSGT_STATUSLINE,MSGL_STATUS,"Pos:%6.1fs %6df (%2d%%) %5.2ffps Trem:%4dmin %3dmb A-V:%5.3f [%d:%d]\r",
mux_v->timer, decoded_frameno, (int)(p*100),
(t>1) ? (float)(decoded_frameno/t) : 0,

No comments:

Post a Comment

I appreciate comments. Feel free to write anything you wish. Selected comments and questions will be published.