---
ffmpeg.c | 53 ++++++++++++++++++++++++++++-------------------------
1 files changed, 28 insertions(+), 25 deletions(-)
diff --git a/ffmpeg.c b/ffmpeg.c
index b284087..f9c52c9 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -298,6 +298,7 @@ typedef struct AVOutputStream {
#endif
int sws_flags;
+ AVDictionary *opts;
} AVOutputStream;
static AVOutputStream **output_streams_for_file[MAX_FILES] = { NULL };
@@ -322,6 +323,8 @@ typedef struct AVInputStream {
AVFrame *filter_frame;
int has_filter_frame;
#endif
+
+ AVDictionary *opts;
} AVInputStream;
typedef struct AVInputFile {
@@ -469,6 +472,8 @@ static int ffmpeg_exit(int ret)
av_close_input_file(input_files[i].ctx);
av_free(input_files_ts_scale[i]);
}
+ for (i = 0; i < nb_input_streams; i++)
+ av_dict_free(&input_streams[i].opts);
av_free(intra_matrix);
av_free(inter_matrix);
@@ -2328,12 +2333,13 @@ static int transcode(AVFormatContext **output_files,
memcpy(ost->st->codec->subtitle_header, dec->subtitle_header,
dec->subtitle_header_size);
ost->st->codec->subtitle_header_size =
dec->subtitle_header_size;
}
- if (avcodec_open(ost->st->codec, codec) < 0) {
+ if (avcodec_open2(ost->st->codec, codec, &ost->opts) < 0) {
snprintf(error, sizeof(error), "Error while opening encoder
for output stream #%d.%d - maybe incorrect parameters such as bit_rate, rate,
width or height",
ost->file_index, ost->index);
ret = AVERROR(EINVAL);
goto dump_format;
}
+ assert_avoptions(ost->opts);
extra_size += ost->st->codec->extradata_size;
}
}
@@ -2362,12 +2368,13 @@ static int transcode(AVFormatContext **output_files,
}
}
- if (avcodec_open(ist->st->codec, codec) < 0) {
+ if (avcodec_open2(ist->st->codec, codec, &ist->opts) < 0) {
snprintf(error, sizeof(error), "Error while opening decoder
for input stream #%d.%d",
ist->file_index, ist->st->index);
ret = AVERROR(EINVAL);
goto dump_format;
}
+ assert_avoptions(ost->opts);
//if (ist->st->codec->codec_type == AVMEDIA_TYPE_VIDEO)
// ist->st->codec->flags |= CODEC_FLAG_REPEAT_FIELD;
}
@@ -2731,6 +2738,7 @@ static int transcode(AVFormatContext **output_files,
audio_resample_close(ost->resample);
if (ost->reformat_ctx)
av_audio_convert_free(ost->reformat_ctx);
+ av_dict_free(&ost->opts);
av_free(ost);
}
}
@@ -3161,6 +3169,8 @@ static int opt_input_file(const char *opt, const char
*filename)
int err, i, ret, rfps, rfps_base;
int64_t timestamp;
uint8_t buf[128];
+ AVDictionary **opts;
+ int orig_nb_streams; // number of streams before
avformat_find_stream_info
if (last_asked_format) {
if (!(file_iformat = av_find_input_format(last_asked_format))) {
@@ -3246,26 +3256,13 @@ static int opt_input_file(const char *opt, const char
*filename)
ic->loop_input = loop_input;
- /* Set AVCodecContext options so they will be seen by
av_find_stream_info() */
- for (i = 0; i < ic->nb_streams; i++) {
- AVCodecContext *dec = ic->streams[i]->codec;
- 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,
- NULL);
- break;
- case AVMEDIA_TYPE_VIDEO:
- set_context_opts(dec, avcodec_opts[AVMEDIA_TYPE_VIDEO],
- AV_OPT_FLAG_VIDEO_PARAM |
AV_OPT_FLAG_DECODING_PARAM,
- NULL);
- break;
- }
- }
+ /* Set AVCodecContext options for avformat_find_stream_info */
+ opts = setup_find_stream_info_opts(ic);
+ orig_nb_streams = ic->nb_streams;
/* If not enough info to get the stream parameters, we decode the
first frames to get it. (used in mpeg case for example) */
- ret = av_find_stream_info(ic);
+ ret = avformat_find_stream_info(ic, opts);
if (ret < 0 && verbose >= 0) {
fprintf(stderr, "%s: could not find codec parameters\n", filename);
av_close_input_file(ic);
@@ -3306,7 +3303,7 @@ static int opt_input_file(const char *opt, const char
*filename)
switch (dec->codec_type) {
case AVMEDIA_TYPE_AUDIO:
input_codecs[nb_input_codecs-1] =
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_input_codecs-1]);
+ av_dict_copy(&ist->opts, audio_opts, 0);
channel_layout = dec->channel_layout;
audio_sample_fmt = dec->sample_fmt;
if(audio_disable)
@@ -3314,7 +3311,7 @@ static int opt_input_file(const char *opt, const char
*filename)
break;
case AVMEDIA_TYPE_VIDEO:
input_codecs[nb_input_codecs-1] =
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_input_codecs-1]);
+ av_dict_copy(&ist->opts, video_opts, 0);
rfps = ic->streams[i]->r_frame_rate.num;
rfps_base = ic->streams[i]->r_frame_rate.den;
if (dec->lowres) {
@@ -3343,6 +3340,7 @@ static int opt_input_file(const char *opt, const char
*filename)
break;
case AVMEDIA_TYPE_SUBTITLE:
input_codecs[nb_input_codecs-1] =
avcodec_find_decoder_by_name(subtitle_codec_name);
+ av_dict_copy(&ist->opts, sub_opts, 0);
if(subtitle_disable)
st->discard = AVDISCARD_ALL;
break;
@@ -3370,6 +3368,9 @@ static int opt_input_file(const char *opt, const char
*filename)
audio_sample_rate = 0;
audio_channels = 0;
+ for (i = 0; i < orig_nb_streams; i++)
+ av_dict_free(&opts[i]);
+ av_freep(&opts);
av_freep(&video_codec_name);
av_freep(&audio_codec_name);
av_freep(&subtitle_codec_name);
@@ -3436,6 +3437,8 @@ static void new_video_stream(AVFormatContext *oc, int
file_idx)
}
ost = new_output_stream(oc, file_idx);
+ av_dict_copy(&ost->opts, video_opts, 0);
+
if(!video_stream_copy){
if (video_codec_name) {
codec_id = find_codec_or_die(video_codec_name, AVMEDIA_TYPE_VIDEO,
1,
@@ -3471,9 +3474,9 @@ static void new_video_stream(AVFormatContext *oc, int
file_idx)
avcodec_opts[AVMEDIA_TYPE_VIDEO]->flags|= CODEC_FLAG_GLOBAL_HEADER;
}
+ video_enc->codec_type = AVMEDIA_TYPE_VIDEO;
if (video_stream_copy) {
st->stream_copy = 1;
- video_enc->codec_type = AVMEDIA_TYPE_VIDEO;
video_enc->sample_aspect_ratio =
st->sample_aspect_ratio =
av_d2q(frame_aspect_ratio*frame_height/frame_width, 255);
} else {
@@ -3483,7 +3486,6 @@ static void new_video_stream(AVFormatContext *oc, int
file_idx)
if (frame_rate.num)
ost->frame_rate = frame_rate;
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, codec);
video_enc->width = frame_width;
video_enc->height = frame_height;
@@ -3576,6 +3578,8 @@ static void new_audio_stream(AVFormatContext *oc, int
file_idx)
}
ost = new_output_stream(oc, file_idx);
+ av_dict_copy(&ost->opts, audio_opts, 0);
+
if(!audio_stream_copy){
if (audio_codec_name) {
codec_id = find_codec_or_die(audio_codec_name, AVMEDIA_TYPE_AUDIO,
1,
@@ -3609,7 +3613,6 @@ static void new_audio_stream(AVFormatContext *oc, int
file_idx)
st->stream_copy = 1;
} else {
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;
@@ -3685,6 +3688,7 @@ static void new_subtitle_stream(AVFormatContext *oc, int
file_idx)
ffmpeg_exit(1);
}
ost = new_output_stream(oc, file_idx);
+ av_dict_copy(&ost->opts, sub_opts, 0);
subtitle_enc = st->codec;
if(!subtitle_stream_copy){
if (subtitle_codec_name) {
@@ -3715,7 +3719,6 @@ static void new_subtitle_stream(AVFormatContext *oc, int
file_idx)
st->stream_copy = 1;
} else {
subtitle_enc->codec_id = codec_id;
- set_context_opts(avcodec_opts[AVMEDIA_TYPE_SUBTITLE], subtitle_enc,
AV_OPT_FLAG_SUBTITLE_PARAM | AV_OPT_FLAG_ENCODING_PARAM, codec);
}
if (subtitle_language) {
--
1.7.5.3
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel