Created
July 3, 2019 16:30
-
-
Save dasl-/043f329302783595e107fdb6ec51acfb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import argparse | |
from lightness.settings import Settings | |
from lightness.videoplayer import VideoPlayer | |
from lightness.videoprocessor import VideoProcessor | |
import numpy as np | |
import cv2 | |
import time | |
import io | |
import datetime | |
import subprocess | |
from picamera.array import PiRGBArray | |
from picamera import PiCamera | |
def parseArgs(): | |
parser = argparse.ArgumentParser(description='convert a video.') | |
parser.add_argument('--url', dest='url', action='store', default='https://www.youtube.com/watch?v=xmUZ6nCFNoU', | |
help='youtube video url. default: The Smashing Pumpkins - Today.') | |
parser.add_argument('--display-width', dest='display_width', action='store', type=int, default=28, metavar='N', | |
help='Number of pixels / units') | |
parser.add_argument('--display-height', dest='display_height', action='store', type=int, default=18, metavar='N', | |
help='Number of pixels / units') | |
parser.add_argument('--color', dest='is_color', action='store_true', default=False, | |
help='color output? (default is black and white)') | |
parser.add_argument('--flip-x', dest='flip_x', action='store_true', default=False, | |
help='flip X direction output') | |
parser.add_argument('--flip-y', dest='flip_y', action='store_true', default=False, | |
help='flip Y direction output') | |
parser.add_argument('--brightness', dest='brightness', action='store', type=int, default=3, metavar='N', | |
help='Global brightness value. Max of 31.') | |
args = parser.parse_args() | |
return args | |
args = parseArgs() | |
video_settings = Settings(args) | |
video_player = VideoPlayer(video_settings) | |
video_player.clearScreen() | |
video_processor = VideoProcessor(video_settings, None) | |
pix_fmt = 'gray' | |
if args.is_color: | |
pix_fmt = 'rgb24' | |
# start the ffmpeg process with a pipe for stdin | |
# I'm just copying to a file, but you could stream to somewhere else | |
ffmpeg = subprocess.Popen([ | |
'ffmpeg', '-i', '-', | |
# '-vcodec', 'copy', | |
# '-an', '/home/pi/test.mpg', | |
'-filter:v', 'scale=28x18', | |
'-c:a', 'copy', # don't process the audio at all | |
'-f', 'rawvideo', '-pix_fmt', pix_fmt, # output in numpy compatible byte format | |
'pipe:1' # output to stdout | |
], stdin=subprocess.PIPE)#, stdout=subprocess.PIPE | |
# ffmpeg_proc = subprocess.Popen( | |
# ( | |
# 'ffmpeg', | |
# '-threads', '1', # using one thread is plenty fast and is probably better to avoid tying up CPUs for displaying LEDs | |
# '-i', video_path, | |
# '-filter:v', 'scale=' + str(self.__video_settings.display_width) + 'x' + str(self.__video_settings.display_height), | |
# '-c:a', 'copy', # don't process the audio at all | |
# '-f', 'rawvideo', '-pix_fmt', pix_fmt, # output in numpy compatible byte format | |
# 'pipe:1' # output to stdout | |
# ), | |
# stdout=subprocess.PIPE | |
# ) | |
# initialize the camera | |
camera = PiCamera(resolution=(80, 60), framerate=25) | |
# start recording to ffmpeg's stdin | |
camera.start_recording(ffmpeg.stdin, format='h264', bitrate=2000000) | |
# while True: | |
# in_bytes = ffmpeg_proc.stdout.read(bytes_per_frame) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment