diff -urN main/cfg-common.h main_endpos6/cfg-common.h --- main/cfg-common.h 2005-08-09 10:58:41.879285984 +0200 +++ main_endpos6/cfg-common.h 2005-11-17 17:56:30.240968128 +0100 @@ -77,6 +77,9 @@ {"sb", &seek_to_byte, CONF_TYPE_POSITION, CONF_MIN, 0, 0, NULL}, {"ss", &seek_to_sec, CONF_TYPE_STRING, CONF_MIN, 0, 0, NULL}, + // stop at given position + {"endpos", &end_at_string, CONF_TYPE_STRING, 0, 0, 0, NULL}, + #ifdef USE_EDL {"edl", &edl_filename, CONF_TYPE_STRING, 0, 0, 0, NULL}, #else diff -urN main/cfg-mencoder.h main_endpos6/cfg-mencoder.h --- main/cfg-mencoder.h 2005-11-14 10:25:44.830719416 +0100 +++ main_endpos6/cfg-mencoder.h 2005-11-17 17:56:30.320955968 +0100 @@ -200,8 +200,6 @@ m_option_t mencoder_opts[]={ /* name, pointer, type, flags, min, max */ - {"endpos", &end_at_string, CONF_TYPE_STRING, 0, 0, 0, NULL}, - {"frameno-file", &frameno_filename, CONF_TYPE_STRING, CONF_GLOBAL, 0, 0, NULL}, #ifdef USE_EDL diff -urN main/DOCS/man/en/mplayer.1 main_endpos6/DOCS/man/en/mplayer.1 --- main/DOCS/man/en/mplayer.1 2005-11-17 17:35:45.409211320 +0100 +++ main_endpos6/DOCS/man/en/mplayer.1 2005-11-17 17:56:30.334953840 +0100 @@ -1064,6 +1064,30 @@ See DOCS/\:HTML/\:en/\:edl.html for details on how to use this. . .TP +.B \-endpos <[[hh:]mm:]ss[.ms]|size[b|kb|mb]> (also see \-ss and \-sb) +Stop at given time or byte position. +.br +.I NOTE: +Byte position is enabled only for MEncoder and will not be accurate, as it can +only stop at a frame boundary. +When used in conjunction with \-ss option, \-endpos time will shift forward by +seconds specified with \-ss. +.sp 1 +.I EXAMPLE: +.PD 0 +.RSs +.IPs "\-endpos 56" +Stop at 56 seconds. +.IPs "\-endpos 01:10:00" +Stop at 1 hour 10 minutes. +.IPs "\-ss 10 \-endpos 56" +Stop at 1 minute 6 seconds. +.IPs "\-endpos 100mb" +Encode only 100 MB. +.RE +.PD 1 +. +.TP .B \-forceidx Force index rebuilding. Useful for files with broken index (A/\:V desync, etc). @@ -5935,26 +5959,6 @@ Sets up the audio buffering time interval (default: 0.5s). . .TP -.B \-endpos <[[hh:]mm:]ss[.ms]|size[b|kb|mb]> (also see \-ss and \-sb) -Stop encoding at the given time or byte position. -.br -.I NOTE: -Byte position will not be accurate, as it can only stop at -a frame boundary. -.sp 1 -.I EXAMPLE: -.PD 0 -.RSs -.IPs "\-endpos 56" -Encode only 56 seconds. -.IPs "\-endpos 01:10:00" -Encode only 1 hour 10 minutes. -.IPs "\-endpos 100mb" -Encode only 100 MB. -.RE -.PD 1 -. -.TP .B \-fafmttag Can be used to override the audio format tag of the output file. .sp 1 diff -urN main/help/help_mp-en.h main_endpos6/help/help_mp-en.h --- main/help/help_mp-en.h 2005-11-16 20:13:25.614679408 +0100 +++ main_endpos6/help/help_mp-en.h 2005-11-17 17:56:30.338953232 +0100 @@ -199,6 +199,7 @@ #define MSGTR_EdlBadLineOverlap "Last stop position was [%f]; next start is "\ "[%f]. Entries must be in chronological order, cannot overlap. Discarding.\n" #define MSGTR_EdlBadLineBadStop "Stop time has to be after start time.\n" +#define MSGTR_MPEndposNoSizeBased "Option -endpos in MPlayer doesn't yet support size units\n" // mplayer.c OSD diff -urN main/mplayer.c main_endpos6/mplayer.c --- main/mplayer.c 2005-11-16 20:07:59.481259224 +0100 +++ main_endpos6/mplayer.c 2005-11-17 18:02:50.638138968 +0100 @@ -242,6 +242,12 @@ static int loop_times=-1; static int loop_seek=0; +static void parse_end_at(); +enum end_at_type_t {END_AT_NONE, END_AT_TIME, END_AT_SIZE}; +static enum end_at_type_t end_at_type = END_AT_NONE; +static char * end_at_string=NULL; +static double end_at=0; + // A/V sync: int autosync=0; // 30 might be a good default value. @@ -1258,6 +1264,52 @@ } +static void parse_end_at() +{ + + end_at_type = END_AT_NONE; + + /* End at size parsing */ + { + char unit[4]; + + end_at_type = END_AT_SIZE; + + if(sscanf(end_at_string, "%lf%3s", &end_at, unit) == 2) { + if(!strcasecmp(unit, "b")) + ; + else if(!strcasecmp(unit, "kb")) + end_at *= 1024; + else if(!strcasecmp(unit, "mb")) + end_at *= 1024*1024; + else + end_at_type = END_AT_NONE; + } + else + end_at_type = END_AT_NONE; + } + + /* End at time parsing. This has to be last because of + * sscanf("%f", ...) below */ + if(end_at_type == END_AT_NONE) { + int a,b; float d; + + end_at_type = END_AT_TIME; + + if (sscanf(end_at_string, "%d:%d:%f", &a, &b, &d) == 3) + end_at = 3600*a + 60*b + d; + else if (sscanf(end_at_string, "%d:%f", &a, &d) == 2) + end_at = 60*a + d; + else if (sscanf(end_at_string, "%f", &d) == 1) + end_at = d; + else + end_at_type = END_AT_NONE; + } + + end_at_string = NULL; +} + + int main(int argc,char* argv[]){ @@ -2594,11 +2646,20 @@ if(!sh_video) { // handle audio-only case: - if(!quiet) { - float a_pos = sh_audio->delay - audio_out->get_delay() * playback_speed; - print_status(a_pos, 0, 0); + float a_pos=0; + if (end_at_string) { + parse_end_at(); + end_at_string = NULL; } - if(d_audio->eof && sh_audio->a_in_buffer_len <= 0) eof = PT_NEXT_ENTRY; + if(!quiet || end_at_type == END_AT_TIME ) + a_pos = sh_audio->delay - audio_out->get_delay() * playback_speed; + + if(!quiet) + print_status(a_pos, 0, 0); + + if( (d_audio->eof && sh_audio->a_in_buffer_len <= 0) || + (end_at_type == END_AT_TIME && end_at < a_pos) ) + eof = PT_NEXT_ENTRY; } else { @@ -2819,6 +2880,10 @@ too_slow_frame_cnt++; /* printf ("PANIC: too slow frame (%.3f)!\n", j); */ + // FIXME: add size based support for -endpos + if ( end_at_type == END_AT_TIME && end_at < sh_video->pts ) + break; + if(vo_config_count) video_out->flip_page(); if (play_n_frames >= 0) { --play_n_frames; @@ -4120,6 +4185,20 @@ seek_to_sec = NULL; } + if (end_at_string) { + + parse_end_at(); + + // if -ss option given, shift end_at by that time + if(end_at_type == END_AT_TIME) { + end_at += rel_seek_secs; + } else if(end_at_type == END_AT_SIZE) { + mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_MPEndposNoSizeBased); + end_at_type = END_AT_NONE; + } + + } + /* Looping. */ if(eof==1 && loop_times>=0) { int l = loop_times;