Re: [FFmpeg-devel] [PATCH 4/7] lavf/segment: write attached pictures to all segments by default

2017-11-21 Thread Rostislav Pehlivanov
On 2 August 2017 at 07:30, Rodger Combs  wrote:

> ---
>  doc/muxers.texi   |  4 
>  libavformat/segment.c | 40 +---
>  2 files changed, 33 insertions(+), 11 deletions(-)
>
> diff --git a/doc/muxers.texi b/doc/muxers.texi
> index 23ef2e7..93147e1 100644
> --- a/doc/muxers.texi
> +++ b/doc/muxers.texi
> @@ -1576,6 +1576,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}.
> +
> +@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 ef0a915..632476e 100644
> --- a/libavformat/segment.c
> +++ b/libavformat/segment.c
> @@ -119,6 +119,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];
> @@ -126,6 +127,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)
> @@ -193,16 +196,15 @@ static int replace_variables(AVFormatContext *oc)
>  {
>  char name[sizeof(oc->filename)];
>  char *p = name;
> -char *out = oc->filename;
> +AVBPrint bprint;
>  strncpy(name, oc->filename, sizeof(name));
> +av_bprint_init_for_buffer(&bprint, oc->filename,
> sizeof(oc->filename));
>  while (*p) {
>  char c = *p++;
>  if (c == '$') {
>  if (*p == '$') {
> -p++;
> -goto append;
> +av_bprint_chars(&bprint, c, 1);
>  } else {
> -int len;
>  const char *val;
>  const AVDictionaryEntry *e;
>  int end = strcspn(p, "$");
> @@ -211,18 +213,13 @@ static int replace_variables(AVFormatContext *oc)
>  p[end] = '\0';
>  e = av_dict_get(oc->metadata, p, NULL, 0);
>  val = e ? e->value : "(unknown)";
> -len = strlen(val);
> -strncpy(out, val, oc->filename + sizeof(oc->filename) - 1
> - out);
> -out = FFMIN(oc->filename + sizeof(oc->filename) - 1, out
> + len);
> +av_bprint_append_data(&bprint, val, strlen(val));
>  p += end + 1;
>  }
>  } else {
> -append:
> -if (out - oc->filename < sizeof(oc->filename) - 1)
> -*out++ = c;
> +av_bprint_chars(&bprint, c, 1);
>  }
>  }
> -*out = '\0';
>  return 0;
>  }
>
> @@ -301,6 +298,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);
> @@ -308,6 +306,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;
> @@ -680,6 +685,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)
> @@ -840,6 +851,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;
>
> @@ -905,6 +919,9 @@ static int seg_write_packet(AVFormatContext *s,
> AVPacket *pkt)
>  if (!seg->avf || !seg->avf

[FFmpeg-devel] [PATCH 4/7] lavf/segment: write attached pictures to all segments by default

2017-08-02 Thread Rodger Combs
---
 doc/muxers.texi   |  4 
 libavformat/segment.c | 40 +---
 2 files changed, 33 insertions(+), 11 deletions(-)

diff --git a/doc/muxers.texi b/doc/muxers.texi
index 23ef2e7..93147e1 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -1576,6 +1576,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}.
+
+@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 ef0a915..632476e 100644
--- a/libavformat/segment.c
+++ b/libavformat/segment.c
@@ -119,6 +119,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];
@@ -126,6 +127,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)
@@ -193,16 +196,15 @@ static int replace_variables(AVFormatContext *oc)
 {
 char name[sizeof(oc->filename)];
 char *p = name;
-char *out = oc->filename;
+AVBPrint bprint;
 strncpy(name, oc->filename, sizeof(name));
+av_bprint_init_for_buffer(&bprint, oc->filename, sizeof(oc->filename));
 while (*p) {
 char c = *p++;
 if (c == '$') {
 if (*p == '$') {
-p++;
-goto append;
+av_bprint_chars(&bprint, c, 1);
 } else {
-int len;
 const char *val;
 const AVDictionaryEntry *e;
 int end = strcspn(p, "$");
@@ -211,18 +213,13 @@ static int replace_variables(AVFormatContext *oc)
 p[end] = '\0';
 e = av_dict_get(oc->metadata, p, NULL, 0);
 val = e ? e->value : "(unknown)";
-len = strlen(val);
-strncpy(out, val, oc->filename + sizeof(oc->filename) - 1 - 
out);
-out = FFMIN(oc->filename + sizeof(oc->filename) - 1, out + 
len);
+av_bprint_append_data(&bprint, val, strlen(val));
 p += end + 1;
 }
 } else {
-append:
-if (out - oc->filename < sizeof(oc->filename) - 1)
-*out++ = c;
+av_bprint_chars(&bprint, c, 1);
 }
 }
-*out = '\0';
 return 0;
 }
 
@@ -301,6 +298,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);
@@ -308,6 +306,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;
@@ -680,6 +685,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)
@@ -840,6 +851,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;
 
@@ -905,6 +919,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 ?
@@ -,6 +1128,7

Re: [FFmpeg-devel] [PATCH 4/7] lavf/segment: write attached pictures to all segments by default

