change inputs or mapping while recording

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|

change inputs or mapping while recording

Stephan Monecke
Hey!


I have two identical rtsp video-sources stream1, stream2 and an audio
source. I currently merge stream1 with the audio for a rtmp-server
using:

stream1="rtsp://streamurl1"

/usr/bin/ffmpeg                    \
    [...]
    -i "$stream1"                  \
    [...]
    -itsoffset $AUDIOVIDEOOFFSET   \
    -f pulse                       \
    -i default                     \
    [...]
    -vcodec copy                   \
    -map 0:v -map 1:a              \
    [...]
    -f flv "rtmp://streamingserver"

I would now like to add stream2 as second video input and switch
between stream1 and stream2 back and forth without interrupting the
audio. Both streams are identical / come from identical cameras.

Is there any sane way to do this with ffmpeg? Or how would you
recommend doing it?

Just stopping the process and restarting it using stream2 instead of
stream1 with some timeoff on the rtmp-server should work but would
result in several seconds outage on the stream and is the current the
worst case scenario I would like to improve.

Thanks a ton!

Cheers,
Stephan


P.s. Maybe some additional visual information: Since students
currently can't attend, we want to record university
blackboard-lectures (math) but have an array of blackboards that each
get its own camera. Hence we try to keep the audio stream running
while switching the input source when the lecturer switches the
blackboard.
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: change inputs or mapping while recording

Carl Zwanzig
On 4/24/2020 1:50 AM, Stephan Monecke wrote:
> Is there any sane way to do this with ffmpeg? Or how would you
> recommend doing it?

You need something like OBS Studio (free, works well) to do this.

z!
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: change inputs or mapping while recording

kumowoon1025
In reply to this post by Stephan Monecke
Hi,

> I would now like to add stream2 as second video input and switch
> between stream1 and stream2 back and forth without interrupting the
> audio. Both streams are identical / come from identical cameras.
>
> Is there any sane way to do this with ffmpeg? Or how would you
> recommend doing it?
If I had to do this, I would basically composite the two streams and toggle opacity of the top layer between 0 and 1.
It would break if either stream had reading problems, and you would constantly be processing both streams which might not be desirable if you were switching from A to B and never go back to A, for example.

Regards,
Ted Park

_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: change inputs or mapping while recording

Michael Koch
Am 24.04.2020 um 20:08 schrieb Edward Park:
>> I would now like to add stream2 as second video input and switch
>> between stream1 and stream2 back and forth without interrupting the
>> audio. Both streams are identical / come from identical cameras.
>>
>> Is there any sane way to do this with ffmpeg? Or how would you
>> recommend doing it?
> If I had to do this, I would basically composite the two streams and toggle opacity of the top layer between 0 and 1.
> It would break if either stream had reading problems, and you would constantly be processing both streams which might not be desirable if you were switching from A to B and never go back to A, for example.

How can this be done with FFmpeg? Do you have an example? I know how
commands / sendcmd works. The opacity could be toggled, or the
streamselect filter could be used. But where does the switching signal
come from, while FFmpeg is running?

Michael

_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: change inputs or mapping while recording

kumowoon1025
Hi,

> How can this be done with FFmpeg? Do you have an example? I know how commands / sendcmd works. The opacity could be toggled, or the streamselect filter could be used. But where does the switching signal come from, while FFmpeg is running?


The specific messaging protocol/method would depend on a variety of factors including personal preference, but to parrot an example given in the manual using zmq,

% ffmpeg -i INPUT -filter_complex 'null[main];movie=INPUT2,zmq,lumakey@toggle=tolerance=1,[main]overlay,realtime' OUTPUT

and sending commands to the named lumakey filter would mimic toggling between the two streams if they were the same size and position.
i.e. using the zmqsend example program,

% zmqsend <<<"lumakey@toggle tolerance 0"

Regards,
Ted Park

_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: change inputs or mapping while recording

Michael Koch
Am 24.04.2020 um 21:56 schrieb Edward Park:

> Hi,
>
>> How can this be done with FFmpeg? Do you have an example? I know how commands / sendcmd works. The opacity could be toggled, or the streamselect filter could be used. But where does the switching signal come from, while FFmpeg is running?
>
> The specific messaging protocol/method would depend on a variety of factors including personal preference, but to parrot an example given in the manual using zmq,
>
> % ffmpeg -i INPUT -filter_complex 'null[main];movie=INPUT2,zmq,lumakey@toggle=tolerance=1,[main]overlay,realtime' OUTPUT
>
> and sending commands to the named lumakey filter would mimic toggling between the two streams if they were the same size and position.
> i.e. using the zmqsend example program,
>
> % zmqsend <<<"lumakey@toggle tolerance 0"

That works only under Linux, right? It seems libzmq is not enabled in
the FFmpeg build for Windows from Zeranoe.

Michael
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: change inputs or mapping while recording

kumowoon1025
Hi,

> That works only under Linux, right? It seems libzmq is not enabled in the FFmpeg build for Windows from Zeranoe.

FFmpeg would need to have been built with 0mq support but I'm almost sure there are windows versions of the library, client and server. Any way to send commands to a filter would work, you can sort of do it in the shell that's running FFmpeg (typing "c" brings up a command line) but it pauses everything.

Regards,
Ted Park

_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: change inputs or mapping while recording

