lavf/segment: add option to write empty filler segments as needed

pull/193/merge
Rodger Combs 9 years ago
parent 5b4f44f66a
commit 4b150fbe1f
  1. 5
      doc/muxers.texi
  2. 8
      libavformat/segment.c

@ -1238,6 +1238,11 @@ muxers/codecs. It is set to @code{0} by default.
@item initial_offset @var{offset} @item initial_offset @var{offset}
Specify timestamp offset to apply to the output packet timestamps. The Specify timestamp offset to apply to the output packet timestamps. The
argument must be a time duration specification, and defaults to 0. argument must be a time duration specification, and defaults to 0.
@item write_empty_segments @var{1|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}.
@end table @end table
@subsection Examples @subsection Examples

@ -118,6 +118,7 @@ typedef struct SegmentContext {
char *reference_stream_specifier; ///< reference stream specifier char *reference_stream_specifier; ///< reference stream specifier
int reference_stream_index; int reference_stream_index;
int break_non_keyframes; int break_non_keyframes;
int write_empty;
int use_rename; int use_rename;
char temp_list_filename[1024]; char temp_list_filename[1024];
@ -810,6 +811,7 @@ static int seg_write_packet(AVFormatContext *s, AVPacket *pkt)
if (!seg->avf) if (!seg->avf)
return AVERROR(EINVAL); return AVERROR(EINVAL);
calc_times:
if (seg->times) { if (seg->times) {
end_pts = seg->segment_count < seg->nb_times ? end_pts = seg->segment_count < seg->nb_times ?
seg->times[seg->segment_count] : INT64_MAX; seg->times[seg->segment_count] : INT64_MAX;
@ -841,7 +843,7 @@ static int seg_write_packet(AVFormatContext *s, AVPacket *pkt)
if (pkt->stream_index == seg->reference_stream_index && if (pkt->stream_index == seg->reference_stream_index &&
(pkt->flags & AV_PKT_FLAG_KEY || seg->break_non_keyframes) && (pkt->flags & AV_PKT_FLAG_KEY || seg->break_non_keyframes) &&
seg->segment_frame_count > 0 && (seg->segment_frame_count > 0 || seg->write_empty) &&
(seg->cut_pending || seg->frame_count >= start_frame || (seg->cut_pending || seg->frame_count >= start_frame ||
(pkt->pts != AV_NOPTS_VALUE && (pkt->pts != AV_NOPTS_VALUE &&
av_compare_ts(pkt->pts, st->time_base, av_compare_ts(pkt->pts, st->time_base,
@ -861,6 +863,9 @@ static int seg_write_packet(AVFormatContext *s, AVPacket *pkt)
seg->cur_entry.start_time = (double)pkt->pts * av_q2d(st->time_base); seg->cur_entry.start_time = (double)pkt->pts * av_q2d(st->time_base);
seg->cur_entry.start_pts = av_rescale_q(pkt->pts, st->time_base, AV_TIME_BASE_Q); seg->cur_entry.start_pts = av_rescale_q(pkt->pts, st->time_base, AV_TIME_BASE_Q);
seg->cur_entry.end_time = seg->cur_entry.start_time; seg->cur_entry.end_time = seg->cur_entry.start_time;
if (seg->times || (!seg->frames && !seg->use_clocktime) && seg->write_empty)
goto calc_times;
} }
if (pkt->stream_index == seg->reference_stream_index) { if (pkt->stream_index == seg->reference_stream_index) {
@ -1010,6 +1015,7 @@ static const AVOption options[] = {
{ "write_header_trailer", "write a header to the first segment and a trailer to the last one", OFFSET(write_header_trailer), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, E }, { "write_header_trailer", "write a header to the first segment and a trailer to the last one", OFFSET(write_header_trailer), AV_OPT_TYPE_BOOL, {.i64 = 1}, 0, 1, E },
{ "reset_timestamps", "reset timestamps at the begin of each segment", OFFSET(reset_timestamps), AV_OPT_TYPE_BOOL, {.i64 = 0}, 0, 1, E }, { "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 }, { "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 },
{ NULL }, { NULL },
}; };

Loading…
Cancel
Save