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

Rodger Combs rodger.combs at gmail.com
Tue Aug 1 10:16:17 EEST 2017


Variables may be declared at the top of a scope block in ffmpeg.

> On Aug 1, 2017, at 01:50, Steven Liu <lingjiujianke at gmail.com> wrote:
> 
> 2017-08-01 14:33 GMT+08:00 Rodger Combs <rodger.combs at gmail.com <mailto:rodger.combs at gmail.com>>:
>> ---
>> 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}.
>> +
>> + 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 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 ?
>> @@ -1111,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 at ffmpeg.org <mailto:ffmpeg-devel at ffmpeg.org>
>> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel <http://ffmpeg.org/mailman/listinfo/ffmpeg-devel>
> _______________________________________________
> ffmpeg-devel mailing list
> ffmpeg-devel at ffmpeg.org <mailto:ffmpeg-devel at ffmpeg.org>
> http://ffmpeg.org/mailman/listinfo/ffmpeg-devel <http://ffmpeg.org/mailman/listinfo/ffmpeg-devel>


More information about the ffmpeg-devel mailing list