[FFmpeg-devel] [PATCH 4/7] lavf/segment: write attached pictures to all segments by default
Rodger Combs
rodger.combs at gmail.com
Mon May 8 07:36:21 EEST 2017
---
doc/muxers.texi | 4 ++++
libavformat/segment.c | 24 ++++++++++++++++++++++++
libavformat/version.h | 2 +-
3 files changed, 29 insertions(+), 1 deletion(-)
diff --git a/doc/muxers.texi b/doc/muxers.texi
index b80bc68..3707d05 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -1559,6 +1559,10 @@ argument must be a time duration specification, and defaults to 0.
If enabled, write an empty segment if there are no packets during the period a
segment would usually span. Otherwise, the segment will be filled with the next
packet written. Defaults to @code{0}.
+
+ at item dup_attached_pics @var{1|0}
+If enabled, attached-picture packets will be written to all segments, rather
+than only the first. Defaults to @code{1}.
@end table
@subsection Examples
diff --git a/libavformat/segment.c b/libavformat/segment.c
index 9c6ce73..0b9089c 100644
--- a/libavformat/segment.c
+++ b/libavformat/segment.c
@@ -121,6 +121,7 @@ typedef struct SegmentContext {
int reference_stream_index;
int break_non_keyframes;
int write_empty;
+ int dup_attached_pics;
int use_rename;
char temp_list_filename[1024];
@@ -128,6 +129,8 @@ typedef struct SegmentContext {
SegmentListEntry cur_entry;
SegmentListEntry *segment_list_entries;
SegmentListEntry *segment_list_entries_end;
+
+ AVPacket *attached_pics;
} SegmentContext;
static void print_csv_escaped_str(AVIOContext *ctx, const char *str)
@@ -303,6 +306,7 @@ static int segment_start(AVFormatContext *s, int write_header)
av_opt_set(oc->priv_data, "mpegts_flags", "+resend_headers", 0);
if (write_header) {
+ int i;
AVDictionary *options = NULL;
av_dict_copy(&options, seg->format_options, 0);
av_dict_set(&options, "fflags", "-autobsf", 0);
@@ -310,6 +314,13 @@ static int segment_start(AVFormatContext *s, int write_header)
av_dict_free(&options);
if (err < 0)
return err;
+ for (i = 0; i < s->nb_streams; i++) {
+ if (seg->dup_attached_pics &&
+ s->streams[i]->disposition & AV_DISPOSITION_ATTACHED_PIC &&
+ seg->attached_pics[i].data) {
+ av_write_frame(oc, &seg->attached_pics[i]);
+ }
+ }
}
seg->segment_frame_count = 0;
@@ -682,6 +693,12 @@ static void seg_free(AVFormatContext *s)
ff_format_io_close(seg->avf, &seg->list_pb);
avformat_free_context(seg->avf);
seg->avf = NULL;
+ if (seg->attached_pics) {
+ int i;
+ for (i = 0; i < s->nb_streams; i++)
+ av_packet_unref(&seg->attached_pics[i]);
+ av_freep(&seg->attached_pics);
+ }
}
static int seg_init(AVFormatContext *s)
@@ -842,6 +859,9 @@ static int seg_init(AVFormatContext *s)
avpriv_set_pts_info(outer_st, inner_st->pts_wrap_bits, inner_st->time_base.num, inner_st->time_base.den);
}
+ if (seg->dup_attached_pics && !(seg->attached_pics = av_calloc(s->nb_streams, sizeof(AVPacket))))
+ return AVERROR(ENOMEM);
+
if (oc->avoid_negative_ts > 0 && s->avoid_negative_ts < 0)
s->avoid_negative_ts = 1;
@@ -907,6 +927,9 @@ static int seg_write_packet(AVFormatContext *s, AVPacket *pkt)
if (!seg->avf || !seg->avf->pb)
return AVERROR(EINVAL);
+ if (seg->dup_attached_pics && st->disposition & AV_DISPOSITION_ATTACHED_PIC)
+ av_copy_packet(&seg->attached_pics[pkt->stream_index], pkt);
+
calc_times:
if (seg->times) {
end_pts = seg->segment_count < seg->nb_times ?
@@ -1113,6 +1136,7 @@ static const AVOption options[] = {
{ "reset_timestamps", "reset timestamps at the begin of each segment", OFFSET(reset_timestamps), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, E },
{ "initial_offset", "set initial timestamp offset", OFFSET(initial_offset), AV_OPT_TYPE_DURATION, {.i64 = 0}, -INT64_MAX, INT64_MAX, E },
{ "write_empty_segments", "allow writing empty 'filler' segments", OFFSET(write_empty), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, E },
+ { "dup_attached_pics", "write attached pictures to all segments", OFFSET(dup_attached_pics), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, E },
{ NULL },
};
diff --git a/libavformat/version.h b/libavformat/version.h
index 645a226..910e348 100644
--- a/libavformat/version.h
+++ b/libavformat/version.h
@@ -33,7 +33,7 @@
// Also please add any ticket numbers that you believe might be affected here
#define LIBAVFORMAT_VERSION_MAJOR 57
#define LIBAVFORMAT_VERSION_MINOR 73
-#define LIBAVFORMAT_VERSION_MICRO 101
+#define LIBAVFORMAT_VERSION_MICRO 102
#define LIBAVFORMAT_VERSION_INT AV_VERSION_INT(LIBAVFORMAT_VERSION_MAJOR, \
LIBAVFORMAT_VERSION_MINOR, \
--
2.6.4
More information about the ffmpeg-devel
mailing list