Unable to switch between streams using input-selector

Marianna Smidth Buschle msb at qtec.com
Tue Apr 19 07:13:52 UTC 2022


I have also done something similar, so here is some example code of how 
to handle the switch on key-frame only.

def got_buff (self, pad, info, new_pad):
buf = info.get_buffer()

print("Waiting for Key-frame in pad '{}'...".format(new_pad))

if buf.has_flags(Gst.BufferFlags.DELTA_UNIT) is False:
print("Key-frame received in pad '{}'".format(new_pad))

self.selector.set_property("listen-to", new_pad)

return Gst.PadProbeReturn.REMOVE
else:
return Gst.PadProbeReturn.OK

def check_kf(self, new_pad, sink):
current_pad = self.selector.get_property("listen-to")
if current_pad == new_pad:
print("Pad already selected")
return True

#add pad probe
pad = sink.get_static_pad("sink")
pad.add_probe(Gst.PadProbeType.BUFFER, self.got_buff, new_pad)

return True

def set_output(self, index=0, new_pad=None):
self.selector = None
selector_pipe = None
for pipe in self.pipeline:
self.selector = pipe.get_by_name("vselect")
if self.selector:
selector_pipe = pipe
break
if not self.selector:
print("Couldn't find input-selector named 'vselect'")
return False

i=0
found = False
for pipe in self.pipeline:
sink = pipe.get_by_name(new_pad)
if sink:
break
i=i+1
if not sink:
print("Couldn't find new_pad named " + new_pad)
return False

#selector.set_property("listen-to", new_pad)
self.check_kf(new_pad, sink)
return True

Note that I use 'interpipesrc/sink' instead of 'inputselector', but the 
principle is the same.

On 14.04.2022 14.00, gstreamer-devel-request at lists.freedesktop.org wrote:
>> I'm trying to switch between two streams and publish it to a RTMP server using input-selector as follows:
>>
> I am assuming that the stream works if you do not switch at runtime?
> It's not so simple to switch between two h264 streams like this. You
> need to account for the following:
>
> 1. Video frames can only be decoded with a reference frame, so you can
> only switch streams on a keyframe.
> 2. Both streams must have the same characteristics (resolution,
> framerate, level, profile, etc), or downstream must be able to
> renegotiate
> 3. If reneg is needed, then you must resend the SPS/PPS with every
> switch (config-interval=-1 on h264parse should do that for you)
> 4. If reneg is needed, some endpoints may only be able to handle a
> subset of stream characteristics changes dynamically
>
> (1) and (3) are probably what you are missing here.
>
> Cheers,
> Nirbheek

-- 
Best regards / Med venlig hilsen
“Marianna Smidth Buschle”
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/gstreamer-devel/attachments/20220419/d2748bf6/attachment-0001.htm>


More information about the gstreamer-devel mailing list