0

Is there a way to script filters for ffmpeg, such that when ever I give an input, the filter will change behavior?

An example would be changing contrast with a key, or blending two videos with another key, while recording the stream.

I've seen I could do this in a static way, like restart recording with the new behavior, and calling for a concat after, this results in some frame loss because of the process killing and process lifiting, but I wanted to know If this is possible, with out calling for restart.

ekiim
  • 792
  • 1
  • 11
  • 25

2 Answers2

1

I think you're looking for sendcmd, which is supported by several filters. See the FFmpeg filters documentation (search for sendcmd).

llogan
  • 121,796
  • 28
  • 232
  • 243
Mike Versteeg
  • 1,615
  • 14
  • 28
1

Use the zmq and azmq filters. Unlike the sendcmd filter, which uses pre-written commands, (a)zmq allows you arbitrarily to send filter commands.

To enable these filters you need to install the libzmq library and headers and configure ffmpeg with --enable-libzmq.

Only filters that support commands can be used with this filter. Refer to the output of ffmpeg -filters to view a list of which filters support commands. Additionally, not all options for a filter are considered to be commands. Refer to the documentation of each filter for a list of supported commands.


Examples from the documentation

Consider the following filtergraph generated by ffplay. In this example the last overlay filter has an instance name. All other filters will have default instance names.

ffplay -dumpgraph 1 -f lavfi "
color=s=100x100:c=red  [l];
color=s=100x100:c=blue [r];
nullsrc=s=200x100, zmq [bg];
[bg][l]   overlay     [bg+l];
[bg+l][r] overlay@my=x=100 "

To change the color of the left side of the video, the following command can be used:

echo Parsed_color_0 c yellow | tools/zmqsend

To change the right side:

echo Parsed_color_1 c pink | tools/zmqsend

To change the position of the right side:

echo overlay@my x 150 | tools/zmqsend

llogan
  • 121,796
  • 28
  • 232
  • 243