It supports more convenient setting of AVOptions.
---
libavformat/avformat.h | 12 ++++++++++++
libavformat/utils.c | 22 ++++++++++++++++++++++
2 files changed, 34 insertions(+), 0 deletions(-)
diff --git a/libavformat/avformat.h b/libavformat/avformat.h
index 5d49acf..b09a321 100644
--- a/libavformat/avformat.h
+++ b/libavformat/avformat.h
@@ -1328,6 +1328,18 @@ void av_url_split(char *proto, int proto_size,
const char *url);
/**
+ * Allocate the stream private data and write the stream header to
+ * an output media file.
+ *
+ * @param s media file handle
+ * @param options Metadata filled with AVFormatContext and demuxer-private
options.
+ * On return this object will be filled with options that were
not found.
+ * @see av_find_opt
+ * @return 0 on success, negative AVERROR on failure.
+ */
+int avformat_open_output(AVFormatContext *s, AVMetadata **options);
+
+/**
* Allocate the stream private data and write the stream header to an
* output media file.
* @note: this sets stream time-bases, if possible to stream->codec->time_base
diff --git a/libavformat/utils.c b/libavformat/utils.c
index 9ea7a5e..ab3d0c8 100644
--- a/libavformat/utils.c
+++ b/libavformat/utils.c
@@ -2846,8 +2846,19 @@ static int validate_codec_tag(AVFormatContext *s,
AVStream *st)
int av_write_header(AVFormatContext *s)
{
+ return avformat_open_output(s, NULL);
+}
+
+int avformat_open_output(AVFormatContext *s, AVMetadata **options)
+{
int ret, i;
AVStream *st;
+ AVMetadata *tmp = NULL;
+
+ if (options)
+ avmeta_copy(&tmp, *options, 0);
+ if ((ret = avopt_process(s, &tmp)) < 0)
+ return ret;
// some sanity checks
if (s->nb_streams == 0 && !(s->oformat->flags & AVFMT_NOSTREAMS)) {
@@ -2911,6 +2922,12 @@ int av_write_header(AVFormatContext *s)
s->priv_data = av_mallocz(s->oformat->priv_data_size);
if (!s->priv_data)
return AVERROR(ENOMEM);
+ if (s->oformat->priv_class) {
+ *(const AVClass**)s->priv_data= s->oformat->priv_class;
+ av_opt_set_defaults(s->priv_data);
+ if ((ret = avopt_process(s->priv_data, &tmp)) < 0)
+ return ret;
+ }
}
/* set muxer identification string */
@@ -2945,6 +2962,11 @@ int av_write_header(AVFormatContext *s)
av_frac_init(&st->pts, 0, 0, den);
}
}
+
+ if (options) {
+ avmeta_free(options);
+ *options = tmp;
+ }
return 0;
}
--
1.7.5.1
_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel