[Ffmpeg-devel] [PATCH] fix -ab default
Michael Niedermayer
michaelni
Tue Mar 6 20:52:18 CET 2007
Hi
attached patch adds a new avcodec_get_context_defaults2() and
avcodec_alloc_context2() which take an additional CodecType as argument
it adds a av_opt_set_defaults2() which has a flags parameter so only
specific defaults are used
and it adds a -ab to AVOption whos flags specify that it only applies for
audio and -b only applies to video
and last it makes ffmpeg.c use the new code
all that together fixes the -ab default (note the recent changes to
command line option handling did not truly introduce this bug it was
rather hidden by the old code ...)
so everyone who flamed please now read and comment! that is
comment now not after i applied it!
is CodecType a good choice as argument for the default setting function?
i choose it as it was slightly easier, alternatives are AVCodec and
CodecID, the advantage of the later 2 would be that we would move
toward being able to have per codec defaults which could come in handy
for x264
is the flag parameter as ive implemented for av_opt_set_defaults2() ideal
or does anyone has a better more flexible idea?
PS: yes this patch matters independant of the recent change, even if
its reverted this change is still usefull ...
--
Michael GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB
Those who are too smart to engage in politics are punished by being
governed by those who are dumber. -- Plato
-------------- next part --------------
Index: ffmpeg.c
===================================================================
--- ffmpeg.c (revision 8273)
+++ ffmpeg.c (working copy)
@@ -3760,7 +3760,7 @@
av_register_all();
for(i=0; i<CODEC_TYPE_NB; i++)
- avctx_opts[i]= avcodec_alloc_context();
+ 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,17 @@
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;
+ av_opt_set_defaults2(s, flags);
s->rc_eq= "tex^qComp";
s->time_base= (AVRational){0,1};
@@ -752,16 +758,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/opt.c
===================================================================
--- libavcodec/opt.c (revision 8273)
+++ libavcodec/opt.c (working copy)
@@ -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)
@@ -79,5 +79,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/c5f77884/attachment.pgp>
More information about the ffmpeg-devel
mailing list