[Ffmpeg-devel] [PATCH] fix -ab default
Michael Niedermayer
michaelni
Tue Mar 6 22:27:05 CET 2007
Hi
On Tue, Mar 06, 2007 at 09:07:44PM +0100, Benoit Fouet wrote:
[...]
> > -{"b", "set bitrate (in bits/s)", OFFSET(bit_rate), FF_OPT_TYPE_INT, AV_CODEC_DEFAULT_BITRATE, INT_MIN, INT_MAX, V|A|E},
> > +{"b", "set bitrate (in bits/s)", OFFSET(bit_rate), FF_OPT_TYPE_INT, AV_CODEC_DEFAULT_BITRATE, INT_MIN, INT_MAX, V|E},
> > +{"ab", "set bitrate (in bits/s)", OFFSET(bit_rate), FF_OPT_TYPE_INT, 64*1000, INT_MIN, INT_MAX, A|E},
> >
> why not a define, as for video one ?
because it doesnt work
[...]
> >
> > - av_opt_set_defaults(s);
> > + if(codec_type == CODEC_TYPE_AUDIO)
> > + flags= AV_OPT_FLAG_AUDIO_PARAM;
> > + else if(codec_type == CODEC_TYPE_VIDEO)
> > + flags= AV_OPT_FLAG_VIDEO_PARAM;
> > + av_opt_set_defaults2(s, flags);
> >
> no AV_OPT_FLAG_SUBTITLE_PARAM handling ?
fixed
ive also fixed the missing prototype in avcodec.h
new patch attached
with it
-ab X -b Y also works like before with the exception that -ab is in bits/sec
so are there any comments about the API changes? as they where what i
actually would like feedback on, adding a AV_OPT_FLAG_SUBTITLE_PARAM
later is trivial changing API is always problematic ...
[...]
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Let us carefully observe those good qualities wherein our enemies excel us
and endeavor to excel them, by avoiding what is faulty, and imitating what
is excellent in them. -- Plutarch
-------------- next part --------------
Index: ffmpeg.c
===================================================================
--- ffmpeg.c (revision 8273)
+++ ffmpeg.c (working copy)
@@ -2705,6 +2705,7 @@
fprintf(stderr, "Could not alloc stream\n");
exit(1);
}
+ avcodec_get_context_defaults2(st->codec, CODEC_TYPE_VIDEO);
bitstream_filters[nb_output_files][oc->nb_streams - 1]= video_bitstream_filters;
video_bitstream_filters= NULL;
@@ -2863,6 +2864,7 @@
fprintf(stderr, "Could not alloc stream\n");
exit(1);
}
+ avcodec_get_context_defaults2(st->codec, CODEC_TYPE_AUDIO);
bitstream_filters[nb_output_files][oc->nb_streams - 1]= audio_bitstream_filters;
audio_bitstream_filters= NULL;
@@ -2939,6 +2941,7 @@
fprintf(stderr, "Could not alloc stream\n");
exit(1);
}
+ avcodec_get_context_defaults2(st->codec, CODEC_TYPE_SUBTITLE);
subtitle_enc = st->codec;
subtitle_enc->codec_type = CODEC_TYPE_SUBTITLE;
@@ -3507,9 +3510,14 @@
static int opt_default(const char *opt, const char *arg){
int type;
- const AVOption *o;
- for(type=0; type<CODEC_TYPE_NB; type++)
- o = av_set_string(avctx_opts[type], opt, arg);
+ const AVOption *o= NULL;
+ int opt_types[]={AV_OPT_FLAG_VIDEO_PARAM, AV_OPT_FLAG_AUDIO_PARAM, 0, AV_OPT_FLAG_SUBTITLE_PARAM, 0};
+ const AVOption *o2 = av_find_opt(avctx_opts[0], opt, NULL);
+
+ for(type=0; type<CODEC_TYPE_NB; type++){
+ if(o2 && (o2->flags & opt_types[type]))
+ o = av_set_string(avctx_opts[type], opt, arg);
+ }
if(!o)
o = av_set_string(avformat_opts, opt, arg);
if(!o){
@@ -3759,8 +3767,9 @@
av_register_all();
- for(i=0; i<CODEC_TYPE_NB; i++)
- avctx_opts[i]= avcodec_alloc_context();
+ for(i=0; i<CODEC_TYPE_NB; i++){
+ avctx_opts[i]= avcodec_alloc_context2(i);
+ }
avformat_opts = av_alloc_format_context();
if (argc <= 1)
Index: libavcodec/utils.c
===================================================================
--- libavcodec/utils.c (revision 8273)
+++ libavcodec/utils.c (working copy)
@@ -411,7 +411,8 @@
#define AV_CODEC_DEFAULT_BITRATE 200*1000
static const AVOption options[]={
-{"b", "set bitrate (in bits/s)", OFFSET(bit_rate), FF_OPT_TYPE_INT, AV_CODEC_DEFAULT_BITRATE, INT_MIN, INT_MAX, V|A|E},
+{"b", "set bitrate (in bits/s)", OFFSET(bit_rate), FF_OPT_TYPE_INT, AV_CODEC_DEFAULT_BITRATE, INT_MIN, INT_MAX, V|E},
+{"ab", "set bitrate (in bits/s)", OFFSET(bit_rate), FF_OPT_TYPE_INT, 64*1000, INT_MIN, INT_MAX, A|E},
{"bt", "set video bitrate tolerance (in bits/s)", OFFSET(bit_rate_tolerance), FF_OPT_TYPE_INT, AV_CODEC_DEFAULT_BITRATE*20, 1, INT_MAX, V|E},
{"flags", NULL, OFFSET(flags), FF_OPT_TYPE_FLAGS, DEFAULT, INT_MIN, INT_MAX, V|A|E|D, "flags"},
{"mv4", "use four motion vector by macroblock (mpeg4)", 0, FF_OPT_TYPE_CONST, CODEC_FLAG_4MV, INT_MIN, INT_MAX, V|E, "flags"},
@@ -731,12 +732,19 @@
static AVClass av_codec_context_class = { "AVCodecContext", context_to_name, options };
-void avcodec_get_context_defaults(AVCodecContext *s){
+void avcodec_get_context_defaults2(AVCodecContext *s, enum CodecType codec_type){
+ int flags=0;
memset(s, 0, sizeof(AVCodecContext));
s->av_class= &av_codec_context_class;
- av_opt_set_defaults(s);
+ if(codec_type == CODEC_TYPE_AUDIO)
+ flags= AV_OPT_FLAG_AUDIO_PARAM;
+ else if(codec_type == CODEC_TYPE_VIDEO)
+ flags= AV_OPT_FLAG_VIDEO_PARAM;
+ else if(codec_type == CODEC_TYPE_SUBTITLE)
+ flags= AV_OPT_FLAG_SUBTITLE_PARAM;
+ av_opt_set_defaults2(s, flags);
s->rc_eq= "tex^qComp";
s->time_base= (AVRational){0,1};
@@ -752,16 +760,24 @@
s->reget_buffer= avcodec_default_reget_buffer;
}
-AVCodecContext *avcodec_alloc_context(void){
+AVCodecContext *avcodec_alloc_context2(enum CodecType codec_type){
AVCodecContext *avctx= av_malloc(sizeof(AVCodecContext));
if(avctx==NULL) return NULL;
- avcodec_get_context_defaults(avctx);
+ avcodec_get_context_defaults2(avctx, codec_type);
return avctx;
}
+void avcodec_get_context_defaults(AVCodecContext *s){
+ avcodec_get_context_defaults2(s, CODEC_TYPE_UNKNOWN);
+}
+
+AVCodecContext *avcodec_alloc_context(void){
+ return avcodec_alloc_context2(CODEC_TYPE_UNKNOWN);
+}
+
void avcodec_get_frame_defaults(AVFrame *pic){
memset(pic, 0, sizeof(AVFrame));
Index: libavcodec/avcodec.h
===================================================================
--- libavcodec/avcodec.h (revision 8273)
+++ libavcodec/avcodec.h (working copy)
@@ -2631,6 +2631,8 @@
*/
void avcodec_get_context_defaults(AVCodecContext *s);
+void avcodec_get_context_defaults2(AVCodecContext *s, enum CodecType);
+
/**
* Allocates an AVCodecContext and sets its fields to default values. The
* resulting struct can be deallocated by simply calling av_free().
@@ -2640,6 +2642,8 @@
*/
AVCodecContext *avcodec_alloc_context(void);
+AVCodecContext *avcodec_alloc_context2(enum CodecType);
+
/**
* Sets the fields of the given AVFrame to default values.
*
Index: libavcodec/opt.c
===================================================================
--- libavcodec/opt.c (revision 8273)
+++ libavcodec/opt.c (working copy)
@@ -31,7 +31,7 @@
#include "eval.h"
//FIXME order them and do a bin search
-static const AVOption *find_opt(void *v, const char *name, const char *unit){
+const AVOption *av_find_opt(void *v, const char *name, const char *unit){
AVClass *c= *(AVClass**)v; //FIXME silly way of storing AVClass
const AVOption *o= c->option;
@@ -49,7 +49,7 @@
}
static const AVOption *av_set_number(void *obj, const char *name, double num, int den, int64_t intnum){
- const AVOption *o= find_opt(obj, name, NULL);
+ const AVOption *o= av_find_opt(obj, name, NULL);
void *dst;
if(!o || o->offset<=0)
return NULL;
@@ -109,7 +109,7 @@
};
const AVOption *av_set_string(void *obj, const char *name, const char *val){
- const AVOption *o= find_opt(obj, name, NULL);
+ const AVOption *o= av_find_opt(obj, name, NULL);
if(o && o->offset==0 && o->type == FF_OPT_TYPE_CONST && o->unit){
return set_all_opt(obj, o->unit, o->default_val);
}
@@ -133,7 +133,7 @@
d = ff_eval2(buf, const_values, const_names, NULL, NULL, NULL, NULL, NULL, &error);
if(isnan(d)) {
- const AVOption *o_named= find_opt(obj, buf, o->unit);
+ const AVOption *o_named= av_find_opt(obj, buf, o->unit);
if(o_named && o_named->type == FF_OPT_TYPE_CONST)
d= o_named->default_val;
else if(!strcmp(buf, "default")) d= o->default_val;
@@ -180,7 +180,7 @@
* @param buf_len allocated length in bytes of buf
*/
const char *av_get_string(void *obj, const char *name, const AVOption **o_out, char *buf, int buf_len){
- const AVOption *o= find_opt(obj, name, NULL);
+ const AVOption *o= av_find_opt(obj, name, NULL);
void *dst;
if(!o || o->offset<=0)
return NULL;
@@ -206,7 +206,7 @@
}
static int av_get_number(void *obj, const char *name, const AVOption **o_out, double *num, int *den, int64_t *intnum){
- const AVOption *o= find_opt(obj, name, NULL);
+ const AVOption *o= av_find_opt(obj, name, NULL);
void *dst;
if(!o || o->offset<=0)
goto error;
@@ -343,10 +343,12 @@
*
* @param s AVCodecContext or AVFormatContext for which the defaults will be set
*/
-void av_opt_set_defaults(void *s)
+void av_opt_set_defaults2(void *s, int flags)
{
const AVOption *opt = NULL;
while ((opt = av_next_option(s, opt)) != NULL) {
+ if((opt->flags & flags) != flags)
+ continue;
switch(opt->type) {
case FF_OPT_TYPE_CONST:
/* Nothing to be done here */
@@ -379,3 +381,6 @@
}
}
+void av_opt_set_defaults(void *s){
+ av_opt_set_defaults2(s, 0);
+}
Index: libavcodec/opt.h
===================================================================
--- libavcodec/opt.h (revision 8273)
+++ libavcodec/opt.h (working copy)
@@ -68,6 +68,7 @@
} AVOption;
+const AVOption *av_find_opt(void *v, const char *name, const char *unit);
const AVOption *av_set_string(void *obj, const char *name, const char *val);
const AVOption *av_set_double(void *obj, const char *name, double n);
const AVOption *av_set_q(void *obj, const char *name, AVRational n);
@@ -79,5 +80,6 @@
const AVOption *av_next_option(void *obj, const AVOption *last);
int av_opt_show(void *obj, void *av_log_obj);
void av_opt_set_defaults(void *s);
+void av_opt_set_defaults2(void *s, int flags);
#endif
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
URL: <http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/attachments/20070306/148954b5/attachment.pgp>
More information about the ffmpeg-devel
mailing list