Xilinx / PYNQ

Python Productivity for ZYNQ
http://www.pynq.io/
BSD 3-Clause "New" or "Revised" License
1.99k stars 818 forks source link

Issue with getting real-time video stream into PYNQ via HDMI input cable connected to camera source #1109

Closed Ghazanfar373 closed 3 years ago

Ghazanfar373 commented 4 years ago

Issue with getting real-time video stream into PYNQ via HDMI input cable connected to camera source

I'm successfully done with laptop HDMI input to monitor HDMI out with PYNQ but when i tried to connect camera with HDMI input it didn't work.

I'm using this tutorial provided with Jupyter Docs

To start with download the base overlay and instantate the HDMI input and output.

from pynq.overlays.base import BaseOverlay
from pynq.lib.video import *

base = BaseOverlay("base.bit")
hdmi_in = base.video.hdmi_in
hdmi_out = base.video.hdmi_out 
VicerExciser commented 4 years ago

Well, that's a start. What you'll need to do next is read frames from the hdmi_in and then write them to the hdmi_out. Here's a basic streaming example that should work:

from pynq import Overlay
from pynq.pl import PL
from time import sleep

## Skip redownloading base.bit if already loaded  (did this b/c the overlay download always shuts off my camera input)
base_needs_download = not 'base.bit' in PL.bitfile_name.split('/')
base = Overlay('base.bit', download=base_needs_download)
hdmi_in = base.video.hdmi_in
hdmi_out = base.video.hdmi_out

## Configure & start the HDMI stream
hdmi_in.configure()
hdmi_out.configure(hdmi_in.mode)
hdmi_in.start()
hdmi_out.start()

while True:
    try:
        frame = hdmi_in.readframe()
        hdmi_out.writeframe(frame)
        sleep(0.016)
    except KeyboardInterrupt:
        break

## Stop stream & clean up
hdmi_in.close()
hdmi_out.close()