Skip to content

Commit

Permalink
Merge pull request #4 from AsaadMe/refactor
Browse files Browse the repository at this point in the history
Refactor
  • Loading branch information
AsaadMe authored Mar 20, 2021
2 parents 045ecef + f3bc0a3 commit 98b2a58
Show file tree
Hide file tree
Showing 4 changed files with 266 additions and 118 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ pip install -e .

Run it with:
```
moviecolor input.mp4 [-l 30] [-o output_name] [--alt] [--help]
moviecolor input.mp4 [-e 30] [-o output_name] [--alt] [--help]
```
>-l , --length: chosen part of the video from start (in Minutes)
>-e , --end: chosen part of the video from start (in Minutes)
>-a , --alt: instead of using average color, use shrinked frames
Expand Down
74 changes: 27 additions & 47 deletions moviecolor/__main__.py
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()
Loading

0 comments on commit 98b2a58

Please sign in to comment.