Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flow control #16

Merged
merged 2 commits into from
Oct 9, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 32 additions & 8 deletions generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import numpy as np

class AMP():
def __init__(self, chars_id=3, rLH=159, rUH=14, gLH=36, gUH=80, bLH=104, bUH=138):
def __init__(self, chars_id=0, rLH=159, rUH=14, gLH=36, gUH=80, bLH=104, bUH=138):
ASCII_CHAR_ARRAY = (" .:-=+*#%@", " .,:ilwW", " ▏▁░▂▖▃▍▐▒▀▞▚▌▅▆▊▓▇▉█", " `^|1aUBN", " .`!?xyWN")

self.ASCII_CHARS = ASCII_CHAR_ARRAY[chars_id]
Expand All @@ -29,6 +29,9 @@ def __init__(self, chars_id=3, rLH=159, rUH=14, gLH=36, gUH=80, bLH=104, bUH=138
self.bLowerHue = bLH
self.bUpperHue = bUH

self.SPACEBAR_KEY = (32,)
self.QUIT_KEYS = (113,81)


def vid_render(self, pixels, coloring = True):
"""Function to merge and render the ASCII output to the terminal.
Expand All @@ -53,9 +56,11 @@ def vid_render(self, pixels, coloring = True):

def subtitle_show(self, subs, tstamp_ms):
"""Function to get subtitles of current frame and display them"""
self.captions.clear()
self.captions.border(' ', ' ', 0, 0, ' ', ' ', ' ', ' ')
parts = subs.slice(starts_before={'milliseconds': int(tstamp_ms)}, ends_after={'milliseconds': int(tstamp_ms)})
if parts:
self.captions.clear()
self.captions.border(' ', ' ', 0, 0, ' ', ' ', ' ', ' ')

self.captions.addstr(0, 1, "Captions")
self.captions.move(1, 0)
for part in parts:
Expand All @@ -78,8 +83,6 @@ def get_pixel_matrix(self, image):
# set image to determined d1 and column size
im = image.resize((d1, d2))
pixels = np.reshape(im.getdata(), (d2, d1, 3))
with open('error.txt', 'a') as f:
print(pixels.shape, file=f)
return pixels


Expand Down Expand Up @@ -138,10 +141,27 @@ def read_media_sub(self, vidfile, coloring, subfile=''):
vidcap = cv2.VideoCapture(vidfile)
if subfile: subs = pysrt.open(subfile,encoding='latin-1')
fps = vidcap.get(cv2.CAP_PROP_FPS)

self.media.nodelay(True)

user_input = curses.ERR

while vidcap.isOpened():
# read frames from the image
# Read frames from the image
success, image = vidcap.read()
if not success: break

# Check for user input
user_input = self.media.getch()

if user_input in self.SPACEBAR_KEY:
user_input = self.media.getch()
while user_input == curses.ERR:
user_input = self.media.getch()

if user_input in self.QUIT_KEYS: break

# Process a frame
dur = time.process_time()
cv2.imwrite("./data/frame.jpg", image)
self.print_from_image("./data/frame.jpg", coloring)
Expand All @@ -151,6 +171,9 @@ def read_media_sub(self, vidfile, coloring, subfile=''):
vidcap.release()
cv2.destroyAllWindows()

self.media.nodelay(False)
return user_input


def main(self, argv):
beginX = 0; beginY = 0
Expand All @@ -171,9 +194,10 @@ def main(self, argv):
self.captions.border(0, 0, 0, 0, 0, 0, 0, 0)
subfile = argv[2]

self.read_media_sub(vidfile,colored_output,subfile)
return_val = self.read_media_sub(vidfile,colored_output,subfile)

self.media.getch()
if (return_val not in self.QUIT_KEYS):
self.media.getch()

def run(stdscr):
obj = AMP()
Expand Down