Skip to content

Commit

Permalink
record functionality moved to its own repo
Browse files Browse the repository at this point in the history
  • Loading branch information
beasteers committed Sep 17, 2023
1 parent ea777d5 commit a60579e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 323 deletions.
Empty file removed redis_streamer/agents/__init__.py
Empty file.
256 changes: 0 additions & 256 deletions redis_streamer/agents/record.py

This file was deleted.

45 changes: 0 additions & 45 deletions redis_streamer/agents/replay.py

This file was deleted.

42 changes: 20 additions & 22 deletions redis_streamer/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,21 @@ def ls(self, *fields):
}
}''', {'fields': fields})

def record(self, name):
return self.cmd('set', 'RECORD:NAME', name)
# def record(self, name):
# return self.cmd('set', 'RECORD:NAME', name)

def stop_record(self):
return self.cmd('del', 'RECORD:NAME')
# def stop_record(self):
# return self.cmd('del', 'RECORD:NAME')

def xrecord(self, name):
return self.cmd('XADD', 'XRECORD:NAME', "MAXLEN", "~", 100, '*', 'd', '"asdf"')
# def xrecord(self, name):
# return self.cmd('XADD', 'XRECORD:NAME', "MAXLEN", "~", 100, '*', 'd', name)

def stop_xrecord(self):
return self.cmd('XADD', 'XRECORD:NAME', "MAXLEN", "~", 100, '*', 'd', '')
# def stop_xrecord(self):
# return self.cmd('XADD', 'XRECORD:NAME', "MAXLEN", "~", 100, '*', 'd', '')

def cmd(self, *cmd):
print(cmd)#/{shlex.join(map(str, cmd))}
return self.sess.put(self.asurl('cmd'), json={'cmd': cmd}).text
return self.sess.put(self.asurl('redis'), json={'cmd': cmd}).text

def last(self, key):
return self.cmd('xrevrange', key, '+', '-', 'COUNT', '1')
Expand Down Expand Up @@ -109,24 +109,25 @@ async def pull_raw(self, sid, **kw):
# ---------------------------------------------------------------------------- #

@async2sync
async def push_image(self, sid, shape=(100, 100, 3), fps=100, **kw):
async def push_image(self, sid, size=700, shape=None, fps=None, **kw):
# import pyinstrument
# p=pyinstrument.Profiler()
# try:
# with p:
t0 = time.time()

shape = shape or (size, size, 3)
print(f"Pushing image with shape: {shape}")
im = np.random.randint(0, 255, size=shape).astype('uint8')
im = format_image(im)
async with self.push_connect_async(sid, **kw) as ws:
while True:
# im = np.random.randint(0, 255, size=shape).astype('uint8')
im = np.zeros(shape, dtype=np.uint8)
im = format_image(im)
await ws.send_data(im)
# print(im)
# print(len(im))
# print(im[:30], im[-30:])
# print(len(im))
# input()
if fps:
t1 = time.time()
await asyncio.sleep(max(0, 1/fps-(t1 - t0)))
t0 = t1
# finally:
# p.print()

@async2sync
async def pull_image(self, sid, **kw):
Expand All @@ -149,9 +150,6 @@ async def pull_video(self, sid, fps=30, **kw):
header, entries = await ws.recv_data()
entries = unpack_entries(header, entries)
for sid, t, data in entries:
# data = data.decode('unicode_escape').encode()
# data = data.replace(b'\\\\', b'\\')
print(sid, t, len(data))
im = load_image(data)
if s is None:
s = sv.VideoSink(f'{sid}.mp4', video_info=sv.VideoInfo(width=im.shape[1], height=im.shape[0], fps=fps))
Expand Down

0 comments on commit a60579e

Please sign in to comment.