Skip to content

Commit b52b520

Browse files
author
Bartu Yaman
authored
Updated.
Code re-arranged according to flake8.
1 parent 4a4ddc1 commit b52b520

1 file changed

Lines changed: 21 additions & 15 deletions

File tree

‎projects/EasyVideoPlayer/EasyVideoPlayer.py‎

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,49 @@
1-
import cv2 ## Used for the video.
1+
import cv2
22
import os
33
from pathlib import Path
4-
import numpy as np
5-
from ffpyplayer.player import MediaPlayer ## Used for the audio.
4+
from ffpyplayer.player import MediaPlayer
65

76

7+
# User input for the name of the image file.
8+
video_name = input("Name of the video file that you want to play: ")
89

9-
video_name = input("Please enter the name of the video file that you want to play: ") ## User input for the name of the image file.
10-
video_directory_guess = input("Please enter the directory that may contain the video: ") ## User input for the path of the image file.
10+
# User input for the path of the image file.
11+
video_directory_guess = input("Directory that may contain the video: ")
1112

12-
## This function looks for and finds the desired file. You can specify a parent directory for the fundtion to look for, however if you have no idea where a file is; this functio will find it for you, just slower. If you have no idea where a file is, just type "/".
13+
14+
# This function finds your file. If you don't know the directory just type '/'
1315
def find_the_video(file_name, directory_name):
1416
files_found = []
1517
for path, subdirs, files in os.walk(directory_name):
1618
for name in files:
1719
if(file_name == name):
18-
file_path = os.path.join(path,name)
20+
file_path = os.path.join(path, name)
1921
files_found.append(file_path)
2022

2123
print(files_found)
22-
return files_found[0] ## Return the path.
24+
return files_found[0] # Return the path.
25+
26+
27+
# Initialize the path of the image file.
28+
video_directory = Path(find_the_video(video_name, video_directory_guess))
2329

30+
# Initialize the parent directory of the image path.
31+
new_working_directory = video_directory.parent
2432

25-
video_directory = Path(find_the_video(video_name, video_directory_guess)) ## Initialize the path of the image file.
26-
new_working_directory = video_directory.parent ## Initialize the parent directory of the image path.
27-
os.chdir(new_working_directory) ## Change the working directory of the script to the parent directory of the image path.
33+
# Change the working directory of the script.
34+
os.chdir(new_working_directory)
2835

2936

37+
video_path = find_the_video(video_name, video_directory_guess)
3038

31-
video_path=find_the_video(video_name, video_directory_guess)
3239

3340
def PlayVideo(video_path):
3441

35-
video=cv2.VideoCapture(video_path)
42+
video = cv2.VideoCapture(video_path)
3643
player = MediaPlayer(video_path)
3744

3845
while True:
39-
grabbed, frame=video.read()
46+
grabbed, frame = video.read()
4047
audio_frame, val = player.get_frame()
4148
if not grabbed:
4249
print("End of video")
@@ -45,7 +52,6 @@ def PlayVideo(video_path):
4552
break
4653
cv2.imshow("Video", frame)
4754
if val != 'eof' and audio_frame is not None:
48-
#audio
4955
img, t = audio_frame
5056
video.release()
5157
cv2.destroyAllWindows()

0 commit comments

Comments
 (0)