[FFmpeg-devel] [PATCH] avfilter/avf_concat: add next command

Bodecs Bela bodecsb at vivanet.hu
Sun Feb 25 18:07:40 EET 2018


Dear All,

this patch makes it possible to dinamically close the current segment
and step to the next one by introducing command handling capabilities
into the filter. This new feature is very usefull when working with
real-time sources or live streams as source. Combinig usage with zmqsend
tool you can interactively end the current segment and step to next one.

it is very usefull in case of event streaming when sending an intro then a
live section and then an outro and you want to start and stop the live 
event manually.

example:

ffmpeg -re -i very_long_intro.mp4 -i <event_source> -re -i 
very_long_outro.mp4
     -filter_complex   '[0:v][0:a] [1:v][1:a] [2:v][2:a] 
concat=n=3:v=1:a=1 [v] [a];
                                   [v] 
zmq=b=tcp\\:\\/\\/127.0.0.1\\:5555  [v_out]'
     -map '[v_out]' -map '[a]'  <output>

When you you want to start the live event, issue in another window:
echo "Parsed_concat_0 next" | zmqsend  -b tcp://127.0.0.1:5555

When you want to end the live session:
echo "Parsed_concat_0 next" | zmqsend  -b tcp://127.0.0.1:5555


Please review this patch. Thank you in advance.

Bela Bodecs


-------------- next part --------------
>From daa8ecc9b01f78bc62f23880e3b2632d2c8e56c5 Mon Sep 17 00:00:00 2001
From: Bela Bodecs <bodecsb at vivanet.hu>
Date: Sun, 25 Feb 2018 16:45:59 +0100
Subject: [PATCH] avfilter/avf_concat: add next command

This patch makes it possible to dinamically close the current segment
and step to the next one by introducing command handling capabilities
into the filter. This new feature is very usefull when working with
real-time sources or live streams as source. Combinig usage with zmqsend
tool you can interactively end the current segment and step to next one.

Signed-off-by: Bela Bodecs <bodecsb at vivanet.hu>
---
 doc/filters.texi         |  9 +++++++++
 libavfilter/avf_concat.c | 16 ++++++++++++++++
 2 files changed, 25 insertions(+)

diff --git a/doc/filters.texi b/doc/filters.texi
index 6ad2db2..40023da 100644
--- a/doc/filters.texi
+++ b/doc/filters.texi
@@ -15862,6 +15862,15 @@ do not have exactly the same duration in the first file.
 
 @end itemize
 
+ at subsection Commands
+
+This filter supports the following commands:
+ at table @option
+ at item next
+Close the current segment and step to the next one
+ at end table
+
+
 @section drawgraph, adrawgraph
 
 Draw a graph using input video or audio metadata.
diff --git a/libavfilter/avf_concat.c b/libavfilter/avf_concat.c
index 56e4179..25b3752 100644
--- a/libavfilter/avf_concat.c
+++ b/libavfilter/avf_concat.c
@@ -411,6 +411,21 @@ static av_cold void uninit(AVFilterContext *ctx)
     av_freep(&cat->in);
 }
 
+
+static int process_command(AVFilterContext *ctx, const char *cmd, const char *args,
+                           char *res, int res_len, int flags)
+{
+    int ret = AVERROR(ENOSYS);
+
+    if (!strcmp(cmd, "next")) {
+        av_log(ctx, AV_LOG_VERBOSE, "Command received: next\n");
+        return flush_segment(ctx);
+    }
+
+    return ret;
+}
+
+
 AVFilter ff_avf_concat = {
     .name          = "concat",
     .description   = NULL_IF_CONFIG_SMALL("Concatenate audio and video streams."),
@@ -422,4 +437,5 @@ AVFilter ff_avf_concat = {
     .outputs       = NULL,
     .priv_class    = &concat_class,
     .flags         = AVFILTER_FLAG_DYNAMIC_INPUTS | AVFILTER_FLAG_DYNAMIC_OUTPUTS,
+    .process_command = process_command,
 };
-- 
2.5.3.windows.1



More information about the ffmpeg-devel mailing list