diff -urN main/cfg-common.h main_endpos9/cfg-common.h --- main/cfg-common.h 2005-11-28 17:31:15.573303120 +0100 +++ main_endpos9/cfg-common.h 2005-12-01 02:05:46.733989656 +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, CONF_TYPE_TIME_SIZE, 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_endpos9/cfg-mencoder.h --- main/cfg-mencoder.h 2005-11-28 17:31:15.594299928 +0100 +++ main_endpos9/cfg-mencoder.h 2005-12-01 02:05:46.737989048 +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_endpos9/DOCS/man/en/mplayer.1 --- main/DOCS/man/en/mplayer.1 2005-11-23 11:26:02.314573624 +0100 +++ main_endpos9/DOCS/man/en/mplayer.1 2005-12-01 02:05:46.751986920 +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). @@ -5948,26 +5972,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_endpos9/help/help_mp-en.h --- main/help/help_mp-en.h 2005-12-01 00:33:45.794300064 +0100 +++ main_endpos9/help/help_mp-en.h 2005-12-01 02:05:46.756986160 +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/mencoder.c main_endpos9/mencoder.c --- main/mencoder.c 2005-12-01 00:33:23.347712464 +0100 +++ main_endpos9/mencoder.c 2005-12-01 02:05:46.762985248 +0100 @@ -235,10 +235,10 @@ static char *seek_to_sec=NULL; static off_t seek_to_byte=0; +static m_time_size_t end_at = { .type = END_AT_NONE, .pos = 0 }; + static char * frameno_filename=NULL; -static void parse_end_at(); -static char * end_at_string=0; //static uint8_t* flip_upside_down(uint8_t* dst, const uint8_t* src, int width, int height); typedef struct { @@ -341,10 +341,6 @@ static int at_eof=0; static int interrupted=0; -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 double end_at; - static void exit_sighandler(int x){ at_eof=1; interrupted=2; /* 1 means error */ @@ -994,8 +990,6 @@ } } -parse_end_at(); - if (seek_to_sec) { int a,b; float d; @@ -1034,7 +1028,7 @@ } play_n_frames=play_n_frames_mf; -if (curfile && end_at_type == END_AT_TIME) end_at += mux_v->timer; +if (curfile && end_at.type == END_AT_TIME) end_at.pos += mux_v->timer; #ifdef USE_EDL if (edl_records) free_edl(edl_records); @@ -1055,8 +1049,8 @@ float v_pts=0; int skip_flag=0; // 1=skip -1=duplicate - if((end_at_type == END_AT_SIZE && end_at <= ftello(muxer_f)) || - (end_at_type == END_AT_TIME && end_at < mux_v->timer)) + if((end_at.type == END_AT_SIZE && end_at.pos <= ftello(muxer_f)) || + (end_at.type == END_AT_TIME && end_at.pos < mux_v->timer)) break; if(play_n_frames>=0){ @@ -1541,50 +1535,6 @@ return interrupted; } -static void parse_end_at() -{ - - end_at_type = END_AT_NONE; - if (!end_at_string) return; - - /* 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; - } -} #if 0 /* Flip the image in src and store the result in dst. src and dst may overlap. @@ -1610,7 +1560,7 @@ static float stop_time(demuxer_t* demuxer, muxer_stream_t* mux_v) { float timeleft = -1; if (play_n_frames >= 0) timeleft = mux_v->timer + play_n_frames * (double)(mux_v->h.dwScale) / mux_v->h.dwRate; - if (end_at_type == END_AT_TIME && (timeleft > end_at || timeleft == -1)) timeleft = end_at; + if (end_at.type == END_AT_TIME && (timeleft > end_at.pos || timeleft == -1)) timeleft = end_at.pos; #ifdef USE_EDL if (next_edl_record && demuxer && demuxer->video) { // everything is OK to be checked float tmp = mux_v->timer + next_edl_record->start_sec - demuxer->video->pts; diff -urN main/m_option.c main_endpos9/m_option.c --- main/m_option.c 2005-11-28 17:31:15.725280016 +0100 +++ main_endpos9/m_option.c 2005-12-01 02:05:46.767984488 +0100 @@ -1154,6 +1154,78 @@ }; +// Time or size (-endpos) + +static int parse_time_size(m_option_t* opt,char *name, char *param, void* dst, int src) { + + if (dst == NULL) + return 0; + + m_time_size_t* ts = dst; + ts->pos=0; + + char unit[4]; + int a,b; + float d; + double end_at; + + if (param == NULL || strlen(param) == 0) + return M_OPT_MISSING_PARAM; + + /* End at size parsing */ + if(sscanf(param, "%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 if(!strcasecmp(unit, "gb")) + end_at *= 1024*1024*1024; + else { + mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Option %s: unknown unit: '%s'\n", + name,unit); + return M_OPT_INVALID; + } + ts->type = END_AT_SIZE; + ts->pos = end_at; + return 1; + } + + /* End at time parsing. This has to be last because of + * sscanf("%f", ...) below */ + if (sscanf(param, "%d:%d:%f", &a, &b, &d) == 3) + end_at = 3600*a + 60*b + d; + else if (sscanf(param, "%d:%f", &a, &d) == 2) + end_at = 60*a + d; + else if (sscanf(param, "%f", &d) == 1) + end_at = d; + else { + mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Option %s: invalid time or size: '%s'\n", + name,param); + return M_OPT_INVALID; + } + + ts->type = END_AT_TIME; + ts->pos = end_at; + + return 1; +} + +m_option_type_t m_option_type_time_size = { + "Time or size", + "", + sizeof(m_time_size_t), + 0, + parse_time_size, + NULL, + copy_opt, + copy_opt, + NULL, + NULL +}; + + //// Objects (i.e. filters, etc) settings #include "m_struct.h" diff -urN main/m_option.h main_endpos9/m_option.h --- main/m_option.h 2005-11-28 17:31:15.749276368 +0100 +++ main_endpos9/m_option.h 2005-12-01 02:05:46.770984032 +0100 @@ -15,6 +15,7 @@ extern m_option_type_t m_option_type_string; extern m_option_type_t m_option_type_string_list; extern m_option_type_t m_option_type_position; +extern m_option_type_t m_option_type_time_size; extern m_option_type_t m_option_type_print; extern m_option_type_t m_option_type_print_indirect; @@ -37,6 +38,14 @@ typedef m_opt_func_param_t cfg_func_param_t; typedef m_opt_func_t cfg_func_t; +#define END_AT_NONE 0 +#define END_AT_TIME 1 +#define END_AT_SIZE 2 +typedef struct { + double pos; + int type; +} m_time_size_t; + typedef struct { void** list; void* name_off; @@ -97,6 +106,7 @@ #define CONF_TYPE_OBJ_PRESETS (&m_option_type_obj_presets) #define CONF_TYPE_CUSTOM_URL (&m_option_type_custom_url) #define CONF_TYPE_OBJ_PARAMS (&m_option_type_obj_params) +#define CONF_TYPE_TIME_SIZE (&m_option_type_time_size) ///////////////////////////////////////////////////////////////////////////////////////////// diff -urN main/mplayer.c main_endpos9/mplayer.c --- main/mplayer.c 2005-11-28 17:31:54.000461304 +0100 +++ main_endpos9/mplayer.c 2005-12-01 02:05:46.778982816 +0100 @@ -243,6 +243,8 @@ static int loop_times=-1; static int loop_seek=0; +static m_time_size_t end_at = { .type = END_AT_NONE, .pos = 0 }; + // A/V sync: int autosync=0; // 30 might be a good default value. @@ -2626,11 +2628,17 @@ if(!sh_video) { // handle audio-only case: - if(!quiet) { - float a_pos = sh_audio->delay - audio_out->get_delay() * playback_speed; + + float a_pos=0; + 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) eof = PT_NEXT_ENTRY; + + if( (d_audio->eof && sh_audio->a_in_buffer_len <= 0) || + (end_at.type == END_AT_TIME && end_at.pos < a_pos) ) + eof = PT_NEXT_ENTRY; } else { @@ -2851,6 +2859,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.pos < sh_video->pts ) + break; + if(vo_config_count) video_out->flip_page(); if (play_n_frames >= 0) { --play_n_frames; @@ -4152,6 +4164,15 @@ seek_to_sec = NULL; } + if (end_at.type != END_AT_NONE) { + if(end_at.type == END_AT_SIZE) { + mp_msg(MSGT_CPLAYER, MSGL_WARN, MSGTR_MPEndposNoSizeBased); + end_at.type = END_AT_NONE; + } else { + end_at.pos += rel_seek_secs; + } + } + /* Looping. */ if(eof==1 && loop_times>=0) { int l = loop_times;