2017-08-01 Thread Steven Liu
2017-08-01 15:16 GMT+08:00 Rodger Combs :
> Variables may be declared at the top of a scope block in ffmpeg.
yes, this is not a rule, just a suggest, for the code read clear.
>
>> On Aug 1, 2017, at 01:50, Steven Liu  wrote:
>>
>> 2017-08-01 14:33 GMT+08:00 Rodger Combs > >:
>>> ---
>>> doc/muxers.texi   |  4 
>>> libavformat/segment.c | 24 
>>> 2 files changed, 28 insertions(+)
>>>
>>> diff --git a/doc/muxers.texi b/doc/muxers.texi
>>> index 23ef2e7..93147e1 100644
>>> --- a/doc/muxers.texi
>>> +++ b/doc/muxers.texi
>>> @@ -1576,6 +1576,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}.
>>> +
>>> +@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 ef0a915..8e82030 100644
>>> --- a/libavformat/segment.c
>>> +++ b/libavformat/segment.c
>>> @@ -119,6 +119,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];
>>> @@ -126,6 +127,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)
>>> @@ -301,6 +304,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;
>> move to the top of the function,
>>> AVDictionary *options = NULL;
>>> av_dict_copy(&options, seg->format_options, 0);
>>> av_dict_set(&options, "fflags", "-autobsf", 0);
>>> @@ -308,6 +312,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;
>>> @@ -680,6 +691,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;
>> move to the top of the function,
>>> +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)
>>> @@ -840,6 +857,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;
>>>
>>> @@ -905,6 +925,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 ?
>>> @@ -,6 +1134,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 },
>>> };
>>>
>>> --
>>> 2.6.4
>>>
>>> _

Re: [FFmpeg-devel] [PATCH 4/7] lavf/segment: write attached pictures to all segments by default

2017-08-01 Thread Rodger Combs
Variables may be declared at the top of a scope block in ffmpeg.

> On Aug 1, 2017, at 01:50, Steven Liu  wrote:
> 
> 2017-08-01 14:33 GMT+08:00 Rodger Combs  >:
>> ---
>> doc/muxers.texi   |  4 
>> libavformat/segment.c | 24 
>> 2 files changed, 28 insertions(+)
>> 
>> diff --git a/doc/muxers.texi b/doc/muxers.texi
>> index 23ef2e7..93147e1 100644
>> --- a/doc/muxers.texi
>> +++ b/doc/muxers.texi
>> @@ -1576,6 +1576,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}.
>> +
>> +@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 ef0a915..8e82030 100644
>> --- a/libavformat/segment.c
>> +++ b/libavformat/segment.c
>> @@ -119,6 +119,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];
>> @@ -126,6 +127,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)
>> @@ -301,6 +304,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;
> move to the top of the function,
>> AVDictionary *options = NULL;
>> av_dict_copy(&options, seg->format_options, 0);
>> av_dict_set(&options, "fflags", "-autobsf", 0);
>> @@ -308,6 +312,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;
>> @@ -680,6 +691,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;
> move to the top of the function,
>> +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)
>> @@ -840,6 +857,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;
>> 
>> @@ -905,6 +925,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 ?
>> @@ -,6 +1134,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 },
>> };
>> 
>> --
>> 2.6.4
>> 
>> ___
>> ffmpeg-devel mailing list
>> ffmpeg-devel@ffmpeg.org 
>> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel 
>> 
> 

Re: [FFmpeg-devel] [PATCH 4/7] lavf/segment: write attached pictures to all segments by default

2017-07-31 Thread Steven Liu
2017-08-01 14:33 GMT+08:00 Rodger Combs :
> ---
>  doc/muxers.texi   |  4 
>  libavformat/segment.c | 24 
>  2 files changed, 28 insertions(+)
>
> diff --git a/doc/muxers.texi b/doc/muxers.texi
> index 23ef2e7..93147e1 100644
> --- a/doc/muxers.texi
> +++ b/doc/muxers.texi
> @@ -1576,6 +1576,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}.
> +
> +@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 ef0a915..8e82030 100644
> --- a/libavformat/segment.c
> +++ b/libavformat/segment.c
> @@ -119,6 +119,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];
> @@ -126,6 +127,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)
> @@ -301,6 +304,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;
move to the top of the function,
>  AVDictionary *options = NULL;
>  av_dict_copy(&options, seg->format_options, 0);
>  av_dict_set(&options, "fflags", "-autobsf", 0);
> @@ -308,6 +312,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;
> @@ -680,6 +691,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;
move to the top of the function,
> +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)
> @@ -840,6 +857,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;
>
> @@ -905,6 +925,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 ?
> @@ -,6 +1134,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 },
>  };
>
> --
> 2.6.4
>
> ___
> ffmpeg-devel mailing list
> ffmpeg-devel@ffmpeg.org
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel
___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


[FFmpeg-devel] [PATCH 4/7] lavf/segment: write attached pictures to all segments by default

2017-07-31 Thread Rodger Combs
---
 doc/muxers.texi   |  4 
 libavformat/segment.c | 24 
 2 files changed, 28 insertions(+)

diff --git a/doc/muxers.texi b/doc/muxers.texi
index 23ef2e7..93147e1 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -1576,6 +1576,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}.
+
+@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 ef0a915..8e82030 100644
--- a/libavformat/segment.c
+++ b/libavformat/segment.c
@@ -119,6 +119,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];
@@ -126,6 +127,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)
@@ -301,6 +304,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);
@@ -308,6 +312,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;
@@ -680,6 +691,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)
@@ -840,6 +857,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;
 
@@ -905,6 +925,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 ?
@@ -,6 +1134,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 },
 };
 
-- 
2.6.4

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel


Re: [FFmpeg-devel] [PATCH 4/7] lavf/segment: write attached pictures to all segments by default

2017-05-08 Thread Steven Liu
2017-05-08 12:36 GMT+08:00 Rodger Combs :

> ---
>  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}.
> +
> +@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,
> \
>  

[FFmpeg-devel] [PATCH 4/7] lavf/segment: write attached pictures to all segments by default

2017-05-07 Thread Rodger Combs
---
 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}.
+
+@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

___
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
http://ffmpeg.org/mailman/listinfo/ffmpeg-devel