---
ffmpeg.c | 99 +++++++++++++++++++++------------------------
tests/codec-regression.sh | 2 +-
tests/fate2.mak | 4 +-
tests/regression-funcs.sh | 2 +-
4 files changed, 50 insertions(+), 57 deletions(-)
diff --git a/ffmpeg.c b/ffmpeg.c
index 874d1cb..da15d04 100644
--- a/ffmpeg.c
+++ b/ffmpeg.c
@@ -113,6 +113,7 @@ static int nb_input_codecs = 0;
static int nb_input_files_ts_scale[MAX_FILES] = {0};
static AVFormatContext *output_files[MAX_FILES];
+static AVMetadata *output_opts[MAX_FILES];
static AVCodec **output_codecs = NULL;
static int nb_output_files = 0;
static int nb_output_codecs = 0;
@@ -299,6 +300,7 @@ typedef struct AVOutputStream {
#endif
int sws_flags;
+ AVMetadata *opts;
} AVOutputStream;
static AVOutputStream **output_streams_for_file[MAX_FILES] = { NULL };
@@ -323,6 +325,8 @@ typedef struct AVInputStream {
AVFrame *filter_frame;
int has_filter_frame;
#endif
+
+ AVMetadata *opts;
} AVInputStream;
typedef struct AVInputFile {
@@ -455,7 +459,7 @@ static int decode_interrupt_cb(void)
static int ffmpeg_exit(int ret)
{
- int i;
+ int i, j;
/* close files */
for(i=0;i<nb_output_files;i++) {
@@ -464,11 +468,14 @@ static int ffmpeg_exit(int ret)
avio_close(s->pb);
avformat_free_context(s);
av_free(output_streams_for_file[i]);
+ avmeta_free(&output_opts[i]);
}
for(i=0;i<nb_input_files;i++) {
av_close_input_file(input_files[i].ctx);
av_free(input_files_ts_scale[i]);
}
+ for (i = 0; i < nb_input_streams; i++)
+ avmeta_free(&input_streams[i].opts);
av_free(intra_matrix);
av_free(inter_matrix);
@@ -514,6 +521,15 @@ static int ffmpeg_exit(int ret)
return ret;
}
+static void assert_avoptions(AVMetadata *m)
+{
+ AVMetadataTag *t;
+ if ((t = avmeta_get(m, "", NULL, AV_METADATA_IGNORE_SUFFIX))) {
+ av_log(NULL, AV_LOG_ERROR, "Option %s not found.\n", t->key);
+ ffmpeg_exit(1);
+ }
+}
+
/* similar to ff_dynarray_add() and av_fast_realloc() */
static void *grow_array(void *array, int elem_size, int *size, int new_size)
{
@@ -2294,12 +2310,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;
}
}
@@ -2328,12 +2345,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;
}
@@ -2442,11 +2460,12 @@ static int transcode(AVFormatContext **output_files,
/* open files and write file headers */
for(i=0;i<nb_output_files;i++) {
os = output_files[i];
- if (av_write_header(os) < 0) {
+ if (avformat_open_output(os, &output_opts[i]) < 0) {
snprintf(error, sizeof(error), "Could not write header for output
file #%d (incorrect codec parameters ?)", i);
ret = AVERROR(EINVAL);
goto dump_format;
}
+ assert_avoptions(output_opts[i]);
if (strcmp(output_files[i]->oformat->name, "rtp")) {
want_sdp = 0;
}
@@ -3111,6 +3130,8 @@ static void opt_input_file(const char *filename)
AVInputFormat *file_iformat = NULL;
int err, i, ret, rfps, rfps_base;
int64_t timestamp;
+ AVMetadata **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))) {
@@ -3132,21 +3153,11 @@ static void opt_input_file(const char *filename)
print_error(filename, AVERROR(ENOMEM));
ffmpeg_exit(1);
}
+ ic->iformat = file_iformat;
memset(ap, 0, sizeof(*ap));
- ap->prealloced_context = 1;
- ap->sample_rate = audio_sample_rate;
- ap->channels = audio_channels;
ap->time_base.den = frame_rate.num;
ap->time_base.num = frame_rate.den;
- ap->width = frame_width;
- ap->height = frame_height;
- ap->pix_fmt = frame_pix_fmt;
- // ap->sample_fmt = audio_sample_fmt; //FIXME:not implemented in libavformat
- ap->channel = video_channel;
- ap->standard = video_standard;
-
- 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,
@@ -3160,11 +3171,13 @@ static void opt_input_file(const char *filename)
ic->flags |= AVFMT_FLAG_NONBLOCK;
/* open the input file with generic libav function */
- err = av_open_input_file(&ic, filename, file_iformat, 0, ap);
+ err = avformat_open_input(&ic, filename, &format_opts);
if (err < 0) {
print_error(filename, err);
ffmpeg_exit(1);
}
+ assert_avoptions(format_opts);
+
if(opt_programid) {
int i, j;
int found=0;
@@ -3191,26 +3204,13 @@ static void opt_input_file(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);
@@ -3251,7 +3251,7 @@ static void opt_input_file(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]);
+ avmeta_copy(&ist->opts, audio_opts, 0);
channel_layout = dec->channel_layout;
audio_channels = dec->channels;
audio_sample_rate = dec->sample_rate;
@@ -3266,7 +3266,7 @@ static void opt_input_file(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]);
+ avmeta_copy(&ist->opts, video_opts, 0);
frame_height = dec->height;
frame_width = dec->width;
frame_pix_fmt = dec->pix_fmt;
@@ -3303,6 +3303,7 @@ static void opt_input_file(const char *filename)
break;
case AVMEDIA_TYPE_SUBTITLE:
input_codecs[nb_input_codecs-1] =
avcodec_find_decoder_by_name(subtitle_codec_name);
+ avmeta_copy(&ist->opts, sub_opts, 0);
if(subtitle_disable)
st->discard = AVDISCARD_ALL;
break;
@@ -3325,6 +3326,9 @@ static void opt_input_file(const char *filename)
video_channel = 0;
+ for (i = 0; i < orig_nb_streams; i++)
+ avmeta_free(&opts[i]);
+ av_freep(&opts);
av_freep(&video_codec_name);
av_freep(&audio_codec_name);
av_freep(&subtitle_codec_name);
@@ -3390,6 +3394,8 @@ static void new_video_stream(AVFormatContext *oc, int
file_idx)
}
ost = new_output_stream(oc, file_idx);
+ avmeta_copy(&ost->opts, video_opts, 0);
+
output_codecs = grow_array(output_codecs, sizeof(*output_codecs),
&nb_output_codecs, nb_output_codecs + 1);
if(!video_stream_copy){
if (video_codec_name) {
@@ -3410,7 +3416,6 @@ static void new_video_stream(AVFormatContext *oc, int
file_idx)
#endif
}
- avcodec_get_context_defaults3(st->codec, codec);
ost->bitstream_filters = video_bitstream_filters;
video_bitstream_filters= NULL;
@@ -3426,9 +3431,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 {
@@ -3437,7 +3442,6 @@ static void new_video_stream(AVFormatContext *oc, int
file_idx)
AVRational fps= frame_rate.num ? frame_rate : (AVRational){25,1};
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);
if (codec && codec->supported_framerates && !force_fps)
fps = codec->supported_framerates[av_find_nearest_q_idx(fps,
codec->supported_framerates)];
@@ -3537,6 +3541,8 @@ static void new_audio_stream(AVFormatContext *oc, int
file_idx)
}
ost = new_output_stream(oc, file_idx);
+ avmeta_copy(&ost->opts, audio_opts, 0);
+
output_codecs = grow_array(output_codecs, sizeof(*output_codecs),
&nb_output_codecs, nb_output_codecs + 1);
if(!audio_stream_copy){
if (audio_codec_name) {
@@ -3550,8 +3556,6 @@ static void new_audio_stream(AVFormatContext *oc, int
file_idx)
}
}
- avcodec_get_context_defaults3(st->codec, codec);
-
ost->bitstream_filters = audio_bitstream_filters;
audio_bitstream_filters= NULL;
@@ -3573,7 +3577,6 @@ static void new_audio_stream(AVFormatContext *oc, int
file_idx)
audio_enc->sample_rate = audio_sample_rate;
} 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;
@@ -3653,6 +3656,7 @@ static void new_subtitle_stream(AVFormatContext *oc, int
file_idx)
ffmpeg_exit(1);
}
ost = new_output_stream(oc, file_idx);
+ avmeta_copy(&ost->opts, sub_opts, 0);
subtitle_enc = st->codec;
output_codecs = grow_array(output_codecs, sizeof(*output_codecs),
&nb_output_codecs, nb_output_codecs + 1);
if(!subtitle_stream_copy){
@@ -3665,7 +3669,6 @@ static void new_subtitle_stream(AVFormatContext *oc, int
file_idx)
codec = avcodec_find_encoder(codec_id);
}
}
- avcodec_get_context_defaults3(st->codec, codec);
ost->bitstream_filters = subtitle_bitstream_filters;
subtitle_bitstream_filters= NULL;
@@ -3683,7 +3686,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) {
@@ -3741,7 +3743,6 @@ static void opt_output_file(const char *filename)
AVFormatContext *oc;
int err, use_video, use_audio, use_subtitle, use_data;
int input_has_video, input_has_audio, input_has_subtitle, input_has_data;
- AVFormatParameters params, *ap = ¶ms;
AVOutputFormat *file_oformat;
if (!strcmp(filename, "-"))
@@ -3822,6 +3823,7 @@ static void opt_output_file(const char *filename)
avmeta_free(&metadata);
}
+ avmeta_copy(&output_opts[nb_output_files], format_opts, 0);
output_files[nb_output_files++] = oc;
/* check filename in case of an image number is expected */
@@ -3861,20 +3863,11 @@ static void opt_output_file(const char *filename)
}
}
- memset(ap, 0, sizeof(*ap));
- if (av_set_parameters(oc, ap) < 0) {
- fprintf(stderr, "%s: Invalid encoding parameters\n",
- oc->filename);
- ffmpeg_exit(1);
- }
-
oc->preload= (int)(mux_preload*AV_TIME_BASE);
oc->max_delay= (int)(mux_max_delay*AV_TIME_BASE);
oc->loop_output = loop_output;
oc->flags |= AVFMT_FLAG_NONBLOCK;
- set_context_opts(oc, avformat_opts, AV_OPT_FLAG_ENCODING_PARAM, NULL);
-
av_freep(&forced_key_frames);
uninit_opts();
init_opts();
diff --git a/tests/codec-regression.sh b/tests/codec-regression.sh
index 335e1f7..d15eb67 100755
--- a/tests/codec-regression.sh
+++ b/tests/codec-regression.sh
@@ -18,7 +18,7 @@ if [ -n "$do_vref" ]; then
do_ffmpeg $raw_ref -f image2 -vcodec pgmyuv -i $raw_src -an -f rawvideo
fi
if [ -n "$do_aref" ]; then
-do_ffmpeg $pcm_ref -ab 128k -ac 2 -ar 44100 -f s16le -i $pcm_src -f wav
+do_ffmpeg $pcm_ref -ab 128k -channels 2 -sample_rate 44100 -f s16le -i
$pcm_src -f wav
fi
if [ -n "$do_mpeg" ] ; then
diff --git a/tests/fate2.mak b/tests/fate2.mak
index 6a9448f..2ee1fdf 100644
--- a/tests/fate2.mak
+++ b/tests/fate2.mak
@@ -131,7 +131,7 @@ FATE_TESTS += fate-gsm-ms
fate-gsm-ms: CMD = framecrc -i $(SAMPLES)/gsm/ciao.wav
FATE_TESTS += fate-g722dec-1
-fate-g722dec-1: CMD = framecrc -ar 16000 -i
$(SAMPLES)/g722/conf-adminmenu-162.g722
+fate-g722dec-1: CMD = framecrc -channels 1 -sample_rate 16000 -i
$(SAMPLES)/g722/conf-adminmenu-162.g722
FATE_TESTS += fate-msmpeg4v1
fate-msmpeg4v1: CMD = framecrc -flags +bitexact -dct fastint -idct simple -i
$(SAMPLES)/msmpeg4v1/mpg4.avi -an
@@ -165,7 +165,7 @@ fate-wmapro-2ch: CMP = oneoff
fate-wmapro-2ch: REF = $(SAMPLES)/wmapro/Beethovens_9th-1_small.pcm
FATE_TESTS += fate-ansi
-fate-ansi: CMD = framecrc -i $(SAMPLES)/ansi/TRE-IOM5.ANS -pix_fmt rgb24
+fate-ansi: CMD = framecrc -chars_per_frame 44100 -i
$(SAMPLES)/ansi/TRE-IOM5.ANS -pix_fmt rgb24
FATE_TESTS += fate-wmv8-drm
# discard last packet to avoid fails due to overread of VC-1 decoder
diff --git a/tests/regression-funcs.sh b/tests/regression-funcs.sh
index 933aa64..431272b 100755
--- a/tests/regression-funcs.sh
+++ b/tests/regression-funcs.sh
@@ -114,7 +114,7 @@ do_video_encoding()
do_audio_encoding()
{
file=${outfile}$1
- do_ffmpeg $file $DEC_OPTS -ac 2 -f s16le -i $pcm_src -ab 128k $ENC_OPTS $2
+ do_ffmpeg $file $DEC_OPTS -channels 2 -sample_rate 44100 -f s16le -i
$pcm_src -ab 128k $ENC_OPTS $2
}
do_audio_decoding()
--
1.7.5.1
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel