[FFmpeg-devel] [PATCH 5/8] lavf/segment: fix writing separate header with auto BSF
Rodger Combs
rodger.combs at gmail.com
Wed Apr 13 11:28:35 CEST 2016
---
libavformat/segment.c | 55 ++++++++++++++++++++++++++++++++++++++-------------
1 file changed, 41 insertions(+), 14 deletions(-)
diff --git a/libavformat/segment.c b/libavformat/segment.c
index 1fffb7b..1578bdb 100644
--- a/libavformat/segment.c
+++ b/libavformat/segment.c
@@ -260,6 +260,7 @@ static int segment_start(AVFormatContext *s, int write_header)
if (write_header) {
AVDictionary *options = NULL;
av_dict_copy(&options, seg->format_options, 0);
+ av_dict_set(&options, "fflags", "-autobsf", 0);
err = avformat_write_header(oc, &options);
av_dict_free(&options);
if (err < 0)
@@ -754,7 +755,8 @@ static int seg_init(AVFormatContext *s)
}
av_dict_copy(&options, seg->format_options, 0);
- ret = avformat_write_header(oc, &options);
+ av_dict_set(&options, "fflags", "-autobsf", 0);
+ ret = avformat_init_output(oc, &options);
if (av_dict_count(options)) {
av_log(s, AV_LOG_ERROR,
"Some of the provided format options in '%s' are not recognized\n", seg->format_options_str);
@@ -769,14 +771,42 @@ static int seg_init(AVFormatContext *s)
seg->segment_frame_count = 0;
av_assert0(s->nb_streams == oc->nb_streams);
- for (i = 0; i < s->nb_streams; i++) {
- AVStream *inner_st = oc->streams[i];
- AVStream *outer_st = s->streams[i];
- avpriv_set_pts_info(outer_st, inner_st->pts_wrap_bits, inner_st->time_base.num, inner_st->time_base.den);
+ if (ret) {
+ for (i = 0; i < s->nb_streams; i++) {
+ AVStream *inner_st = oc->streams[i];
+ AVStream *outer_st = s->streams[i];
+ avpriv_set_pts_info(outer_st, inner_st->pts_wrap_bits, inner_st->time_base.num, inner_st->time_base.den);
+ }
+
+ if (oc->avoid_negative_ts > 0 && s->avoid_negative_ts < 0)
+ s->avoid_negative_ts = 1;
}
- if (oc->avoid_negative_ts > 0 && s->avoid_negative_ts < 0)
- s->avoid_negative_ts = 1;
+fail:
+ av_dict_free(&options);
+ return ret;
+}
+
+static int seg_write_header(AVFormatContext *s)
+{
+ SegmentContext *seg = s->priv_data;
+ AVFormatContext *oc = seg->avf;
+ int i;
+
+ int ret = avformat_write_header(oc, NULL);
+ if (ret < 0)
+ return ret;
+
+ if (!ret) {
+ for (i = 0; i < s->nb_streams; i++) {
+ AVStream *inner_st = oc->streams[i];
+ AVStream *outer_st = s->streams[i];
+ avpriv_set_pts_info(outer_st, inner_st->pts_wrap_bits, inner_st->time_base.num, inner_st->time_base.den);
+ }
+
+ if (oc->avoid_negative_ts > 0 && s->avoid_negative_ts < 0)
+ s->avoid_negative_ts = 1;
+ }
if (!seg->write_header_trailer || seg->header_filename) {
if (seg->header_filename) {
@@ -786,17 +816,12 @@ static int seg_init(AVFormatContext *s)
close_null_ctxp(&oc->pb);
}
if ((ret = oc->io_open(oc, &oc->pb, oc->filename, AVIO_FLAG_WRITE, NULL)) < 0)
- goto fail;
+ return ret;
if (!seg->individual_header_trailer)
oc->pb->seekable = 0;
}
-fail:
- av_dict_free(&options);
- if (ret < 0)
- seg_free_context(seg);
-
- return ret;
+ return 0;
}
static int seg_write_packet(AVFormatContext *s, AVPacket *pkt)
@@ -1031,6 +1056,7 @@ AVOutputFormat ff_segment_muxer = {
.priv_data_size = sizeof(SegmentContext),
.flags = AVFMT_NOFILE|AVFMT_GLOBALHEADER,
.init = seg_init,
+ .write_header = seg_write_header,
.write_packet = seg_write_packet,
.write_trailer = seg_write_trailer,
.deinit = seg_free,
@@ -1051,6 +1077,7 @@ AVOutputFormat ff_stream_segment_muxer = {
.priv_data_size = sizeof(SegmentContext),
.flags = AVFMT_NOFILE,
.init = seg_init,
+ .write_header = seg_write_header,
.write_packet = seg_write_packet,
.write_trailer = seg_write_trailer,
.deinit = seg_free,
--
2.7.3
More information about the ffmpeg-devel
mailing list