def thread_function():
        ds = DataStore.getInstance()
        tos = TwitchBufferedOutputStream(
            twitch_stream_key=os.environ['TWITCH_SECRET'],
            width=1280,
            height=720,
            fps=30,
            verbose=True)
        camera = picamera.PiCamera(1280, 720, framerate=24)
        camera.start_preview()
        camera.annotate_background = picamera.Color('black')
        camera.annotate_text = "Current orientation: " + ds.getOrientation()
        sleep(2)
        now = datetime.now()
        # Begine recording the video
        camera.start_recording('launches/launch-' +
                               now.strftime("%m-%d-%H-%M-%S") + '.h264')

        while True:
            # Get current frame
            camera.annotate_text = "Current orientation: " + ds.getOrientation(
            )
            frame = camera.frame
            tos.send_video_frame(frame)
            time.sleep(1 / 30)
Exemplo n.º 2
0
async def loop_send_frame(streamkey, resolution, L):
    # load two streams:
     # * one stream to send the video
    with TwitchBufferedOutputStream(
            twitch_stream_key=streamkey,
            width=resolution[0],
            height=resolution[1],
            fps=30.,
            enable_audio=False,
            verbose=False) as videostream:
        try:
                    # The main loop to create videos
            while True:
                # If there are not enough video frames left,
                # add some more.
                print(f'Sending frame... {L.qsize()}')
                frame = await L.get()
                if frame.size > 0:
                    videostream.send_video_frame(frame)
                L.task_done()


        except Exception as e:
            raise e
Exemplo n.º 3
0
        cv2.putText(frame, text, (10, H - ((i * 20) + 20)),
                    cv2.FONT_HERSHEY_SIMPLEX, 0.6, (0, 0, 255), 2)

    # check to see if we should write the frame to disk
    if writer is not None:
        writer.write(frame)
#     sys.stdout.write( f"{frame}" )

# Send frames to twitch
    if stream is None:
        print(frame.shape)
        (streamH, streamW) = frame.shape[:2]
        stream = TwitchBufferedOutputStream(
            twitch_stream_key=args["streamkey"],
            width=streamW,
            height=streamH,
            fps=45.,
            enable_audio=False,
            verbose=False)
        print(stream.height, stream.width, "3")

    if stream.get_video_frame_buffer_state() < 15:
        norm_image = cv2.cvtColor(frame, cv2.COLOR_RGB2BGR)
        norm_image = cv2.normalize(norm_image,
                                   None,
                                   alpha=0,
                                   beta=1,
                                   norm_type=cv2.NORM_MINMAX,
                                   dtype=cv2.CV_32F)
        stream.send_video_frame(norm_image)
#         sys.stdout.write( f"{norm_image}" )
Exemplo n.º 4
0
from twitchstream.outputvideo import TwitchBufferedOutputStream
import argparse
import numpy as np

if __name__ == "__main__":
    parser = argparse.ArgumentParser(description=__doc__)
    required = parser.add_argument_group('required arguments')
    required.add_argument('-s',
                          '--streamkey',
                          help='twitch streamkey',
                          required=True)
    args = parser.parse_args()

    with TwitchBufferedOutputStream(twitch_stream_key=args.streamkey,
                                    width=640,
                                    height=480,
                                    fps=30.,
                                    verbose=True,
                                    audio_enabled=True) as videostream:

        frame = np.zeros((480, 640, 3))

        while True:
            if videostream.get_video_frame_buffer_state() < 30:
                frame = np.random.rand(480, 640, 3)
                videostream.send_video_frame(frame)

            if videostream.get_audio_buffer_state() < 30:
                left_audio = np.random.randn(1470)
                right_audio = np.random.randn(1470)
                videostream.send_audio(left_audio, right_audio)
