[FFmpeg-devel] [PATCH 2/3] concatdec: add force_duration option
Andrey Utkin
andrey.krieger.utkin at gmail.com
Mon Jun 23 13:01:18 CEST 2014
When set to 1, demuxer stops reading file when timestamp reaches stated duration
---
libavformat/concatdec.c | 15 +++++++++++++++
1 file changed, 15 insertions(+)
diff --git a/libavformat/concatdec.c b/libavformat/concatdec.c
index b3e6a37..263e00f 100644
--- a/libavformat/concatdec.c
+++ b/libavformat/concatdec.c
@@ -56,6 +56,7 @@ typedef struct {
int seekable;
ConcatMatchMode stream_match_mode;
unsigned auto_convert;
+ int force_duration;
} ConcatContext;
static int concat_probe(AVProbeData *probe)
@@ -516,6 +517,18 @@ static int concat_read_packet(AVFormatContext *avf, AVPacket *pkt)
av_packet_unref(pkt);
continue;
}
+ if (cat->force_duration && cat->cur_file->duration != AV_NOPTS_VALUE
+ && pkt->pts != AV_NOPTS_VALUE) {
+ int64_t duration_up_to_now = av_rescale_q(pkt->pts,
+ cat->avf->streams[pkt->stream_index]->time_base, AV_TIME_BASE_Q)
+ - cat->cur_file->start_time;
+ if (duration_up_to_now > cat->cur_file->duration) {
+ av_packet_unref(pkt);
+ if ((ret = open_next_file(avf)) < 0)
+ return ret;
+ continue;
+ }
+ }
pkt->stream_index = cs->out_stream_index;
break;
}
@@ -629,6 +642,8 @@ static const AVOption options[] = {
OFFSET(safe), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 1, DEC },
{ "auto_convert", "automatically convert bitstream format",
OFFSET(auto_convert), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, DEC },
+ { "force_duration", "stop reading file when timestamp reaches stated duration",
+ OFFSET(force_duration), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 1, DEC },
{ NULL }
};
--
1.8.3.2
More information about the ffmpeg-devel
mailing list