char *reference_stream_specifier; ///< reference stream specifier
int reference_stream_index;
int break_non_keyframes;
+ int write_empty;
int use_rename;
char temp_list_filename[1024];
for (i = 0; i < s->nb_streams; i++) {
AVStream *st;
- AVCodecContext *icodec, *ocodec;
+ AVCodecParameters *ipar, *opar;
if (!(st = avformat_new_stream(oc, NULL)))
return AVERROR(ENOMEM);
- icodec = s->streams[i]->codec;
- ocodec = st->codec;
- avcodec_copy_context(ocodec, icodec);
+ ipar = s->streams[i]->codecpar;
+ opar = st->codecpar;
+ avcodec_parameters_copy(opar, ipar);
if (!oc->oformat->codec_tag ||
- av_codec_get_id (oc->oformat->codec_tag, icodec->codec_tag) == ocodec->codec_id ||
- av_codec_get_tag(oc->oformat->codec_tag, icodec->codec_id) <= 0) {
- ocodec->codec_tag = icodec->codec_tag;
+ av_codec_get_id (oc->oformat->codec_tag, ipar->codec_tag) == opar->codec_id ||
+ av_codec_get_tag(oc->oformat->codec_tag, ipar->codec_id) <= 0) {
+ opar->codec_tag = ipar->codec_tag;
} else {
- ocodec->codec_tag = 0;
+ opar->codec_tag = 0;
}
st->sample_aspect_ratio = s->streams[i]->sample_aspect_ratio;
st->time_base = s->streams[i]->time_base;
if (tcr) {
/* search the first video stream */
for (i = 0; i < s->nb_streams; i++) {
- if (s->streams[i]->codec->codec_type == AVMEDIA_TYPE_VIDEO) {
+ if (s->streams[i]->codecpar->codec_type == AVMEDIA_TYPE_VIDEO) {
rate = s->streams[i]->avg_frame_rate;/* Get fps from the video stream */
err = av_timecode_init_from_string(&tc, rate, tcr->value, s);
if (err < 0) {
/* select first index for each type */
for (i = 0; i < s->nb_streams; i++) {
- type = s->streams[i]->codec->codec_type;
+ type = s->streams[i]->codecpar->codec_type;
if ((unsigned)type < AVMEDIA_TYPE_NB && type_index_map[type] == -1
/* ignore attached pictures/cover art streams */
&& !(s->streams[i]->disposition & AV_DISPOSITION_ATTACHED_PIC))
goto fail;
av_log(s, AV_LOG_VERBOSE, "Selected stream id:%d type:%s\n",
seg->reference_stream_index,
- av_get_media_type_string(s->streams[seg->reference_stream_index]->codec->codec_type));
+ av_get_media_type_string(s->streams[seg->reference_stream_index]->codecpar->codec_type));
seg->oformat = av_guess_format(seg->format, s->filename, NULL);
if (!seg->avf)
return AVERROR(EINVAL);
+calc_times:
if (seg->times) {
end_pts = seg->segment_count < seg->nb_times ?
seg->times[seg->segment_count] : INT64_MAX;
if (pkt->stream_index == seg->reference_stream_index &&
(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 ||
(pkt->pts != AV_NOPTS_VALUE &&
av_compare_ts(pkt->pts, st->time_base,
- end_pts-seg->time_delta, AV_TIME_BASE_Q) >= 0))) {
+ end_pts - seg->time_delta, AV_TIME_BASE_Q) >= 0))) {
/* sanitize end time in case last packet didn't have a defined duration */
if (seg->cur_entry.last_duration == 0)
seg->cur_entry.end_time = (double)pkt->pts * av_q2d(st->time_base);
seg->cur_entry.index = seg->segment_idx + seg->segment_idx_wrap * seg->segment_idx_wrap_nb;
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.end_time = seg->cur_entry.start_time +
- pkt->pts != AV_NOPTS_VALUE ? (double)(pkt->pts + pkt->duration) * av_q2d(st->time_base) : 0;
- } else if (pkt->pts != AV_NOPTS_VALUE && pkt->stream_index == seg->reference_stream_index) {
- seg->cur_entry.end_time =
- FFMAX(seg->cur_entry.end_time, (double)(pkt->pts + pkt->duration) * av_q2d(st->time_base));
+ 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->pts != AV_NOPTS_VALUE)
+ seg->cur_entry.end_time =
+ FFMAX(seg->cur_entry.end_time, (double)(pkt->pts + pkt->duration) * av_q2d(st->time_base));
seg->cur_entry.last_duration = pkt->duration;
}
{ "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 },
{ "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 },
};