diff options
author | Rodger Combs <rodger.combs@gmail.com> | 2016-06-24 22:02:50 -0500 |
---|---|---|
committer | Rodger Combs <rodger.combs@gmail.com> | 2016-10-24 03:53:21 -0500 |
commit | a246fef163387c0d79830a9bdf408443a9aba1c1 (patch) | |
tree | ba5a56853e481e34c2cf2dcceaae00cb0b2ae883 /libavformat/mux.c | |
parent | 8a24e03684cad4b8207a0317123ca2bd544d012e (diff) |
lavf/mux: add avformat_init_output
This allows a consumer to run the muxer's init function without actually
writing the header, which is useful in chained muxers that support
automatic bitstream filtering.
Diffstat (limited to 'libavformat/mux.c')
-rw-r--r-- | libavformat/mux.c | 68 |
1 files changed, 54 insertions, 14 deletions
diff --git a/libavformat/mux.c b/libavformat/mux.c index bbfc0fccb8..06d87dec7f 100644 --- a/libavformat/mux.c +++ b/libavformat/mux.c @@ -423,10 +423,13 @@ FF_ENABLE_DEPRECATION_WARNINGS *options = tmp; } - if (s->oformat->init && (ret = s->oformat->init(s)) < 0) { - if (s->oformat->deinit) - s->oformat->deinit(s); - goto fail; + if (s->oformat->init) { + if ((ret = s->oformat->init(s)) < 0) { + if (s->oformat->deinit) + s->oformat->deinit(s); + return ret; + } + return ret == 0; } return 0; @@ -493,31 +496,64 @@ static int write_header_internal(AVFormatContext *s) return 0; } -int avformat_write_header(AVFormatContext *s, AVDictionary **options) +int avformat_init_output(AVFormatContext *s, AVDictionary **options) { int ret = 0; if ((ret = init_muxer(s, options)) < 0) return ret; + s->internal->initialized = 1; + s->internal->streams_initialized = ret; + + if (s->oformat->init && ret) { + if ((ret = init_pts(s)) < 0) + return ret; + + if (s->avoid_negative_ts < 0) { + av_assert2(s->avoid_negative_ts == AVFMT_AVOID_NEG_TS_AUTO); + if (s->oformat->flags & (AVFMT_TS_NEGATIVE | AVFMT_NOTIMESTAMPS)) { + s->avoid_negative_ts = 0; + } else + s->avoid_negative_ts = AVFMT_AVOID_NEG_TS_MAKE_NON_NEGATIVE; + } + + return AVSTREAM_INIT_IN_INIT_OUTPUT; + } + + return AVSTREAM_INIT_IN_WRITE_HEADER; +} + +int avformat_write_header(AVFormatContext *s, AVDictionary **options) +{ + int ret = 0; + int already_initialized = s->internal->initialized; + int streams_already_initialized = s->internal->streams_initialized; + + if (!already_initialized) + if ((ret = avformat_init_output(s, options)) < 0) + return ret; + if (!(s->oformat->check_bitstream && s->flags & AVFMT_FLAG_AUTO_BSF)) { ret = write_header_internal(s); if (ret < 0) goto fail; } - if ((ret = init_pts(s)) < 0) - goto fail; + if (!s->internal->streams_initialized) { + if ((ret = init_pts(s)) < 0) + goto fail; - if (s->avoid_negative_ts < 0) { - av_assert2(s->avoid_negative_ts == AVFMT_AVOID_NEG_TS_AUTO); - if (s->oformat->flags & (AVFMT_TS_NEGATIVE | AVFMT_NOTIMESTAMPS)) { - s->avoid_negative_ts = 0; - } else - s->avoid_negative_ts = AVFMT_AVOID_NEG_TS_MAKE_NON_NEGATIVE; + if (s->avoid_negative_ts < 0) { + av_assert2(s->avoid_negative_ts == AVFMT_AVOID_NEG_TS_AUTO); + if (s->oformat->flags & (AVFMT_TS_NEGATIVE | AVFMT_NOTIMESTAMPS)) { + s->avoid_negative_ts = 0; + } else + s->avoid_negative_ts = AVFMT_AVOID_NEG_TS_MAKE_NON_NEGATIVE; + } } - return 0; + return streams_already_initialized; fail: if (s->oformat->deinit) @@ -1292,6 +1328,10 @@ fail: if (s->oformat->deinit) s->oformat->deinit(s); + s->internal->header_written = + s->internal->initialized = + s->internal->streams_initialized = 0; + if (s->pb) avio_flush(s->pb); if (ret == 0) |