Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contributions #7

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,15 @@ services:
- ./data:/app/data
- ./logs:/app/logs
- ./app/logs:/app/app/logs
dev:
<<: *common
profiles:
- dev
#command: poetry run python -m app.main
volumes:
- /tmp/.X11-unix:/tmp/.X11-unix
- ./input:/app/input
- ./output:/app/output
#- ./:/app
- ./app:/app/app
- ./pyproject.toml:/app/pyproject.toml
33 changes: 33 additions & 0 deletions tools/find_already_annotated_videos/find_overlapping_videos.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import cv2
import ffmpeg
import av
import numpy as np
import tqdm
from imagehash import dhash, phash
Expand Down Expand Up @@ -36,6 +37,38 @@ def extract_images_from_video(video_path, output_folder):

cap.release()

# The following function is my attempt to substitute the function "extract_images_from_video_ffmpeg to avoid using ffmpeg"
def extract_images_from_video_av(video_path, output_folder):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just change the existing function instead of adding a new one, so that it is easy to compare the differences.

video_path = Path(video_path) # Ensure it's a Path object
video_name = video_path.stem # Get the file name without extension

# Create the output folder if it doesn't exist
os.makedirs(output_folder, exist_ok=True)

output_file_pattern = os.path.join(output_folder, f"{video_name}_frame_%04d.jpg")

# Open the video file with PyAV
try:
container = av.open(str(video_path))
except av.AVError as e:
print(f"Error opening video file: {e}")
return

frame_index = 0

# Loop through all the frames in the video stream
for frame in container.decode(video=0): # 'video=0' to select the first video stream
# Convert the frame to an image (PIL)
img = frame.to_image()

# Save the frame as a JPEG image
output_file = output_file_pattern % frame_index
img.save(output_file)

print(f"Saved frame {frame_index} to {output_file}")
frame_index += 1

print(f"Extraction complete. {frame_index} frames saved to {output_folder}.")

def extract_images_from_video_ffmpeg(video_path, output_folder):
video_name = video_path.stem
Expand Down
Loading