Воспроизведение видео из данных в реальном времени? Python - PullRequest
1 голос
/ 28 мая 2020

Я постараюсь сохранить как можно более базовое c ... Это компьютерный проект, над которым я работаю для развлечения. Я сделал код, который считывает аналоговый видеосигнал низкого качества через порт аудиовхода и dr aws последовательность изображений. Мне нужен способ отображения изображений в том виде, в каком они нарисованы, чтобы иметь возможность воспроизводить видео.

Вот что у меня есть на данный момент.

import time
import threading
import pyaudio
import numpy as np
from PIL import Image


peaksens = 2000
hipeaksens = 1000
divid = 100
CHUNK = 4096 # number of data points to read at a time
RATE = 48000

q = input("Standard Quality = sq Low Quality = lq >> ")
if q == 'sq':
    RATE = 96000
    CHUNK = 2048
elif q == 'lq':
    RATE = 48000
    CHUNK = 1024
else:
    while q != 'sq' and q != 'lq':
        print("INVALID!")
        q = input("Standard Quality = sq Low Quality = lq >> ")
    else:
        if q == 'sq':
            RATE = 96000
            CHUNK = 2048
        elif q == 'lq':
            RATE = 48000
            CHUNK = 1024

def sq(data, x, y):
    peak = max(data) - hipeaksens
    hi = peak - peaksens
    lo = min(data) + peaksens
    for d in data:
        if d > peak:
            y = 0
            x = 0
        elif d > hi and d < peak:
            y = 2
            x = 0
        elif d < lo:
            x = 0
            y += 4
        else:
            x += 1
        if x > 127:
            x = 0
        if y > 99:
            y = 0
        pix = d / 100
        pix = pix + 128
        pix = int(float(np.clip(pix, 0, 256)))
        img.putpixel((x, y), pix)
        img.putpixel((x, y + 1), pix)

def lq(data, x, y):
    peak = max(data) - hipeaksens
    hi = peak - peaksens
    lo = min(data) + peaksens
    for d in data:
        if d > peak:
            y = 0
            x = 0
        elif d > hi and d < peak:
            y = 2
            x = 0
        elif d < lo:
            x = 0
            y += 4
        else:
            x += 2
        if x > 127:
            x = 0
        if y > 99:
            y = 0
        pix = d / 100
        pix = pix + 128
        pix = int(float(np.clip(pix, 0, 256)))
        img.putpixel((x, y), pix)
        img.putpixel((x, y + 1), pix)
        img.putpixel((x+1, y), pix)
        img.putpixel((x+1, y + 1), pix)

# set global variable flag
flag = 1
p=pyaudio.PyAudio() # start the PyAudio class
stream=p.open(format=pyaudio.paInt16,channels=1,rate=RATE,input=True,
              frames_per_buffer=CHUNK) #uses default input device
img = Image.new('L', (128, 100), color=128)
def normal():
    x = 0
    y = 0
    global flag
    while flag==1:
        data = np.frombuffer(stream.read(CHUNK, exception_on_overflow = False), dtype=np.int16)
        if q == 'sq':
            sq(data, x, y)
        else:
            lq(data, x, y)
        if flag==False:
            print('Closed')
            img.show()
            img.close()
            stream.stop_stream()
            stream.close()
            p.terminate()


def get_input():
    global flag
    keystrk=input('Press Return to exit. \n')
    time.sleep(2)
    # thread doesn't continue until key is pressed
    flag=False

n=threading.Thread(target=normal)
i=threading.Thread(target=get_input)
n.start()
i.start()

На данный момент этот код dr aws кадров, но не отображает их (если вы не остановите код).

Характеристики видео, если необходимо: (30 кадров в секунду с чересстрочной разверткой) (черно-белое) (50 строк развертки по вертикали) (128 пикселей по горизонтали)

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...