[FFmpeg-devel] [PATCH v2 3/3] avformat/fifo: add option to delay output
leozhang
leozhang at qiyi.com
Thu May 7 09:17:21 EEST 2020
Suggested-by: Nicolas George <george at nsup.org>
Reviewed-by: Nicolas George <george at nsup.org>
Reviewed-by: Marton Balint <cus at passwd.hu>
Reviewed-by: Andreas Rheinhardt <andreas.rheinhardt at gmail.com>
Signed-off-by: leozhang <leozhang at qiyi.com>
---
doc/muxers.texi | 14 ++++++++++++++
libavformat/fifo.c | 8 ++++++++
2 files changed, 22 insertions(+)
diff --git a/doc/muxers.texi b/doc/muxers.texi
index 14528f1..272cf24 100644
--- a/doc/muxers.texi
+++ b/doc/muxers.texi
@@ -2285,6 +2285,10 @@ It is the same as the speed option to realtime or arealtime filters.
@item realtime_limit @var{duration}
It is the same as the limit option to realtime or arealtime filters.
+ at item output_delay @var{duration}
+Time to delay output. This will block every output packet for the extra specified duration. Default value is 0.
+This option is useful when user wouldn't want broadcast what's comming next immediately in live streaming applications.
+
@end table
@subsection Examples
@@ -2312,6 +2316,16 @@ ffmpeg -i your_input_file -c copy -map 0:v -map 0:a -f fifo -fifo_format flv -re
@end itemize
+ at itemize
+
+ at item
+Add 20 seconds delay to rtmp stream.
+ at example
+ffmpeg -i your_input_stream_address -c copy -map 0:a -map 0:v -f fifo -realtime 1 -queue_size 6000000 -output_delay 20 -fifo_format flv rtmp://example.com/live/delayed_stream_name
+ at end example
+
+ at end itemize
+
@anchor{tee}
@section tee
diff --git a/libavformat/fifo.c b/libavformat/fifo.c
index b819aeb..ba463e4 100644
--- a/libavformat/fifo.c
+++ b/libavformat/fifo.c
@@ -89,6 +89,9 @@ typedef struct FifoContext {
int64_t delta;
unsigned inited;
+
+ /* Time to delay output */
+ int64_t output_delay;
} FifoContext;
typedef struct FifoThreadContext {
@@ -439,6 +442,8 @@ static void *fifo_consumer_thread(void *data)
memset(&fifo_thread_ctx, 0, sizeof(FifoThreadContext));
fifo_thread_ctx.avf = avf;
+ fifo_sleep(fifo->output_delay);
+
while (1) {
uint8_t just_flushed = 0;
@@ -681,6 +686,9 @@ static const AVOption options[] = {
{"realtime_limit", "Time limit for the pauses when realtime", OFFSET(realtime_limit),
AV_OPT_TYPE_DURATION, {.i64 = 2000000}, 0, INT64_MAX, AV_OPT_FLAG_ENCODING_PARAM},
+ {"output_delay", "Time to delay output", OFFSET(output_delay),
+ AV_OPT_TYPE_DURATION, {.i64 = 0}, 0, INT64_MAX, AV_OPT_FLAG_ENCODING_PARAM},
+
{NULL},
};
--
1.8.3.1
More information about the ffmpeg-devel
mailing list