From 9f64599b8f84dd60b53f14ec90bc32af569131f5 Mon Sep 17 00:00:00 2001 From: reimar Date: Wed, 20 Oct 2004 20:07:50 +0000 Subject: [PATCH] allow changing playback speed during playback. Based on patch by Steve Mueller (diffusor ugcs (dot) caltech [dot] edu), OSD support by Frank Schertan (scherthan (at) uni-landau de), several modifications by me. git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@13711 b3059339-0415-0410-9bf9-f77b7e298cf2 --- AUTHORS | 8 ++++++ DOCS/man/de/mplayer.1 | 6 +++++ DOCS/man/en/mplayer.1 | 6 +++++ DOCS/tech/slave.txt | 9 +++++++ DOCS/xml/en/usage.xml | 12 +++++++++ etc/input.conf | 5 ++++ input/input.c | 8 ++++++ input/input.h | 3 +++ mplayer.c | 59 +++++++++++++++++++++++++++++++++++++------ 9 files changed, 108 insertions(+), 8 deletions(-) diff --git a/AUTHORS b/AUTHORS index 09d552c382..2e3863ab09 100644 --- a/AUTHORS +++ b/AUTHORS @@ -194,6 +194,8 @@ Dobbelaere, Jeroen Döffinger, Reimar (reimar) * GL code fixes + * various fixes all over the place + * reworked live changing playback speed Dolbeau, Romain * random AltiVec (PowerPC multimedia extensions) stuff @@ -523,6 +525,9 @@ Mohari, Andr * various docs updates and fixes * 1st half of the documentation HTML --> XML conversion +Mueller, Steven + * first implementation of live changing playback speed + MPlayerPL - Polish MPlayer Translation Team (http://mplayerpl.emdej.com) * Waclaw Schiller (Torinthiel) * Kuba Misiorny (Qba) @@ -620,6 +625,9 @@ Sandell, Bj Sauerbeck, Tilman * TGA decoder (RLE/uncomp), -mf tga support +Scherthan, Frank + * added OSD handling for live changing playback speed + Schneider, Florian * RealVideo codec libraries interface, .rm demuxer fixes diff --git a/DOCS/man/de/mplayer.1 b/DOCS/man/de/mplayer.1 index ef0f7a7345..4c563c7403 100644 --- a/DOCS/man/de/mplayer.1 +++ b/DOCS/man/de/mplayer.1 @@ -227,6 +227,12 @@ Springe 10 Sekunden zur Springe 1 Minute zurück/\:vor. .IPs "BildHoch und BildRunter (bzw.\& PGUP/\:PGDOWN)" Springe 10 Minuten zurück/\:vor. +.IPs "[ und ]" +Verringert/erhöht die Abspielgeschwindigkeit um 10%. +.IPs "{ und }" +Halbiert/verdoppelt die Abspielgeschwindigkeit. +.IPs "Löschen (Backspace)" +Setzt die Abspielgeschwindigkeit zurück. .IPs "< und >" zurück\:vor in der Playlist .IPs "Pos1 und Ende" diff --git a/DOCS/man/en/mplayer.1 b/DOCS/man/en/mplayer.1 index 57d7913d3c..0a07e998b3 100644 --- a/DOCS/man/en/mplayer.1 +++ b/DOCS/man/en/mplayer.1 @@ -219,6 +219,12 @@ Seek backward/\:forward 10 seconds. Seek backward/\:forward 1 minute. .IPs "pgup and pgdown" Seek backward/\:forward 10 minutes. +.IPs "[ and ]" +Decreases/increases current playback speed by 10%. +.IPs "{ and }" +Halves/doubles current playback speed. +.IPs "Backspace" +Reset playback speed to normal. .IPs "< and >" backward/\:forward in playlist .IPs "HOME and END" diff --git a/DOCS/tech/slave.txt b/DOCS/tech/slave.txt index 9184f23ae9..c324ae71b5 100644 --- a/DOCS/tech/slave.txt +++ b/DOCS/tech/slave.txt @@ -15,6 +15,15 @@ seek [] 1 is a seek to % in the movie. 2 is a seek to an absolute position of seconds. +speed_set + Set the speed to . + +speed_incr + Add to the current playback speed. + +speed_mult + Multiply the current speed with . + edl_mark ??? diff --git a/DOCS/xml/en/usage.xml b/DOCS/xml/en/usage.xml index 9aafd0410b..cf1f43b92e 100644 --- a/DOCS/xml/en/usage.xml +++ b/DOCS/xml/en/usage.xml @@ -221,6 +221,18 @@ You can have a full list of known commands by running Type 0 is a relative seek of +/- val seconds. Type 1 seek to val % in the movie. +speed_mult (float) val + + Multiply the current speed with val. + +speed_incr (float) val + + Add val to the current playback speed. + +speed_set (float) val + + Set the speed to val. + audio_delay (float) val Adjust the audio delay of val seconds diff --git a/etc/input.conf b/etc/input.conf index 092a408fd1..4cde2d2bab 100644 --- a/etc/input.conf +++ b/etc/input.conf @@ -15,6 +15,11 @@ PGUP seek 600 PGDWN seek -600 - audio_delay 0.100 + audio_delay -0.100 +[ speed_mult 0.9091 # scale playback speed +] speed_mult 1.1 +{ speed_mult 0.5 +} speed_mult 2.0 +BS speed_set 1.0 # reset speed to normal q quit ESC quit ENTER pt_step 1 1 diff --git a/input/input.c b/input/input.c index 420c2fe2de..29d5724450 100644 --- a/input/input.c +++ b/input/input.c @@ -55,6 +55,9 @@ static mp_cmd_t mp_cmds[] = { { MP_CMD_EDL_MARK, "edl_mark", 0, { {-1,{0}} } }, #endif { MP_CMD_AUDIO_DELAY, "audio_delay", 1, { {MP_CMD_ARG_FLOAT,{0}}, {-1,{0}} } }, + { MP_CMD_SPEED_INCR, "speed_incr", 1, { {MP_CMD_ARG_FLOAT,{0}}, {-1,{0}} } }, + { MP_CMD_SPEED_MULT, "speed_mult", 1, { {MP_CMD_ARG_FLOAT,{0}}, {-1,{0}} } }, + { MP_CMD_SPEED_SET, "speed_set", 1, { {MP_CMD_ARG_FLOAT,{0}}, {-1,{0}} } }, { MP_CMD_QUIT, "quit", 0, { {MP_CMD_ARG_INT,{0}}, {-1,{0}} } }, { MP_CMD_PAUSE, "pause", 0, { {-1,{0}} } }, { MP_CMD_FRAME_STEP, "frame_step", 0, { {-1,{0}} } }, @@ -270,6 +273,11 @@ static mp_cmd_bind_t def_cmd_binds[] = { { { KEY_PAGE_DOWN, 0 }, "seek -600" }, { { '-', 0 }, "audio_delay 0.100" }, { { '+', 0 }, "audio_delay -0.100" }, + { { '[', 0 }, "speed_mult 0.9091" }, + { { ']', 0 }, "speed_mult 1.1" }, + { { '{', 0 }, "speed_mult 0.5" }, + { { '}', 0 }, "speed_mult 2.0" }, + { { KEY_BACKSPACE, 0 }, "speed_set 1.0" }, { { 'q', 0 }, "quit" }, { { KEY_ESC, 0 }, "quit" }, #ifndef HAVE_NEW_GUI diff --git a/input/input.h b/input/input.h index 70ffa33ca4..ce65879a31 100644 --- a/input/input.h +++ b/input/input.h @@ -58,6 +58,9 @@ #define MP_CMD_SWITCH_VSYNC 54 #define MP_CMD_SWITCH_RATIO 55 #define MP_CMD_FRAME_STEP 56 +#define MP_CMD_SPEED_INCR 57 +#define MP_CMD_SPEED_MULT 58 +#define MP_CMD_SPEED_SET 59 #define MP_CMD_GUI_EVENTS 5000 #define MP_CMD_GUI_LOADFILE 5001 diff --git a/mplayer.c b/mplayer.c index 52d3a45f22..6d132c410c 100644 --- a/mplayer.c +++ b/mplayer.c @@ -756,6 +756,31 @@ void update_set_of_subtitles() #include #endif +/** + * \brief build a chain of audio filters that converts the input format + * to the ao's format, taking into account the current playback_speed. + * \param sh_audio describes the requested input format of the chain. + * \param ao_data describes the requested output format of the chain. + */ +static int build_afilter_chain(sh_audio_t *sh_audio, ao_data_t *ao_data) +{ + int new_srate = sh_audio->samplerate * playback_speed; + if (!sh_audio) + return 0; + if (new_srate != ao_data->samplerate) { + // limits are taken from libaf/af_resample.c + if (new_srate < 8000) + new_srate = 8000; + if (new_srate > 192000) + new_srate = 192000; + playback_speed = (float)new_srate / (float)sh_audio->samplerate; + } + return init_audio_filters(sh_audio, new_srate, + sh_audio->channels, sh_audio->sample_format, sh_audio->samplesize, + ao_data->samplerate, ao_data->channels, ao_data->format, + audio_out_format_bits(ao_data->format) / 8, /* ao_data.bps, */ + ao_data->outburst * 4, ao_data->buffersize); +} int main(int argc,char* argv[]){ @@ -776,6 +801,7 @@ int osd_function=OSD_PLAY; int osd_last_pts=-303; int osd_show_av_delay = 0; int osd_show_text = 0; +int osd_show_speed = 0; int osd_show_sub_delay = 0; int osd_show_sub_pos = 0; int osd_show_sub_visibility = 0; @@ -1927,12 +1953,7 @@ if(sh_audio){ // init audio filters: #if 1 current_module="af_init"; - if(!init_audio_filters(sh_audio, - (int)(sh_audio->samplerate*playback_speed), - sh_audio->channels, sh_audio->sample_format, sh_audio->samplesize, - ao_data.samplerate, ao_data.channels, ao_data.format, - audio_out_format_bits(ao_data.format)/8, /* ao_data.bps, */ - ao_data.outburst*4, ao_data.buffersize)){ + if(!build_afilter_chain(sh_audio, &ao_data)) { mp_msg(MSGT_CPLAYER,MSGL_ERR,MSGTR_NoMatchingFilter); // mp_msg(MSGT_CPLAYER,MSGL_ERR,"Couldn't find matching filter / ao format! -> NOSOUND\n"); // uninit_player(INITED_ACODEC|INITED_AO); // close codec & ao @@ -2085,7 +2106,7 @@ if(!sh_video) { if ((' ' == hhmmssf[6]) && (' ' != hhmmssf[5])) { hhmmssf[6] = '0'; } - mp_msg(MSGT_AVSYNC,MSGL_STATUS,"A: %s %4.1f%% %d%% \r" + mp_msg(MSGT_AVSYNC,MSGL_STATUS,"A: %s %4.1f%% %d%% %4.2fx \r" ,hhmmssf ,(sh_audio->delay>0.5)?100.0*audio_time_usage/(double)sh_audio->delay:0 ,cache_fill_status @@ -2385,7 +2406,7 @@ if(time_frame>0.001 && !(vo_flags&256)){ else max_pts_correction=sh_video->frametime*0.10; // +-10% of time if(!frame_time_remaining){ sh_audio->delay+=x; c_total+=x;} // correction - if(!quiet) mp_msg(MSGT_AVSYNC,MSGL_STATUS,"A:%6.1f V:%6.1f A-V:%7.3f ct:%7.3f %3d/%3d %2d%% %2d%% %4.1f%% %d %d %d%%\r", + if(!quiet) mp_msg(MSGT_AVSYNC,MSGL_STATUS,"A:%6.1f V:%6.1f A-V:%7.3f ct:%7.3f %3d/%3d %2d%% %2d%% %4.1f%% %d %d %d%% %4.2fx\r", a_pts-audio_delay-delay,v_pts,AV_delay,c_total, (int)sh_video->num_frames,(int)sh_video->num_frames_decoded, (sh_video->timer>0.5)?(int)(100.0*video_time_usage*playback_speed/(double)sh_video->timer):0, @@ -2394,6 +2415,7 @@ if(time_frame>0.001 && !(vo_flags&256)){ ,drop_frame_cnt ,output_quality ,cache_fill_status + ,playback_speed ); fflush(stdout); } @@ -2597,6 +2619,24 @@ if (stream->type==STREAMTYPE_DVDNAV && dvd_nav_still) osd_show_av_delay = 9; if(sh_audio) sh_audio->delay+= v; } break; + case MP_CMD_SPEED_INCR : { + float v = cmd->args[0].v.f; + playback_speed += v; + osd_show_speed = sh_video->fps; + build_afilter_chain(sh_audio, &ao_data); + } break; + case MP_CMD_SPEED_MULT : { + float v = cmd->args[0].v.f; + playback_speed *= v; + osd_show_speed = sh_video->fps; + build_afilter_chain(sh_audio, &ao_data); + } break; + case MP_CMD_SPEED_SET : { + float v = cmd->args[0].v.f; + playback_speed = v; + osd_show_speed = sh_video->fps; + build_afilter_chain(sh_audio, &ao_data); + } break; case MP_CMD_FRAME_STEP : case MP_CMD_PAUSE : { osd_function=OSD_PAUSE; @@ -3791,6 +3831,9 @@ while (next_edl_record) if (osd_show_av_delay) { snprintf(osd_text_tmp, 63, "A-V delay: %d ms", ROUND(audio_delay*1000)); osd_show_av_delay--; + } else if (osd_show_speed) { + snprintf(osd_text_tmp, 63, "Speed: x %6.2f", playback_speed); + osd_show_speed--; } else if (osd_show_ontop) { snprintf(osd_text_tmp, 63, "Stay on top: %sabled", vo_ontop?"en":"dis"); osd_show_ontop--;