diff --git a/app.py b/app.py index ea21137..0cc3e31 100644 --- a/app.py +++ b/app.py @@ -2,7 +2,7 @@ from flask import Flask, render_template, request, flash, redirect, url_for from werkzeug.utils import secure_filename from PIL import Image import os -import ffmpeg +# import ffmpeg import datetime; @@ -54,20 +54,19 @@ def upload_file(): return redirect(url_for('submitted')) elif ext in ['mp4', 'avi', 'mov', 'flv']: out_path = os.path.join(app.config['UPLOAD_FOLDER'], filename.rsplit('.', 1)[0].lower() + '.mp4') - file.save(temp_path) - stream = ffmpeg.input(temp_path) - stream = ffmpeg.hflip(stream) - stream = ffmpeg.output(stream, out_path) - ffmpeg.run(stream) - print("ive outputted somethign") + file.save(out_path) + # stream = ffmpeg.input(temp_path) + # stream = ffmpeg.hflip(stream) + # stream = ffmpeg.output(stream, out_path) + # ffmpeg.run(stream) # ffmpeg.input(temp_path).output(out_path,vf="scale=300:230", crf=24).run() # os.remove(temp_path) return redirect(url_for('submitted')) elif ext in ['mp3', 'wav', 'flac']: out_name = filename.rsplit('.', 1)[0].lower() + '.mp3' - file.save(temp_path) - ffmpeg.input(temp_path).output(os.path.join(app.config['UPLOAD_FOLDER'], out_name)).run() - os.remove(temp_path) + file.save(os.path.join(app.config['UPLOAD_FOLDER'], out_name)) + # ffmpeg.input(temp_path).output(os.path.join(app.config['UPLOAD_FOLDER'], out_name)).run() + # os.remove(temp_path) return redirect(url_for('submitted')) else: print("not an image!") diff --git a/script.py b/script.py index 3c0e582..ceb7dbc 100644 --- a/script.py +++ b/script.py @@ -56,7 +56,14 @@ def resize_and_center_frame(frame): # Create a black background of the window size window_background = np.zeros((WINDOW_HEIGHT, WINDOW_WIDTH, 3), dtype=np.uint8) - # Overlay the resized frame onto the background at the calculated offset + # Overlay the resized frame onto the background at the calculated offset + print(y_offset) + print(y_offset) + print(new_height) + print(x_offset) + print(x_offset) + print(new_width) + window_background[ y_offset : y_offset + new_height, x_offset : x_offset + new_width ] = resized_frame @@ -67,17 +74,22 @@ def resize_and_center_frame(frame): # Show an image on the canvas def showImage(file): # Read the image - current_image = cv2.imread(MEDIA_FOLDER + "/" + file) + current_image = cv2.imread(file) if current_image is None: - print(f"Error loading image: {image_path}") + print(f"Error loading image: {current_image}") return a = cv2.cvtColor(current_image, cv2.COLOR_BGR2GRAY) - resized_frame = resize_and_center_frame(current_image) - cv2.imshow(WINDOW_NAME, resized_frame) - cv2.namedWindow(WINDOW_NAME,cv2.WND_PROP_FULLSCREEN) - cv2.setWindowProperty(WINDOW_NAME, cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN) + + # resized_frame = resize_and_center_frame(current_image) + cv2.imshow(WINDOW_NAME, current_image) + # cv2.namedWindow(WINDOW_NAME,cv2.WND_PROP_FULLSCREEN) + # cv2.setWindowProperty(WINDOW_NAME, cv2.WND_PROP_FULLSCREEN, cv2.WINDOW_FULLSCREEN) + + + cv2.waitKey(1) + while True: for i in range(12): if mpr121[i].value: @@ -87,7 +99,7 @@ def showImage(file): def play_audio(file): clear_frame() - sound = sa.WaveObject.from_wave_file("media/" + file) + sound = sa.WaveObject.from_wave_file(file) play_obj = sound.play() # TODO: check for sensor data change @@ -96,39 +108,55 @@ def play_audio(file): time.sleep(0.1) load_media() -def get_random_file(previous=None): - random.shuffle(mediaFolder) - file = mediaFolder[0] - if file == previous: - return get_random_file(previous) +def get_random_file(f): + print("getting random file from ") + print(f) + + folder = os.listdir(f) + + random.shuffle(folder) + file = folder[0] + + if os.path.isdir(file): + print("oh no u gave me a folder, load the sub instead") + nF = os.listdir(f + "/" + file) + return get_random_file(nF) + return file # create a function with an optional parameter def load_media(region=None, override=None): global current_file - + + print("runningn load_media") + if region: print("i should now load a media from region ") print(region) else: print("region is not defined, just do something!") + folder = os.listdir(MEDIA_FOLDER)[region] + + print(folder) + if(override): file = override else: - file = get_random_file(current_file) + file = get_random_file(MEDIA_FOLDER + "/" + folder) current_file = file - + file_path = MEDIA_FOLDER + "/" + folder + "/" + file + print(file_path) # Check if the file is an image or a video if file.endswith(".jpg") or file.endswith(".png") or file.endswith(".jpeg"): # Read and resize the image print("ive loaded an image: " + file) - showImage(file) + showImage(file_path) elif file.endswith(".mov") or file.endswith(".mp4") or file.endswith(".avi"): # Create a VideoCapture object and read from input file - cap = cv2.VideoCapture("media/" + file) + cap = cv2.VideoCapture(file_path) print("ive loaded a video" + file) # show the input video file @@ -156,7 +184,7 @@ def load_media(region=None, override=None): break elif file.endswith(".wav") or file.endswith(".mp3"): print("ive loaded an audio file: " + file) - play_audio(file) + play_audio(file_path) else: print("Unsupported file format: " + file) @@ -164,4 +192,4 @@ def load_media(region=None, override=None): print("start script ") -load_media() +load_media(2)