Originally committed as revision 13756 to svn://svn.ffmpeg.org/ffmpeg/trunk
Stefano Sabatini authored on 2008/06/12 20:28:49... | ... |
@@ -2688,6 +2688,19 @@ static enum CodecID find_codec_or_die(const char *name, int type, int encoder) |
2688 | 2688 |
return codec->id; |
2689 | 2689 |
} |
2690 | 2690 |
|
2691 |
+static void set_context_opts(void *ctx, void *opts_ctx, int flags) |
|
2692 |
+{ |
|
2693 |
+ int i; |
|
2694 |
+ for(i=0; i<opt_name_count; i++){ |
|
2695 |
+ char buf[256]; |
|
2696 |
+ const AVOption *opt; |
|
2697 |
+ const char *str= av_get_string(opts_ctx, opt_names[i], &opt, buf, sizeof(buf)); |
|
2698 |
+ /* if an option with name opt_names[i] is present in opts_ctx then str is non-NULL */ |
|
2699 |
+ if(str && ((opt->flags & flags) == flags)) |
|
2700 |
+ av_set_string(ctx, opt_names[i], str); |
|
2701 |
+ } |
|
2702 |
+} |
|
2703 |
+ |
|
2691 | 2704 |
static void opt_input_file(const char *filename) |
2692 | 2705 |
{ |
2693 | 2706 |
AVFormatContext *ic; |
... | ... |
@@ -2720,13 +2733,7 @@ static void opt_input_file(const char *filename) |
2720 | 2720 |
if(pgmyuv_compatibility_hack) |
2721 | 2721 |
ap->video_codec_id= CODEC_ID_PGMYUV; |
2722 | 2722 |
|
2723 |
- for(i=0; i<opt_name_count; i++){ |
|
2724 |
- char buf[256]; |
|
2725 |
- const AVOption *opt; |
|
2726 |
- const char *str= av_get_string(avformat_opts, opt_names[i], &opt, buf, sizeof(buf)); |
|
2727 |
- if(str && (opt->flags & AV_OPT_FLAG_DECODING_PARAM)) |
|
2728 |
- av_set_string(ic, opt_names[i], str); |
|
2729 |
- } |
|
2723 |
+ set_context_opts(ic, avformat_opts, AV_OPT_FLAG_DECODING_PARAM); |
|
2730 | 2724 |
|
2731 | 2725 |
ic->video_codec_id = find_codec_or_die(video_codec_name , CODEC_TYPE_VIDEO , 0); |
2732 | 2726 |
ic->audio_codec_id = find_codec_or_die(audio_codec_name , CODEC_TYPE_AUDIO , 0); |
... | ... |
@@ -2773,20 +2780,13 @@ static void opt_input_file(const char *filename) |
2773 | 2773 |
|
2774 | 2774 |
/* update the current parameters so that they match the one of the input stream */ |
2775 | 2775 |
for(i=0;i<ic->nb_streams;i++) { |
2776 |
- int j; |
|
2777 | 2776 |
AVCodecContext *enc = ic->streams[i]->codec; |
2778 | 2777 |
if(thread_count>1) |
2779 | 2778 |
avcodec_thread_init(enc, thread_count); |
2780 | 2779 |
enc->thread_count= thread_count; |
2781 | 2780 |
switch(enc->codec_type) { |
2782 | 2781 |
case CODEC_TYPE_AUDIO: |
2783 |
- for(j=0; j<opt_name_count; j++){ |
|
2784 |
- char buf[256]; |
|
2785 |
- const AVOption *opt; |
|
2786 |
- const char *str= av_get_string(avctx_opts[CODEC_TYPE_AUDIO], opt_names[j], &opt, buf, sizeof(buf)); |
|
2787 |
- if(str && (opt->flags & AV_OPT_FLAG_AUDIO_PARAM) && (opt->flags & AV_OPT_FLAG_DECODING_PARAM)) |
|
2788 |
- av_set_string(enc, opt_names[j], str); |
|
2789 |
- } |
|
2782 |
+ set_context_opts(enc, avctx_opts[CODEC_TYPE_AUDIO], AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_DECODING_PARAM); |
|
2790 | 2783 |
//fprintf(stderr, "\nInput Audio channels: %d", enc->channels); |
2791 | 2784 |
audio_channels = enc->channels; |
2792 | 2785 |
audio_sample_rate = enc->sample_rate; |
... | ... |
@@ -2794,13 +2794,7 @@ static void opt_input_file(const char *filename) |
2794 | 2794 |
ic->streams[i]->discard= AVDISCARD_ALL; |
2795 | 2795 |
break; |
2796 | 2796 |
case CODEC_TYPE_VIDEO: |
2797 |
- for(j=0; j<opt_name_count; j++){ |
|
2798 |
- char buf[256]; |
|
2799 |
- const AVOption *opt; |
|
2800 |
- const char *str= av_get_string(avctx_opts[CODEC_TYPE_VIDEO], opt_names[j], &opt, buf, sizeof(buf)); |
|
2801 |
- if(str && (opt->flags & AV_OPT_FLAG_VIDEO_PARAM) && (opt->flags & AV_OPT_FLAG_DECODING_PARAM)) |
|
2802 |
- av_set_string(enc, opt_names[j], str); |
|
2803 |
- } |
|
2797 |
+ set_context_opts(enc, avctx_opts[CODEC_TYPE_VIDEO], AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM); |
|
2804 | 2798 |
frame_height = enc->height; |
2805 | 2799 |
frame_width = enc->width; |
2806 | 2800 |
frame_aspect_ratio = av_q2d(enc->sample_aspect_ratio) * enc->width / enc->height; |
... | ... |
@@ -2947,13 +2941,7 @@ static void new_video_stream(AVFormatContext *oc) |
2947 | 2947 |
video_enc->codec_id = codec_id; |
2948 | 2948 |
codec = avcodec_find_encoder(codec_id); |
2949 | 2949 |
|
2950 |
- for(i=0; i<opt_name_count; i++){ |
|
2951 |
- char buf[256]; |
|
2952 |
- const AVOption *opt; |
|
2953 |
- const char *str= av_get_string(avctx_opts[CODEC_TYPE_VIDEO], opt_names[i], &opt, buf, sizeof(buf)); |
|
2954 |
- if(str && (opt->flags & AV_OPT_FLAG_VIDEO_PARAM) && (opt->flags & AV_OPT_FLAG_ENCODING_PARAM)) |
|
2955 |
- av_set_string(video_enc, opt_names[i], str); |
|
2956 |
- } |
|
2950 |
+ set_context_opts(video_enc, avctx_opts[CODEC_TYPE_VIDEO], AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM); |
|
2957 | 2951 |
|
2958 | 2952 |
video_enc->time_base.den = fps.num; |
2959 | 2953 |
video_enc->time_base.num = fps.den; |
... | ... |
@@ -3057,7 +3045,7 @@ static void new_audio_stream(AVFormatContext *oc) |
3057 | 3057 |
{ |
3058 | 3058 |
AVStream *st; |
3059 | 3059 |
AVCodecContext *audio_enc; |
3060 |
- int codec_id, i; |
|
3060 |
+ int codec_id; |
|
3061 | 3061 |
|
3062 | 3062 |
st = av_new_stream(oc, oc->nb_streams); |
3063 | 3063 |
if (!st) { |
... | ... |
@@ -3089,13 +3077,7 @@ static void new_audio_stream(AVFormatContext *oc) |
3089 | 3089 |
} else { |
3090 | 3090 |
codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, CODEC_TYPE_AUDIO); |
3091 | 3091 |
|
3092 |
- for(i=0; i<opt_name_count; i++){ |
|
3093 |
- char buf[256]; |
|
3094 |
- const AVOption *opt; |
|
3095 |
- const char *str= av_get_string(avctx_opts[CODEC_TYPE_AUDIO], opt_names[i], &opt, buf, sizeof(buf)); |
|
3096 |
- if(str && (opt->flags & AV_OPT_FLAG_AUDIO_PARAM) && (opt->flags & AV_OPT_FLAG_ENCODING_PARAM)) |
|
3097 |
- av_set_string(audio_enc, opt_names[i], str); |
|
3098 |
- } |
|
3092 |
+ set_context_opts(audio_enc, avctx_opts[CODEC_TYPE_AUDIO], AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM); |
|
3099 | 3093 |
|
3100 | 3094 |
if (audio_codec_name) |
3101 | 3095 |
codec_id = find_codec_or_die(audio_codec_name, CODEC_TYPE_AUDIO, 1); |
... | ... |
@@ -3126,7 +3108,6 @@ static void new_subtitle_stream(AVFormatContext *oc) |
3126 | 3126 |
{ |
3127 | 3127 |
AVStream *st; |
3128 | 3128 |
AVCodecContext *subtitle_enc; |
3129 |
- int i; |
|
3130 | 3129 |
|
3131 | 3130 |
st = av_new_stream(oc, oc->nb_streams); |
3132 | 3131 |
if (!st) { |
... | ... |
@@ -3143,13 +3124,7 @@ static void new_subtitle_stream(AVFormatContext *oc) |
3143 | 3143 |
if (subtitle_stream_copy) { |
3144 | 3144 |
st->stream_copy = 1; |
3145 | 3145 |
} else { |
3146 |
- for(i=0; i<opt_name_count; i++){ |
|
3147 |
- char buf[256]; |
|
3148 |
- const AVOption *opt; |
|
3149 |
- const char *str= av_get_string(avctx_opts[CODEC_TYPE_SUBTITLE], opt_names[i], &opt, buf, sizeof(buf)); |
|
3150 |
- if(str && (opt->flags & AV_OPT_FLAG_SUBTITLE_PARAM) && (opt->flags & AV_OPT_FLAG_ENCODING_PARAM)) |
|
3151 |
- av_set_string(subtitle_enc, opt_names[i], str); |
|
3152 |
- } |
|
3146 |
+ set_context_opts(avctx_opts[CODEC_TYPE_SUBTITLE], subtitle_enc, AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_ENCODING_PARAM); |
|
3153 | 3147 |
subtitle_enc->codec_id = find_codec_or_die(subtitle_codec_name, CODEC_TYPE_SUBTITLE, 1); |
3154 | 3148 |
} |
3155 | 3149 |
|
... | ... |
@@ -3201,7 +3176,7 @@ static void opt_output_file(const char *filename) |
3201 | 3201 |
{ |
3202 | 3202 |
AVFormatContext *oc; |
3203 | 3203 |
int use_video, use_audio, use_subtitle; |
3204 |
- int input_has_video, input_has_audio, input_has_subtitle, i; |
|
3204 |
+ int input_has_video, input_has_audio, input_has_subtitle; |
|
3205 | 3205 |
AVFormatParameters params, *ap = ¶ms; |
3206 | 3206 |
|
3207 | 3207 |
if (!strcmp(filename, "-")) |
... | ... |
@@ -3339,13 +3314,7 @@ static void opt_output_file(const char *filename) |
3339 | 3339 |
oc->max_delay= (int)(mux_max_delay*AV_TIME_BASE); |
3340 | 3340 |
oc->loop_output = loop_output; |
3341 | 3341 |
|
3342 |
- for(i=0; i<opt_name_count; i++){ |
|
3343 |
- char buf[256]; |
|
3344 |
- const AVOption *opt; |
|
3345 |
- const char *str= av_get_string(avformat_opts, opt_names[i], &opt, buf, sizeof(buf)); |
|
3346 |
- if(str && (opt->flags & AV_OPT_FLAG_ENCODING_PARAM)) |
|
3347 |
- av_set_string(oc, opt_names[i], str); |
|
3348 |
- } |
|
3342 |
+ set_context_opts(oc, avformat_opts, AV_OPT_FLAG_ENCODING_PARAM); |
|
3349 | 3343 |
|
3350 | 3344 |
/* reset some options */ |
3351 | 3345 |
file_oformat = NULL; |