Stephan Monecke
In reply to this post by kumowoon1025
That looks really interesting! Thanks a lot, I'll have a look at it!

Besides daily checking, I managed to overlook ALL the replies ... sorry for my late answer and thanks a lot for yours!

OBS is not an option since everything is done automatically / from command-line (and afaik OBS transcodes what would additionally overburden the small machine).

It needs to be light and reliable.

For now, I came up with the nginx rtmp plugin that, used as a local loopback device, now acts as a multiplexer.

Two mutually exclusive systemd services forward the respective rtsp stream to the nginx server and ffmpeg records from it.

That way, by starting one or the other service, I switch the stream.

The starting of the two services is bound to the two corresponding arrow keys of a simple Logitech R400 presenter via xbindkeys (the remaining two keys toggle a recording and a YouTube live-stream).
They are present in abundance at the institute and the setup is practically free of cpu usage even on this weak machine.

That way, the lecturer can switch between blackboards / cameras and fully control the procedure just via the presenter.
Best regards,
Stephan Monecke
--
Sent from my mobile device. Please excuse my brevity.

Am 24. April 2020 21:56:12 MESZ schrieb Edward Park <[hidden email]>:

>Hi,
>
>> How can this be done with FFmpeg? Do you have an example? I know how
>commands / sendcmd works. The opacity could be toggled, or the
>streamselect filter could be used. But where does the switching signal
>come from, while FFmpeg is running?
>
>
>The specific messaging protocol/method would depend on a variety of
>factors including personal preference, but to parrot an example given
>in the manual using zmq,
>
>% ffmpeg -i INPUT -filter_complex
>'null[main];movie=INPUT2,zmq,lumakey@toggle=tolerance=1,[main]overlay,realtime'
>OUTPUT
>
>and sending commands to the named lumakey filter would mimic toggling
>between the two streams if they were the same size and position.
>i.e. using the zmqsend example program,
>
>% zmqsend <<<"lumakey@toggle tolerance 0"
>
>Regards,
>Ted Park
>
>_______________________________________________
>ffmpeg-user mailing list
>[hidden email]
>https://ffmpeg.org/mailman/listinfo/ffmpeg-user
>
>To unsubscribe, visit link above, or email
>[hidden email] with subject "unsubscribe".
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".
Reply | Threaded
Open this post in threaded view
|

Re: change inputs or mapping while recording

Stephan Monecke
I just spent two hours unsuccessfully trying to get the given example to work.

zmqsend <<<"lumakey@toggle tolerance 0" never terminates.

I guess, nothing is more permanent than a temporary solution ...

Cheers,
Stephan

P.s. The zmq example given in the docs directly segfaults for me with
a freshly compiled ffmpeg.

Am Mo., 27. Apr. 2020 um 20:50 Uhr schrieb Stephan Monecke
<[hidden email]>:

>
> That looks really interesting! Thanks a lot, I'll have a look at it!
>
> Besides daily checking, I managed to overlook ALL the replies ... sorry for my late answer and thanks a lot for yours!
>
> OBS is not an option since everything is done automatically / from command-line (and afaik OBS transcodes what would additionally overburden the small machine).
>
> It needs to be light and reliable.
>
> For now, I came up with the nginx rtmp plugin that, used as a local loopback device, now acts as a multiplexer.
>
> Two mutually exclusive systemd services forward the respective rtsp stream to the nginx server and ffmpeg records from it.
>
> That way, by starting one or the other service, I switch the stream.
>
> The starting of the two services is bound to the two corresponding arrow keys of a simple Logitech R400 presenter via xbindkeys (the remaining two keys toggle a recording and a YouTube live-stream).
> They are present in abundance at the institute and the setup is practically free of cpu usage even on this weak machine.
>
> That way, the lecturer can switch between blackboards / cameras and fully control the procedure just via the presenter.
> Best regards,
> Stephan Monecke
> --
> Sent from my mobile device. Please excuse my brevity.
>
> Am 24. April 2020 21:56:12 MESZ schrieb Edward Park <[hidden email]>:
>>
>> Hi,
>>
>>> How can this be done with FFmpeg? Do you have an example? I know how commands / sendcmd works. The opacity could be toggled, or the streamselect filter could be used. But where does the switching signal come from, while FFmpeg is running?
>>
>>
>>
>> The specific messaging protocol/method would depend on a variety of factors including personal preference, but to parrot an example given in the manual using zmq,
>>
>> % ffmpeg -i INPUT -filter_complex 'null[main];movie=INPUT2,zmq,lumakey@toggle=tolerance=1,[main]overlay,realtime' OUTPUT
>>
>> and sending commands to the named lumakey filter would mimic toggling between the two streams if they were the same size and position.
>> i.e. using the zmqsend example program,
>>
>> % zmqsend <<<"lumakey@toggle tolerance 0"
>>
>> Regards,
>> Ted Park
>> ________________________________
>> ffmpeg-user mailing list
>> [hidden email]
>> https://ffmpeg.org/mailman/listinfo/ffmpeg-user
>>
>> To unsubscribe, visit link above, or email
>> [hidden email] with subject "unsubscribe".
_______________________________________________
ffmpeg-user mailing list
[hidden email]
https://ffmpeg.org/mailman/listinfo/ffmpeg-user

To unsubscribe, visit link above, or email
[hidden email] with subject "unsubscribe".