示例#1
0
    def start_capture(
            self,
            cam: Camera,
            trigger: RecordingTrigger,
            with_buffer: bool = False) -> Tuple[VideoWriter, Disposable]:
        print("starting capture of " + cam.name)
        if cam.id in self.__recording:
            return

        buffer = self.__frameserver.get_buffer(cam.id)
        writer = VideoWriter(self.__generate_name(cam, trigger))
        writer.open()
        if with_buffer:
            writer.write_packets(buffer.get_packets())
        subscription = buffer.get_observable().subscribe(
            on_next=lambda p: writer.write_packet(p))
        self.__recording[cam.id] = ActiveRecording(writer, subscription,
                                                   datetime.now())
示例#2
0
async def save(request):
    buffer = frameserver.get_buffer("test")
    writer = VideoWriter("/home/hannes/Projekte/studienarbeit/test/out.mp4")
    writer.open()
    writer.write_packets(buffer.get_packets())
    subscription = buffer.get_observable().subscribe(
        on_next=lambda p: writer.write_packet(p))
    await asyncio.sleep(10)
    subscription.dispose()
    writer.close()

    last = buffer.get_packets()[-1]
    if (last == None):
        return web.Response(content_type="text/html", text="No Frame")
    output = io.BytesIO()
    frame = last.decode()[0].to_image()
    frame.save(output, format='PNG')
    output.seek(0)
    output_s = output.read()
    b64 = b64encode(output_s)
    return web.Response(content_type="text/html",
                        text="<img src='data:image/png;base64," +
                        str(b64)[2:-1] + "'>")