diff --git a/README.md b/README.md index 3817b740..dcc5d263 100644 --- a/README.md +++ b/README.md @@ -31,9 +31,22 @@ Help on package tellopy: ``` ## Examples - You can find basic usage of this package in example code in the examples folder. +### Mplayer +The video examples assume that you have mplayer installed and configured in your path. + +#### Windows +Download Mplayer for Windows from [SourceForge](https://sourceforge.net/projects/mplayerwin/files/MPlayer-MEncoder/r38151/mplayer-svn-38151-x86_64.7z/download). + +Unzip the file via [7zip](https://www.7-zip.org/), and add the extracted folder to your PATH (see [here for env help](https://www.architectryan.com/2018/03/17/add-to-the-path-on-windows-10/)). + +#### Linux +`$ sudo apt install mplayer mplayer-gui` + +#### Mac +`$ brew install mplayer` + ### simple_takeoff This example let Tello take off. Tello will land automatically after a few seconds. @@ -41,6 +54,16 @@ This example let Tello take off. Tello will land automatically after a few secon $ python -m tellopy.examples.simple_takeoff ``` +### keyboard_and_video +Display the realtime video stream from Tello. +``` +$ pip install av +$ pip install opencv-python +$ pip install image +$ pip install pygame +$ python -m tellopy.examples.keyboard_and_video +``` + ### video_effect Filter and display the realtime video stream from Tello. ``` diff --git a/tellopy/examples/keyboard_and_video.py b/tellopy/examples/keyboard_and_video.py index 7e12f5e3..20124a9f 100755 --- a/tellopy/examples/keyboard_and_video.py +++ b/tellopy/examples/keyboard_and_video.py @@ -19,7 +19,6 @@ """ import time -import sys import tellopy import pygame import pygame.display @@ -29,9 +28,7 @@ import os import datetime from subprocess import Popen, PIPE -# from tellopy import logger -# log = tellopy.logger.Logger('TelloUI') prev_flight_data = None video_player = None @@ -40,6 +37,13 @@ wid = None date_fmt = '%Y-%m-%d_%H%M%S' + +def get_file_path(file): + if system() == 'Windows': + return os.path.join(os.environ['USERPROFILE'] + "\\Pictures", file) + else: + return os.path.join(os.environ['HOME'] + "/Pictures", file) + def toggle_recording(drone, speed): global video_recorder global date_fmt @@ -54,8 +58,9 @@ def toggle_recording(drone, speed): return # start a new recording - filename = '%s/Pictures/tello-%s.mp4' % (os.getenv('HOME'), - datetime.datetime.now().strftime(date_fmt)) + filename = 'tello-{}.mp4'.format (datetime.datetime.now().strftime(date_fmt)) + filename = get_file_path(filename) + video_recorder = Popen([ 'mencoder', '-', '-vc', 'x264', '-fps', '30', '-ovc', 'copy', '-of', 'lavf', '-lavfopts', 'format=mp4', @@ -206,9 +211,9 @@ def videoFrameHandler(event, sender, data): def handleFileReceived(event, sender, data): global date_fmt # Create a file in ~/Pictures/ to receive image data from the drone. - path = '%s/Pictures/tello-%s.jpeg' % ( - os.getenv('HOME'), - datetime.datetime.now().strftime('%Y-%m-%d_%H%M%S')) + file = 'tello-{}.jpeg'.format(datetime.datetime.now().strftime('%Y-%m-%d_%H%M%S')) + + path = get_file_path(file) with open(path, 'wb') as fd: fd.write(data) status_print('Saved photo to %s' % path)