Hi Everyone,
I hope you are well
I have this issue with audio tracks in which some of the audio frames/packets are missing and not sent to the user or encoder.
More details in GitHub issue:
Any help is appreciated
from av import VideoFrame
from aiortc.contrib.media import MediaRecorder
from aiortc.mediastreams import AudioStreamTrack, VideoStreamTrack
import av
import numpy as np
import asyncio
def run(coro):
return asyncio.get_event_loop().run_until_complete(coro)
class RTCServer(VideoStreamTrack):
def __init__(self,):
super().__init__()
self.image = np.random.randint(
0, 255, (640, 360, 3),
dtype='uint8')
async def recv(self):
pts, time_base = await self.next_timestamp()
image = np.random.randint(
0, 255, (640, 360, 3),
dtype='uint8')
av_frame = VideoFrame.from_ndarray(image)
av_frame.pts = pts
av_frame.time_base = time_base
return self.frame
def terminate(self):
try:
if not (self.stream is None):
self.stream.release()
self.stream = None
except AttributeError:
pass
rtc_video = RTCServer()
url_youtube = 'rtmp://a.rtmp.youtube.com/live2/'
url_youtube += 'SECRETE-KEY'
recorder = MediaRecorder(url_youtube, format='flv')
recorder.addTrack(rtc_video)
recorder.addTrack(AudioStreamTrack())
run(recorder.start())
run(asyncio.sleep(2))
run(recorder.stop())
I would like to be able to separate the datachannels using decorators like
@pc.on('pingchannelmessage')
def ping_channel(message):
#do something
@pc.on('tempchannelmessage')
def temp_channel(message):
#do something
Currently I do this:
@pc.on("datachannel")
def on_datachannel(channel):
@channel.on("message")
def on_message(message):
print(f"Message is {message}")
if isinstance(message, str) and message.startswith("ping"):
#Do something
if isinstance(message, str) and message.startswith("Temp"):
#Do something
async def on_track(track): ?? what to do here ???