-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfilter_content.py
More file actions
66 lines (57 loc) · 2.38 KB
/
Copy pathfilter_content.py
File metadata and controls
66 lines (57 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import os
from PIL import Image
import cv2
def filter_images(images_directory):
if not os.path.exists(images_directory):
os.makedirs(images_directory)
all_files_images = os.listdir(images_directory)
# Filter image files
IMAGE_FILES = []
for file in all_files_images:
file_path = os.path.join(images_directory, file)
if file.lower().endswith(('.jpg', '.jpeg', '.png', '.gif', '.webp')):
# Open image and get dimensions
try:
with Image.open(file_path) as img:
width, height = img.size
if width == 1024 and height == 576:
IMAGE_FILES.append(file)
except Exception as e:
print(f"Error processing image '{file}': {e}")
return IMAGE_FILES
def filter_images_short(images_short_directory):
if not os.path.exists(images_short_directory):
os.makedirs(images_short_directory)
all_files_images = os.listdir(images_short_directory)
# Filter image files
IMAGE_FILES = []
for file in all_files_images:
file_path = os.path.join(images_short_directory, file)
if file.lower().endswith(('.jpg', '.jpeg', '.png', '.gif', '.webp')):
# Open image and get dimensions
try:
with Image.open(file_path) as img:
width, height = img.size
if width == 536 and height == 960:
IMAGE_FILES.append(file)
except Exception as e:
print(f"Error processing image '{file}': {e}")
return IMAGE_FILES
def filter_videos(videos_directory):
if not os.path.exists(videos_directory):
os.makedirs(videos_directory)
all_files_video = os.listdir(videos_directory)
# Filter video files
VIDEO_FILES = []
for file in all_files_video:
file_path = os.path.join(videos_directory, file)
if file.lower().endswith(('.mp4', '.avi', '.mov', '.mkv')):
# Read video properties
cap = cv2.VideoCapture(file_path)
width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
cap.release()
# Check if video resolution matches 1280x720
if width == 1280 and height == 720:
VIDEO_FILES.append(file)
return VIDEO_FILES