Skip to content

Commit f705b0a

Browse files
authored
Merge pull request Python-World#217 from brtymn/brtymn-video-player
Brtymn EasyVideoPlayer Added.
2 parents 53950a3 + b8f1140 commit f705b0a

2 files changed

Lines changed: 71 additions & 0 deletions

File tree

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import cv2
2+
import os
3+
from pathlib import Path
4+
from ffpyplayer.player import MediaPlayer
5+
6+
7+
# User input for the name of the image file.
8+
video_name = input("Name of the video file that you want to play: ")
9+
10+
# User input for the path of the image file.
11+
video_directory_guess = input("Directory that may contain the video: ")
12+
13+
14+
# This function finds your file. If you don't know the directory just type '/'
15+
def find_the_video(file_name, directory_name):
16+
files_found = []
17+
for path, subdirs, files in os.walk(directory_name):
18+
for name in files:
19+
if(file_name == name):
20+
file_path = os.path.join(path, name)
21+
files_found.append(file_path)
22+
23+
print(files_found)
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))
29+
30+
# Initialize the parent directory of the image path.
31+
new_working_directory = video_directory.parent
32+
33+
# Change the working directory of the script.
34+
os.chdir(new_working_directory)
35+
36+
37+
video_path = find_the_video(video_name, video_directory_guess)
38+
39+
40+
def PlayVideo(video_path):
41+
42+
video = cv2.VideoCapture(video_path)
43+
player = MediaPlayer(video_path)
44+
45+
while True:
46+
grabbed, frame = video.read()
47+
audio_frame, val = player.get_frame()
48+
if not grabbed:
49+
print("End of video")
50+
break
51+
if cv2.waitKey(28) & 0xFF == ord("q"):
52+
break
53+
cv2.imshow("Video", frame)
54+
if val != 'eof' and audio_frame is not None:
55+
img, t = audio_frame
56+
video.release()
57+
cv2.destroyAllWindows()
58+
59+
60+
PlayVideo(video_path)

‎projects/EasyVideoPlayer/README.md‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# EasyVideoPlayer
2+
EasyVideoPlayer script is a video player based on the terminal. It can find the video in a pc, change its working directory and play the video file.
3+
4+
### Prerequisites
5+
cv2, os, pathlib and ffpyplayer.player libraries are needed to run this script, all of which can be installed using "pip3 install 'library name'".
6+
7+
### How to run the script
8+
'cd' to the directory that contains the script and type "python3 EasyVideoPlayer.py". When you are done with the video, use "keyboard interrupt" (Ctrl + C) to exit the player.
9+
10+
## *Author Name*
11+
Bartu Yaman

0 commit comments

Comments
 (0)