#endif
const char **opt_names;
+const char **opt_values;
static int opt_name_count;
AVCodecContext *avcodec_opts[AVMEDIA_TYPE_NB];
AVFormatContext *avformat_opts;
exit(1);
}
if (!o) {
+ AVCodec *p = NULL;
+ while ((p=av_codec_next(p))){
+ AVClass *c= p->priv_class;
+ if(c && av_find_opt(&c, opt, NULL, 0, 0))
+ break;
+ }
+ if(!p){
fprintf(stderr, "Unrecognized option '%s'\n", opt);
exit(1);
+ }
}
// av_log(NULL, AV_LOG_ERROR, "%s:%s: %f 0x%0X\n", opt, arg, av_get_double(avcodec_opts, opt, NULL), (int)av_get_int(avcodec_opts, opt, NULL));
//FIXME we should always use avcodec_opts, ... for storing options so there will not be any need to keep track of what i set over this
+ opt_values= av_realloc(opt_values, sizeof(void*)*(opt_name_count+1));
+ opt_values[opt_name_count]= o ? NULL : arg;
opt_names= av_realloc(opt_names, sizeof(void*)*(opt_name_count+1));
- opt_names[opt_name_count++]= o->name;
+ opt_names[opt_name_count++]= o ? o->name : opt;
if ((*avcodec_opts && avcodec_opts[0]->debug) || (avformat_opts && avformat_opts->debug))
av_log_set_level(AV_LOG_DEBUG);
return 0;
}
-void set_context_opts(void *ctx, void *opts_ctx, int flags)
+void set_context_opts(void *ctx, void *opts_ctx, int flags, AVCodec *codec)
{
int i;
+ void *priv_ctx=NULL;
+ if(!strcmp("AVCodecContext", (*(AVClass**)ctx)->class_name)){
+ AVCodecContext *avctx= ctx;
+ if(codec && codec->priv_class && avctx->priv_data){
+ priv_ctx= avctx->priv_data;
+ }
+ }
for(i=0; i<opt_name_count; i++){
char buf[256];
const AVOption *opt;
/* if an option with name opt_names[i] is present in opts_ctx then str is non-NULL */
if(str && ((opt->flags & flags) == flags))
av_set_string3(ctx, opt_names[i], str, 1, NULL);
+ /* We need to use a differnt system to pass options to the private context because
+ it is not known which codec and thus context kind that will be when parsing options
+ we thus use opt_values directly instead of opts_ctx */
+ if(!str && priv_ctx && av_get_string(priv_ctx, opt_names[i], &opt, buf, sizeof(buf))){
+ av_set_string3(priv_ctx, opt_names[i], opt_values[i], 1, NULL);
+ }
}
}
ap->channel = video_channel;
ap->standard = video_standard;
- set_context_opts(ic, avformat_opts, AV_OPT_FLAG_DECODING_PARAM);
+ set_context_opts(ic, avformat_opts, AV_OPT_FLAG_DECODING_PARAM, NULL);
ic->video_codec_id =
find_codec_or_die(video_codec_name , AVMEDIA_TYPE_VIDEO , 0,
avcodec_thread_init(dec, thread_count);
switch (dec->codec_type) {
case AVMEDIA_TYPE_AUDIO:
- set_context_opts(dec, avcodec_opts[AVMEDIA_TYPE_AUDIO], AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_DECODING_PARAM);
+ input_codecs[nb_icodecs++] = avcodec_find_decoder_by_name(audio_codec_name);
+ set_context_opts(dec, avcodec_opts[AVMEDIA_TYPE_AUDIO], AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_DECODING_PARAM, input_codecs[nb_icodecs-1]);
//fprintf(stderr, "\nInput Audio channels: %d", dec->channels);
channel_layout = dec->channel_layout;
audio_channels = dec->channels;
audio_sample_rate = dec->sample_rate;
audio_sample_fmt = dec->sample_fmt;
- input_codecs[nb_icodecs++] = avcodec_find_decoder_by_name(audio_codec_name);
if(audio_disable)
st->discard= AVDISCARD_ALL;
/* Note that av_find_stream_info can add more streams, and we
audio_sample_rate >>= dec->lowres;
break;
case AVMEDIA_TYPE_VIDEO:
- set_context_opts(dec, avcodec_opts[AVMEDIA_TYPE_VIDEO], AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM);
+ input_codecs[nb_icodecs++] = avcodec_find_decoder_by_name(video_codec_name);
+ set_context_opts(dec, avcodec_opts[AVMEDIA_TYPE_VIDEO], AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_DECODING_PARAM, input_codecs[nb_icodecs-1]);
frame_height = dec->height;
frame_width = dec->width;
if(ic->streams[i]->sample_aspect_ratio.num)
frame_rate.num = rfps;
frame_rate.den = rfps_base;
- input_codecs[nb_icodecs++] = avcodec_find_decoder_by_name(video_codec_name);
if(video_disable)
st->discard= AVDISCARD_ALL;
else if(video_discard)
AVStream *st;
AVCodecContext *video_enc;
enum CodecID codec_id;
+ AVCodec *codec= NULL;
st = av_new_stream(oc, streamid_map[oc->nb_streams]);
if (!st) {
fprintf(stderr, "Could not alloc stream\n");
ffmpeg_exit(1);
}
- avcodec_get_context_defaults2(st->codec, AVMEDIA_TYPE_VIDEO);
+
+ if(!video_stream_copy){
+ if (video_codec_name) {
+ codec_id = find_codec_or_die(video_codec_name, AVMEDIA_TYPE_VIDEO, 1,
+ avcodec_opts[AVMEDIA_TYPE_VIDEO]->strict_std_compliance);
+ codec = avcodec_find_encoder_by_name(video_codec_name);
+ output_codecs[nb_ocodecs] = codec;
+ } else {
+ codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, AVMEDIA_TYPE_VIDEO);
+ codec = avcodec_find_encoder(codec_id);
+ }
+ }
+
+ avcodec_get_context_defaults3(st->codec, codec);
bitstream_filters[nb_output_files][oc->nb_streams - 1]= video_bitstream_filters;
video_bitstream_filters= NULL;
} else {
const char *p;
int i;
- AVCodec *codec;
AVRational fps= frame_rate.num ? frame_rate : (AVRational){25,1};
- if (video_codec_name) {
- codec_id = find_codec_or_die(video_codec_name, AVMEDIA_TYPE_VIDEO, 1,
- avcodec_opts[AVMEDIA_TYPE_VIDEO]->strict_std_compliance);
- codec = avcodec_find_encoder_by_name(video_codec_name);
- output_codecs[nb_ocodecs] = codec;
- } else {
- codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, AVMEDIA_TYPE_VIDEO);
- codec = avcodec_find_encoder(codec_id);
- }
-
video_enc->codec_id = codec_id;
-
- set_context_opts(video_enc, avcodec_opts[AVMEDIA_TYPE_VIDEO], AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM);
+ set_context_opts(video_enc, avcodec_opts[AVMEDIA_TYPE_VIDEO], AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM, codec);
if (codec && codec->supported_framerates && !force_fps)
fps = codec->supported_framerates[av_find_nearest_q_idx(fps, codec->supported_framerates)];
static void new_audio_stream(AVFormatContext *oc)
{
AVStream *st;
+ AVCodec *codec= NULL;
AVCodecContext *audio_enc;
enum CodecID codec_id;
fprintf(stderr, "Could not alloc stream\n");
ffmpeg_exit(1);
}
- avcodec_get_context_defaults2(st->codec, AVMEDIA_TYPE_AUDIO);
+
+ if(!audio_stream_copy){
+ if (audio_codec_name) {
+ codec_id = find_codec_or_die(audio_codec_name, AVMEDIA_TYPE_AUDIO, 1,
+ avcodec_opts[AVMEDIA_TYPE_AUDIO]->strict_std_compliance);
+ codec = avcodec_find_encoder_by_name(audio_codec_name);
+ output_codecs[nb_ocodecs] = codec;
+ } else {
+ codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, AVMEDIA_TYPE_AUDIO);
+ codec = avcodec_find_encoder(codec_id);
+ }
+ }
+
+ avcodec_get_context_defaults3(st->codec, codec);
bitstream_filters[nb_output_files][oc->nb_streams - 1]= audio_bitstream_filters;
audio_bitstream_filters= NULL;
audio_enc->channels = audio_channels;
audio_enc->sample_rate = audio_sample_rate;
} else {
- AVCodec *codec;
-
- set_context_opts(audio_enc, avcodec_opts[AVMEDIA_TYPE_AUDIO], AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM);
-
- if (audio_codec_name) {
- codec_id = find_codec_or_die(audio_codec_name, AVMEDIA_TYPE_AUDIO, 1,
- avcodec_opts[AVMEDIA_TYPE_AUDIO]->strict_std_compliance);
- codec = avcodec_find_encoder_by_name(audio_codec_name);
- output_codecs[nb_ocodecs] = codec;
- } else {
- codec_id = av_guess_codec(oc->oformat, NULL, oc->filename, NULL, AVMEDIA_TYPE_AUDIO);
- codec = avcodec_find_encoder(codec_id);
- }
audio_enc->codec_id = codec_id;
+ set_context_opts(audio_enc, avcodec_opts[AVMEDIA_TYPE_AUDIO], AV_OPT_FLAG_AUDIO_PARAM | AV_OPT_FLAG_ENCODING_PARAM, codec);
if (audio_qscale > QSCALE_NONE) {
audio_enc->flags |= CODEC_FLAG_QSCALE;
static void new_subtitle_stream(AVFormatContext *oc)
{
AVStream *st;
+ AVCodec *codec=NULL;
AVCodecContext *subtitle_enc;
st = av_new_stream(oc, streamid_map[oc->nb_streams]);
fprintf(stderr, "Could not alloc stream\n");
ffmpeg_exit(1);
}
- avcodec_get_context_defaults2(st->codec, AVMEDIA_TYPE_SUBTITLE);
+ subtitle_enc = st->codec;
+ if(!subtitle_stream_copy){
+ subtitle_enc->codec_id = find_codec_or_die(subtitle_codec_name, AVMEDIA_TYPE_SUBTITLE, 1,
+ avcodec_opts[AVMEDIA_TYPE_SUBTITLE]->strict_std_compliance);
+ codec= output_codecs[nb_ocodecs] = avcodec_find_encoder_by_name(subtitle_codec_name);
+ }
+ avcodec_get_context_defaults3(st->codec, codec);
bitstream_filters[nb_output_files][oc->nb_streams - 1]= subtitle_bitstream_filters;
subtitle_bitstream_filters= NULL;
- subtitle_enc = st->codec;
subtitle_enc->codec_type = AVMEDIA_TYPE_SUBTITLE;
if(subtitle_codec_tag)
if (subtitle_stream_copy) {
st->stream_copy = 1;
} else {
- set_context_opts(avcodec_opts[AVMEDIA_TYPE_SUBTITLE], subtitle_enc, AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_ENCODING_PARAM);
- subtitle_enc->codec_id = find_codec_or_die(subtitle_codec_name, AVMEDIA_TYPE_SUBTITLE, 1,
- avcodec_opts[AVMEDIA_TYPE_SUBTITLE]->strict_std_compliance);
- output_codecs[nb_ocodecs] = avcodec_find_encoder_by_name(subtitle_codec_name);
+ set_context_opts(avcodec_opts[AVMEDIA_TYPE_SUBTITLE], subtitle_enc, AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_ENCODING_PARAM, codec);
}
nb_ocodecs++;
oc->loop_output = loop_output;
oc->flags |= AVFMT_FLAG_NONBLOCK;
- set_context_opts(oc, avformat_opts, AV_OPT_FLAG_ENCODING_PARAM);
+ set_context_opts(oc, avformat_opts, AV_OPT_FLAG_ENCODING_PARAM, NULL);
memset(streamid_map, 0, sizeof(streamid_map));
}