Commit 8035f429 authored by Anton Khirnov's avatar Anton Khirnov

ffmpeg: use new avformat_open_* API.

parent 50f2dfad
...@@ -113,6 +113,7 @@ static int nb_input_codecs = 0; ...@@ -113,6 +113,7 @@ static int nb_input_codecs = 0;
static int nb_input_files_ts_scale[MAX_FILES] = {0}; static int nb_input_files_ts_scale[MAX_FILES] = {0};
static AVFormatContext *output_files[MAX_FILES]; static AVFormatContext *output_files[MAX_FILES];
static AVDictionary *output_opts[MAX_FILES];
static int nb_output_files = 0; static int nb_output_files = 0;
static AVStreamMap *stream_maps = NULL; static AVStreamMap *stream_maps = NULL;
...@@ -465,6 +466,7 @@ static int ffmpeg_exit(int ret) ...@@ -465,6 +466,7 @@ static int ffmpeg_exit(int ret)
avio_close(s->pb); avio_close(s->pb);
avformat_free_context(s); avformat_free_context(s);
av_free(output_streams_for_file[i]); av_free(output_streams_for_file[i]);
av_dict_free(&output_opts[i]);
} }
for(i=0;i<nb_input_files;i++) { for(i=0;i<nb_input_files;i++) {
av_close_input_file(input_files[i].ctx); av_close_input_file(input_files[i].ctx);
...@@ -514,6 +516,15 @@ static int ffmpeg_exit(int ret) ...@@ -514,6 +516,15 @@ static int ffmpeg_exit(int ret)
return ret; return ret;
} }
static void assert_avoptions(AVDictionary *m)
{
AVDictionaryEntry *t;
if ((t = av_dict_get(m, "", NULL, AV_DICT_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() */ /* similar to ff_dynarray_add() and av_fast_realloc() */
static void *grow_array(void *array, int elem_size, int *size, int new_size) static void *grow_array(void *array, int elem_size, int *size, int new_size)
{ {
...@@ -666,10 +677,10 @@ static AVOutputStream *new_output_stream(AVFormatContext *oc, int file_idx) ...@@ -666,10 +677,10 @@ static AVOutputStream *new_output_stream(AVFormatContext *oc, int file_idx)
static int read_ffserver_streams(AVFormatContext *s, const char *filename) static int read_ffserver_streams(AVFormatContext *s, const char *filename)
{ {
int i, err; int i, err;
AVFormatContext *ic; AVFormatContext *ic = NULL;
int nopts = 0; int nopts = 0;
err = av_open_input_file(&ic, filename, NULL, FFM_PACKET_SIZE, NULL); err = avformat_open_input(&ic, filename, NULL, NULL);
if (err < 0) if (err < 0)
return err; return err;
/* copy stream format */ /* copy stream format */
...@@ -2470,11 +2481,12 @@ static int transcode(AVFormatContext **output_files, ...@@ -2470,11 +2481,12 @@ static int transcode(AVFormatContext **output_files,
/* open files and write file headers */ /* open files and write file headers */
for(i=0;i<nb_output_files;i++) { for(i=0;i<nb_output_files;i++) {
os = output_files[i]; os = output_files[i];
if (av_write_header(os) < 0) { if (avformat_write_header(os, &output_opts[i]) < 0) {
snprintf(error, sizeof(error), "Could not write header for output file #%d (incorrect codec parameters ?)", i); snprintf(error, sizeof(error), "Could not write header for output file #%d (incorrect codec parameters ?)", i);
ret = AVERROR(EINVAL); ret = AVERROR(EINVAL);
goto dump_format; goto dump_format;
} }
assert_avoptions(output_opts[i]);
if (strcmp(output_files[i]->oformat->name, "rtp")) { if (strcmp(output_files[i]->oformat->name, "rtp")) {
want_sdp = 0; want_sdp = 0;
} }
...@@ -3148,10 +3160,10 @@ static enum CodecID find_codec_or_die(const char *name, int type, int encoder, i ...@@ -3148,10 +3160,10 @@ static enum CodecID find_codec_or_die(const char *name, int type, int encoder, i
static int opt_input_file(const char *opt, const char *filename) static int opt_input_file(const char *opt, const char *filename)
{ {
AVFormatContext *ic; AVFormatContext *ic;
AVFormatParameters params, *ap = &params;
AVInputFormat *file_iformat = NULL; AVInputFormat *file_iformat = NULL;
int err, i, ret, rfps, rfps_base; int err, i, ret, rfps, rfps_base;
int64_t timestamp; int64_t timestamp;
uint8_t buf[128];
if (last_asked_format) { if (last_asked_format) {
if (!(file_iformat = av_find_input_format(last_asked_format))) { if (!(file_iformat = av_find_input_format(last_asked_format))) {
...@@ -3173,21 +3185,24 @@ static int opt_input_file(const char *opt, const char *filename) ...@@ -3173,21 +3185,24 @@ static int opt_input_file(const char *opt, const char *filename)
print_error(filename, AVERROR(ENOMEM)); print_error(filename, AVERROR(ENOMEM));
ffmpeg_exit(1); ffmpeg_exit(1);
} }
if (audio_sample_rate) {
memset(ap, 0, sizeof(*ap)); snprintf(buf, sizeof(buf), "%d", audio_sample_rate);
ap->prealloced_context = 1; av_dict_set(&format_opts, "sample_rate", buf, 0);
ap->sample_rate = audio_sample_rate; }
ap->channels = audio_channels; if (audio_channels) {
ap->time_base.den = frame_rate.num; snprintf(buf, sizeof(buf), "%d", audio_channels);
ap->time_base.num = frame_rate.den; av_dict_set(&format_opts, "channels", buf, 0);
ap->width = frame_width; }
ap->height = frame_height; if (frame_rate.num) {
ap->pix_fmt = frame_pix_fmt; snprintf(buf, sizeof(buf), "%d/%d", frame_rate.num, frame_rate.den);
// ap->sample_fmt = audio_sample_fmt; //FIXME:not implemented in libavformat av_dict_set(&format_opts, "framerate", buf, 0);
ap->channel = video_channel; }
ap->standard = video_standard; if (frame_width && frame_height) {
snprintf(buf, sizeof(buf), "%dx%d", frame_width, frame_height);
set_context_opts(ic, avformat_opts, AV_OPT_FLAG_DECODING_PARAM, NULL); av_dict_set(&format_opts, "video_size", buf, 0);
}
if (frame_pix_fmt != PIX_FMT_NONE)
av_dict_set(&format_opts, "pixel_format", av_get_pix_fmt_name(frame_pix_fmt), 0);
ic->video_codec_id = ic->video_codec_id =
find_codec_or_die(video_codec_name , AVMEDIA_TYPE_VIDEO , 0, find_codec_or_die(video_codec_name , AVMEDIA_TYPE_VIDEO , 0,
...@@ -3201,11 +3216,13 @@ static int opt_input_file(const char *opt, const char *filename) ...@@ -3201,11 +3216,13 @@ static int opt_input_file(const char *opt, const char *filename)
ic->flags |= AVFMT_FLAG_NONBLOCK; ic->flags |= AVFMT_FLAG_NONBLOCK;
/* open the input file with generic libav function */ /* 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, file_iformat, &format_opts);
if (err < 0) { if (err < 0) {
print_error(filename, err); print_error(filename, err);
ffmpeg_exit(1); ffmpeg_exit(1);
} }
assert_avoptions(format_opts);
if(opt_programid) { if(opt_programid) {
int i, j; int i, j;
int found=0; int found=0;
...@@ -3760,7 +3777,6 @@ static void opt_output_file(const char *filename) ...@@ -3760,7 +3777,6 @@ static void opt_output_file(const char *filename)
AVFormatContext *oc; AVFormatContext *oc;
int err, use_video, use_audio, use_subtitle, use_data; int err, use_video, use_audio, use_subtitle, use_data;
int input_has_video, input_has_audio, input_has_subtitle, input_has_data; int input_has_video, input_has_audio, input_has_subtitle, input_has_data;
AVFormatParameters params, *ap = &params;
AVOutputFormat *file_oformat; AVOutputFormat *file_oformat;
if (!strcmp(filename, "-")) if (!strcmp(filename, "-"))
...@@ -3841,6 +3857,7 @@ static void opt_output_file(const char *filename) ...@@ -3841,6 +3857,7 @@ static void opt_output_file(const char *filename)
av_dict_free(&metadata); av_dict_free(&metadata);
} }
av_dict_copy(&output_opts[nb_output_files], format_opts, 0);
output_files[nb_output_files++] = oc; output_files[nb_output_files++] = oc;
/* check filename in case of an image number is expected */ /* check filename in case of an image number is expected */
...@@ -3880,20 +3897,11 @@ static void opt_output_file(const char *filename) ...@@ -3880,20 +3897,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->preload= (int)(mux_preload*AV_TIME_BASE);
oc->max_delay= (int)(mux_max_delay*AV_TIME_BASE); oc->max_delay= (int)(mux_max_delay*AV_TIME_BASE);
oc->loop_output = loop_output; oc->loop_output = loop_output;
oc->flags |= AVFMT_FLAG_NONBLOCK; oc->flags |= AVFMT_FLAG_NONBLOCK;
set_context_opts(oc, avformat_opts, AV_OPT_FLAG_ENCODING_PARAM, NULL);
frame_rate = (AVRational){0, 0}; frame_rate = (AVRational){0, 0};
frame_width = 0; frame_width = 0;
frame_height = 0; frame_height = 0;
...@@ -3988,6 +3996,7 @@ static void show_help(void) ...@@ -3988,6 +3996,7 @@ static void show_help(void)
{ {
AVCodec *c; AVCodec *c;
AVOutputFormat *oformat = NULL; AVOutputFormat *oformat = NULL;
AVInputFormat *iformat = NULL;
av_log_set_callback(log_callback_help); av_log_set_callback(log_callback_help);
show_usage(); show_usage();
...@@ -4038,6 +4047,14 @@ static void show_help(void) ...@@ -4038,6 +4047,14 @@ static void show_help(void)
} }
} }
/* individual demuxer options */
while ((iformat = av_iformat_next(iformat))) {
if (iformat->priv_class) {
av_opt_show2(&iformat->priv_class, NULL, AV_OPT_FLAG_DECODING_PARAM, 0);
printf("\n");
}
}
av_opt_show2(sws_opts, NULL, AV_OPT_FLAG_ENCODING_PARAM|AV_OPT_FLAG_DECODING_PARAM, 0); av_opt_show2(sws_opts, NULL, AV_OPT_FLAG_ENCODING_PARAM|AV_OPT_FLAG_DECODING_PARAM, 0);
} }
......
...@@ -165,7 +165,7 @@ fate-wmapro-2ch: CMP = oneoff ...@@ -165,7 +165,7 @@ fate-wmapro-2ch: CMP = oneoff
fate-wmapro-2ch: REF = $(SAMPLES)/wmapro/Beethovens_9th-1_small.pcm fate-wmapro-2ch: REF = $(SAMPLES)/wmapro/Beethovens_9th-1_small.pcm
FATE_TESTS += fate-ansi FATE_TESTS += fate-ansi
fate-ansi: CMD = framecrc -ar 44100 -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 FATE_TESTS += fate-wmv8-drm
# discard last packet to avoid fails due to overread of VC-1 decoder # discard last packet to avoid fails due to overread of VC-1 decoder
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment