+ if ((ret = av_dict_copy(&oc->metadata, s->metadata, 0)) < 0)
+ return ret;
+
+ if (!(st = avformat_new_stream(oc, NULL)))
+ return AVERROR(ENOMEM);
+
+ if ((ret = avcodec_parameters_copy(st->codecpar, ost->codecpar)) < 0 ||
+ (ret = av_dict_copy(&st->metadata, ost->metadata, 0)) < 0)
+ return ret;
+
+ st->sample_aspect_ratio = ost->sample_aspect_ratio;
+ st->disposition = ost->disposition;
+ avpriv_set_pts_info(st, ost->pts_wrap_bits, ost->time_base.num,
+ ost->time_base.den);
+
+ if (wc->http_method)
+ if ((ret = av_dict_set(&dict, "method", wc->http_method, 0)) < 0)
+ return ret;
+ ret = s->io_open(s, &oc->pb, oc->url, AVIO_FLAG_WRITE, &dict);
+ av_dict_free(&dict);
+ if (ret < 0)
+ return ret;
+ oc->pb->seekable = 0;
+
+ if ((ret = av_dict_set_int(&dict, "dash", 1, 0)) < 0 ||
+ (ret = av_dict_set_int(&dict, "cluster_time_limit",
+ wc->chunk_duration, 0)) < 0 ||
+ (ret = av_dict_set_int(&dict, "live", 1, 0)) < 0)
+ goto fail;
+
+ ret = avformat_init_output(oc, &dict);
+fail:
+ av_dict_free(&dict);
+ if (ret < 0)
+ return ret;
+
+ // Copy the timing info back to the original stream
+ // so that the timestamps of the packets are directly usable
+ avpriv_set_pts_info(ost, st->pts_wrap_bits, st->time_base.num,
+ st->time_base.den);
+
+ // This ensures that the timestamps will already be properly shifted
+ // when the packets arrive here, so we don't need to shift again.
+ s->avoid_negative_ts = oc->avoid_negative_ts;
+ s->internal->avoid_negative_ts_use_pts =
+ oc->internal->avoid_negative_ts_use_pts;
+ oc->avoid_negative_ts = 0;