-
Notifications
You must be signed in to change notification settings - Fork 0
/
dummy_streams.py
50 lines (44 loc) · 1.41 KB
/
dummy_streams.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python3
import av
import numpy as np
import cv2
import asyncio
from aiortc import VideoStreamTrack
from aiortc.mediastreams import AudioStreamTrack
class DummyVideoStreamTrack(VideoStreamTrack):
async def recv(self):
pts, time_base = await self.next_timestamp()
frame = None
while frame is None:
numpy_frame = np.zeros((480, 640, 3), dtype=np.uint8)
cv2.putText(numpy_frame, "hello", (200, 240), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 2)
frame = av.VideoFrame.from_ndarray(numpy_frame, format="bgr24")
frame.pts = pts
frame.time_base = time_base
return frame
class DummyAudioStreamTrack(AudioStreamTrack):
pass
if __name__ == "__main__":
from time import time_ns
import sys
async def test():
frame_count=0
start_time=time_ns()
track = DummyVideoStreamTrack()
while True:
await track.recv()
now = time_ns()
playtime = now - start_time
playtime_sec = playtime * 0.000000001
if playtime_sec >= 1:
print(f'fps: {frame_count}')
frame_count = 0
start_time = time_ns()
else:
frame_count+=1
# Run event loop
loop = asyncio.new_event_loop()
try:
loop.run_until_complete(test())
except KeyboardInterrupt:
sys.exit(0)