def __init__(self, local_ip, local_port, imperial=False, command_timeout=.3, tello_ip='192.168.10.1', tello_port=8889, follower=False, name='default-name'): """ Binds to the local IP/port and puts the Tello into command mode. :param local_ip (str): Local IP address to bind. :param local_port (int): Local port to bind. :param imperial (bool): If True, speed is MPH and distance is feet. If False, speed is KPH and distance is meters. :param command_timeout (int|float): Number of seconds to wait for a response to a command. :param tello_ip (str): Tello IP. :param tello_port (int): Tello port. """ self.name = tello_ip self.abort_flag = False self.decoder = libh264decoder.H264Decoder() self.command_timeout = command_timeout self.imperial = imperial self.response = None self.frame = None # numpy array BGR -- current camera output frame self.is_freeze = False # freeze current camera output self.last_frame = None self.socket = socket.socket( socket.AF_INET, socket.SOCK_DGRAM) # socket for sending cmd self.socket_video = socket.socket( socket.AF_INET, socket.SOCK_DGRAM) # socket for receiving video stream self.tello_address = (tello_ip, tello_port) self.local_video_port = 11111 # port for receiving video stream self.last_height = 0 self.socket.bind((local_ip, local_port)) print(self.tello_address) # thread for receiving cmd ack self.receive_thread = threading.Thread(target=self._receive_thread) self.receive_thread.daemon = True self.receive_thread.start() if not follower: # to receive video -- send cmd: command, streamon self.socket.sendto(b'command', self.tello_address) print('sent: command') self.socket.sendto(b'streamon', self.tello_address) print('sent: streamon') self.socket_video.bind((local_ip, self.local_video_port)) # thread for receiving video self.receive_video_thread = threading.Thread( target=self._receive_video_thread) self.receive_video_thread.daemon = True self.receive_video_thread.start()
frame = frame[:, :w, :] if not img: img = ax.imshow(frame) pyplot.show(block=False) else: img.set_data(frame) pyplot.draw() pyplot.pause(0.001) def run_decode_frame(decoder, data_in): while len(data_in): framedata, nread = decoder.decode_frame(data_in) data_in = data_in[nread:] display(framedata) def run_decode(decoder, data_in): framedatas = decoder.decode(data_in) for framedata in framedatas: display(framedata) decoder = libh264decoder.H264Decoder() with open('testclip.h264', 'rb') as f: while 1: data_in = f.read(1024) if not data_in: break run_decode(decoder, data_in)
def __str__(self): return f'{self.__class__.__name__} : {self.msg}' def __repr__(self): return self.__str__() # By default use compiled library else py-av try: import libh264decoder print('You have compiled the h264 library') except (ModuleNotFoundError, ImportError): LIB_AVAILABLE = False else: # Runtime optimisation variables DECODER = libh264decoder.H264Decoder() LIB_AVAILABLE = True try: import av print('You have access to py-av library') except (ModuleNotFoundError, ImportError): AV_AVAILABLE = False else: AV_AVAILABLE = True NO_VIDEO_DECODER = not LIB_AVAILABLE and not AV_AVAILABLE class AbstractDrone(ABC): """
def _h264_decode(self, packet_data): self.decoder = libh264decoder.H264Decoder() return self.decoder.decode(packet_data)