how to use jetson nano hardware acceleration to play youtube videos

Unfortunately for me I’m getting quite skilled using python and gstreamer (2 things that I hate).

So here you can find a simple solution:

  1. Install required packages:
sudo pip install pafy
sudo pip install --upgrade youtube_dl
  1. create a python file called “youtube.py” with this content:
import pafy
import os

url = 'https://youtu.be/Bey4XXJAqS8' # youtube url to play
vPafy = pafy.new(url)
play = vPafy.getbestvideo()

monitor_width = 1366 # target monitor width
monitor_height = 768 # target monitor height

command = 'gst-launch-1.0 souphttpsrc location="'+ str(play.url) +'" ! matroskademux ! queue ! nvv4l2decoder ! nvvidconv ! "video/x-raw(memory:NVMM), width=(int)'+ str(monitor_width) +', height=(int)'+ str(monitor_height) +'" ! nvdrmvideosink -e'
pipe = os.popen(command)
  1. edit youtube.py to your needs
  2. run script using:
python youtube.py