[MPlayer-dev-eng] Patch: Option to specify when to stop encoding
Fredrik Kuivinen
freku045 at student.liu.se
Mon Jan 14 18:01:58 CET 2002
Hi
This patch adds a command line option to mencoder. The purpose of this option
is to end the encoding at a specific place.
Example:
mencoder -end-at 10mb ...
Stop encoding when the output file has reached a size of 10MB
mencoder -end-at 10kb ...
Stop encoding when the output file is 10KB
mencoder -end-at 1:23:12 ...
Stop encoding when 1 hour 23 minutes and 12 seconds of the input file has been
encoded. (Same syntax as -ss in mplayer.)
Some kind of stop-at-chapter-n would be nice too but I don't know where to add
it and I don't own any dvds so I wouldn't be able to test it anyway.
/ Fredrik Kuivinen
-------------- next part --------------
Index: cfg-mencoder.h
===================================================================
RCS file: /cvsroot/mplayer/main/cfg-mencoder.h,v
retrieving revision 1.16
diff -u -3 -p -r1.16 cfg-mencoder.h
--- cfg-mencoder.h 26 Dec 2001 19:45:44 -0000 1.16
+++ cfg-mencoder.h 14 Jan 2002 16:50:33 -0000
@@ -88,7 +88,9 @@ struct config oac_conf[]={
struct config conf[]={
/* name, pointer, type, flags, min, max */
{"include", cfg_include, CONF_TYPE_FUNC_PARAM, 0, 0, 0}, /* this must be the first!!! */
-
+
+ {"end-at", parse_end_at, CONF_TYPE_FUNC_PARAM, 0, 0, 0},
+
{"ofps", &force_ofps, CONF_TYPE_FLOAT, CONF_MIN, 0, 0},
{"o", &out_filename, CONF_TYPE_STRING, 0, 0, 0},
Index: mencoder.c
===================================================================
RCS file: /cvsroot/mplayer/main/mencoder.c,v
retrieving revision 1.56
diff -u -3 -p -r1.56 mencoder.c
--- mencoder.c 11 Jan 2002 16:06:44 -0000 1.56
+++ mencoder.c 14 Jan 2002 16:50:35 -0000
@@ -177,6 +177,8 @@ static int cfg_include(struct config *co
return parse_config_file(conf, filename);
}
+static int parse_end_at(struct config *conf, const char* param);
+
#include "get_path.c"
#include "cfg-mplayer-def.h"
@@ -302,6 +304,10 @@ int dec_audio(sh_audio_t *sh_audio,unsig
static int 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 int end_at;
+
static void exit_sighandler(int x){
eof=1;
interrupted=1;
@@ -1040,6 +1046,10 @@ while(!eof){
int in_size;
int skip_flag=0; // 1=skip -1=duplicate
+ if((end_at_type == END_AT_SIZE && end_at <= ftell(muxer_f)) ||
+ (end_at_type == END_AT_TIME && end_at < sh_video->timer))
+ play_n_frames = 0;
+
if(play_n_frames>=0){
--play_n_frames;
if(play_n_frames<0) break;
@@ -1339,4 +1349,54 @@ printf("\nAudio stream: %8.3f kbit/s (%
if(stream) free_stream(stream); // kill cache thread
return interrupted;
+}
+
+static int parse_end_at(struct config *conf, const char* param)
+{
+ int i;
+
+ end_at_type = END_AT_NONE;
+
+ /* End at size parsing */
+ {
+ char unit[4];
+
+ end_at_type = END_AT_SIZE;
+
+ if(sscanf(param, "%d%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(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
+ end_at_type = END_AT_NONE;
+ }
+
+ if(end_at_type == END_AT_NONE)
+ return ERR_FUNC_ERR;
+
+ return 1;
}
More information about the MPlayer-dev-eng
mailing list