Exemplo n.º 5
0
def loop_send_frame(streamkey, resolution, stream, pose_processor):

    width, height = resolution
    try:
        # config = tf.ConfigProto()
        # config.intra_op_parallelism_threads = 4
        # config.inter_op_parallelism_threads = 4
        with TwitchBufferedOutputStream(twitch_stream_key=streamkey,
                                        width=width,
                                        height=height,
                                        fps=30.,
                                        enable_audio=False,
                                        verbose=True) as videostream:
            # with tf.Session(config=config) as sess:
            # 	model_cfg, model_outputs = posenet.load_model(3, sess)

            # 	frame = tf.placeholder(tf.uint8, shape=(height, width, 3))
            # 	input_image = tf.placeholder(tf.uint8, shape=(1, height + 1, width + 1, 3))

            # 	while True:
            # 		frame = get_frame_from_stream(resolution, stream)
            # 		if frame is not None:
            # 			start = time.time()
            # 			output_stride = model_cfg['output_stride']

            # 			input_image, frame, output_scale = posenet.process_input(
            # 					frame, output_stride=output_stride)
            # 			heatmaps_result, offsets_result, displacement_fwd_result, displacement_bwd_result = sess.run(
            # 				model_outputs,
            # 				feed_dict={'image:0': input_image}
            # 			)
            # 			pose_scores, keypoint_scores, keypoint_coords = posenet.decode_multiple_poses(
            # 				heatmaps_result.squeeze(axis=0),
            # 				offsets_result.squeeze(axis=0),
            # 				displacement_fwd_result.squeeze(axis=0),
            # 				displacement_bwd_result.squeeze(axis=0),
            # 				output_stride=output_stride,
            # 				max_pose_detections=1, min_pose_score=0.10)

            # 			keypoint_coords *= output_scale

            # 			frame = posenet.draw_skel_and_kp(
            # 					frame, pose_scores, keypoint_scores, keypoint_coords,
            # 					min_pose_score=0.10, min_part_score=0.10)
            # 			videostream.send_video_frame(frame)
            # 			print(time.time() - start)
            model = posenet.load_model(101)
            model = model.cuda()
            output_stride = model.output_stride

            while True:
                frame = get_frame_from_stream(resolution, stream)
                input_image, frame, output_scale = posenet.process_input(
                    frame, output_stride=output_stride)

                with torch.no_grad():
                    input_image = torch.Tensor(input_image).cuda()

                    heatmaps_result, offsets_result, displacement_fwd_result, displacement_bwd_result = model(
                        input_image)

                    pose_scores, keypoint_scores, keypoint_coords = posenet.decode_multiple_poses(
                        heatmaps_result.squeeze(0),
                        offsets_result.squeeze(0),
                        displacement_fwd_result.squeeze(0),
                        displacement_bwd_result.squeeze(0),
                        output_stride=output_stride,
                        max_pose_detections=1,
                        min_pose_score=0.1)

                keypoint_coords *= output_scale

                # TODO this isn't particularly fast, use GL for drawing and display someday...
                frame = 255 - posenet.draw_skel_and_kp(frame,
                                                       pose_scores,
                                                       keypoint_scores,
                                                       keypoint_coords,
                                                       min_pose_score=0.1,
                                                       min_part_score=0.1)
                videostream.send_video_frame(frame)
                # save_image(frame)

    except Exception as e:
        raise
Exemplo n.º 6
0
                          '(visit https://twitchapps.com/tmi/ '
                          'to create one for your account)',
                          required=True)
    required.add_argument('-s',
                          '--streamkey',
                          help='twitch streamkey',
                          required=True)
    args = parser.parse_args()

    # load two streams:
    # * one stream to send the video
    # * one stream to interact with the chat
    with TwitchBufferedOutputStream(
            twitch_stream_key=args.streamkey,
            width=640,
            height=480,
            fps=30.,
            enable_audio=True,
            verbose=False) as videostream, \
        TwitchChatStream(
            username=args.username,
            oauth=args.oauth,
            verbose=False) as chatstream:

        # Send a chat message to let everybody know you've arrived
        chatstream.send_chat_message("Taking requests!")

        frame = np.zeros((480, 640, 3))
        frequency = 100
        last_phase = 0
Exemplo n.º 7
0
import os, sys, subprocess
import numpy as np
import gym
import asteroid
import random

from twitchstream.outputvideo import TwitchBufferedOutputStream
from twitchstream.chat import TwitchChatStream

TWITCH_KEY = "live_86944108_XVDMuEvn7AFBEOLuvNeiyCSE4VX4bY"
OAUTH_KEY = "oauth:y56mfwbmq724genm9bchxqi11u5iac"

#env = gym.make("asteroid-v1")
#env._configure("ec2-34-249-73-16.eu-west-1.compute.amazonaws.com", "")

videostream = TwitchBufferedOutputStream(twitch_stream_key=TWITCH_KEY, width=1238, height=822)
#chat = TwitchChatStream(username='******', oauth=OAUTH_KEY)

while True:
    if videostream.get_video_frame_buffer_state() < 30:
        videostream.send_video_frame(np.ones((822, 1238, 3)))


Exemplo n.º 8
0
    if legit_command:
        game.paint()

        print("user: '******' - command: %s" % (message['username'], command))


if __name__ == "__main__":
    game = Game()
    game.reset()

    # load two streams, one for video one for chat
    with TwitchBufferedOutputStream(
      twitch_stream_key=streaminfo.STREAMKEY,
      width=640,
      height=480,
      fps=30.,
      enable_audio=False,
      verbose=False) as videostream, \
      TwitchChatStream(
       username=streaminfo.USERNAME,
       oauth=streaminfo.OAUTH,
       verbose=False) as chatstream:

        chatstream.send_chat_message('connecting to chat...')
        print('connected to chat...')

        # main loop
        while True:
            # Every loop, call to receive messages.
            # This is important, when it is not called,