1

I am trying to write an incoming webrtc stream to a filesink using webrtcbin and filesink. If i write the file directly as soon as stream comes it produced file is playable but when i dynamically start and stop recording it is showing "unreadable stream type" error while playing.

My original pipeline:

 webrtcbin name=sendrecv bundle-policy=max-bundle turn-server=turn://username:password@localhost:4001
 videotestsrc is-live=true pattern=ball ! videoconvert ! queue ! vp8enc deadline=1 ! rtpvp8pay !
 queue ! application/x-rtp,media=video,encoding-name=VP8,payload=97 ! sendrecv.
 audiotestsrc is-live=true wave=red-noise ! audioconvert ! audioresample ! queue ! opusenc ! rtpopuspay !
 queue ! application/x-rtp,media=audio,encoding-name=OPUS,payload=96 ! sendrecv.

When stream comes in:

if name.startswith('video'):
            print('video track')
            q = Gst.ElementFactory.make('queue')
            conv = Gst.ElementFactory.make('videoconvert')
            fileQueue = Gst.ElementFactory.make('queue')
            encoder = Gst.ElementFactory.make('vp8enc')
            self.pipe.add(q)
            self.pipe.add(conv)
            self.pipe.add(fileQueue)
            self.pipe.add(encoder)
            self.initialize_muxer()
            self.pipe.sync_children_states()
            pad.link(q.get_static_pad('sink'))
            q.link(conv)
            conv.link(fileQueue)
            fileQueue.link(encoder)
            encoder.link(self.muxer)
        elif name.startswith('audio'):
            print('audio track')
            q = Gst.ElementFactory.make('queue')
            progress = Gst.ElementFactory.make('progressreport')
            conv = Gst.ElementFactory.make('audioconvert')
            resample = Gst.ElementFactory.make('audioresample')
            fileQueue = Gst.ElementFactory.make('queue')
            enc = Gst.ElementFactory.make('opusenc')
            self.pipe.add(q)
            self.pipe.add(progress)
            self.pipe.add(conv)
            self.pipe.add(resample)
            self.pipe.add(fileQueue)
            self.pipe.add(enc)
            self.initialize_muxer()
            self.pipe.sync_children_states()
            pad.link(q.get_static_pad('sink'))
            q.link(progress)
            progress.link(conv)
            conv.link(resample)
            resample.link(fileQueue)
            fileQueue.link(enc)
            enc.link(self.muxer)

def initialize_muxer(self):
    if(self.muxer is None):
        self.muxer = Gst.ElementFactory.make('webmmux')
        queue = Gst.ElementFactory.make('queue')
        self.tee = Gst.ElementFactory.make('tee')
        fakesink = Gst.ElementFactory.make('fakesink')

        self.pipe.add(self.muxer)
        self.pipe.add(queue)
        self.pipe.add(self.tee)
        self.pipe.add(fakesink)

        self.muxer.link(queue)
        queue.link(self.tee)
        self.tee.link(fakesink)

On start recording i add a filesink to muxer and set it to play

def start_recording(self, archiveId):
    if(self.filesink is None):
        queue = Gst.ElementFactory.make('queue')
        self.filesink = Gst.ElementFactory.make('filesink')

        archiveDir = str(Path.home()) + '/.gliderMediaArchives/'
        Path(archiveDir).mkdir(parents=True, exist_ok=True)
        file_name = archiveDir + archiveId + '.webm'
        print(archiveDir, file_name)
        self.filesink.set_property('location', file_name)

        self.pipe.add(queue)
        self.pipe.add(self.filesink)
        self.tee.link(queue)
        queue.link(self.filesink)
        queue.sync_state_with_parent()
        self.filesink.sync_state_with_parent()
    print("Archiving started for " + archiveId)

0 Answers0