+ 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;
+