-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4 from AsaadMe/refactor
Refactor
- Loading branch information
Showing
4 changed files
with
266 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,69 +1,49 @@ | ||
#from moviecolor import movcolor | ||
from moviecolor.moviecolor import movcolor | ||
#from moviecolor import Movcolor | ||
from pathlib import Path | ||
import tkinter as tk | ||
import argparse | ||
import threading | ||
import time | ||
import sys | ||
|
||
from moviecolor.moviecolor import Movcolor | ||
|
||
parser = argparse.ArgumentParser() | ||
parser.add_argument('in_file', type=Path, help='Input file path') | ||
parser.add_argument('-o','--out_filename', type=Path, default='result', help='Output file path') | ||
parser.add_argument('-l','--length', type=int, default=0 , help='Chosen part of the video from start in Minutes') | ||
parser.add_argument('-a','--alt', action='store_true', help='Instead of gettig average color of frames, Each bar is the resized frame') | ||
parser.add_argument('-o', '--out_filename', type=Path, | ||
default='result', help='Output file path') | ||
parser.add_argument('-s', '--start', type=int, default=0, | ||
help='Start point of the chosen part of the video in Minutes') | ||
parser.add_argument('-e', '--end', type=int, default=0, | ||
help='End point of the chosen part of the video in Minutes') | ||
parser.add_argument('-a', '--alt', action='store_true', | ||
help='Instead of average color, Each bar is the resized frame') | ||
|
||
|
||
def main(): | ||
"""Starting point of the program | ||
to read the input args and create movcolor object""" | ||
|
||
args = parser.parse_args() | ||
|
||
input_file_path = args.in_file | ||
|
||
if not input_file_path.is_file(): | ||
print( | ||
"\nEnter Valid input Path.\n" | ||
"Example (on windows): \"c:\\video\\input with white space.mp4\"\n" | ||
"Example (on linux): /home/video/file.mp4" | ||
"\nEnter Valid input Path.\n" | ||
"Example (on windows): \"c:\\video\\input with white space.mp4\"\n" | ||
"Example (on linux): /home/video/file.mp4" | ||
) | ||
exit() | ||
sys.exit() | ||
|
||
output_file_path = args.out_filename | ||
video_length = args.length | ||
start_point = args.start | ||
end_point = args.end | ||
|
||
obj1 = movcolor(1, input_file_path, output_file_path) | ||
|
||
if video_length != 0: | ||
number_of_frames = video_length * 60 * 3 | ||
else: | ||
duration = obj1.get_video_duration() | ||
number_of_frames = duration * 3 | ||
video_length = int(duration/60) | ||
|
||
if args.alt: | ||
process_func = movcolor.process_frame_compress_width | ||
refresh_image = obj1.refresh_image_alt | ||
draw_func = obj1.draw_alt | ||
mode = "alt" | ||
else: | ||
process_func = movcolor.process_frame_average_color | ||
refresh_image = obj1.refresh_image_normal | ||
draw_func = obj1.draw_normal | ||
|
||
th = threading.Thread(target=obj1, args=(video_length ,process_func, draw_func, 0)) | ||
|
||
th.daemon = True # terminates whenever main thread does | ||
th.start() | ||
|
||
while len(obj1.rgb_list) == 0: # rgb_list in refresh_image shouldnt be empty | ||
time.sleep(.1) | ||
|
||
root = tk.Tk() | ||
canvas = tk.Canvas(root, height=720, width=1500) | ||
|
||
root.title("MovieColor") | ||
root.geometry("1500x720+0+10") | ||
canvas.pack() | ||
mode = "normal" | ||
|
||
refresh_image(canvas, 1, number_of_frames) | ||
root.mainloop() | ||
obj1 = Movcolor(1, input_file_path, output_file_path, start_point, end_point, mode) | ||
obj1.run() | ||
|
||
if __name__ == "__main__": | ||
main() | ||
main() |
Oops, something went wrong.