Many times, I get bored of watching YouTube videos in HD on my monitor or TV, especially because they tend to not be very crisp. So I set out to create a way to view videos with amazing clarity. For that, I would need a Raspberry Pi 3 and a 64x64 RGB LED matrix.
The most important library is the rgb-led-matrix, which controls the pins for the matrix. Just follow Adafruit's instructions here: https://learn.adafruit.com/adafruit-rgb-matrix-plus-real-time-clock-hat-for-raspberry-pi. Then I installed OpenCV with
sudo apt-get update
sudo apt-get install libopencv-dev python-opencv
Then I needed a way to get the youtube videos to display. I found a library called pafy, which handles that. I installed it with the following commands:
sudo python -m pip install youtube_dl
sudo python -m pip install pafy
Now that the necessary libraries were installed, I began to code.
CodeThe program for this project goes through these steps:
- Import libraries
- Download video and convert it
- Set up RGB matrix
- Create OpenCV video capture
- Loop through each frame of the video while converting it and sending it to the matrix
I set up the program to take a command line argument for the URL. Pafy then downloads the video and stores it. I configured the matrix to be 64 x 64 and have the 'adafruit-hat' mapping. Next, in order for OpenCV to get the frames of the video, I had to create a VideoCapture and pass in the video object. Lastly, the rpi-rgb-led-matrix library uses PIL to draw images to the matrix, so I converted the OpenCV image objects to PIL image objects with
display_img = Image.fromarray(image_resized)
The program keeps displaying the frames until the video is over or the program is halted.
ViewingTo start viewing the amazing videos, simply type
sudo python low_res_yt.py <youtube_video_url>
and then enjoy the stunning quality!
Comments