From 780625920a26ae1de8b7b087abd1b0fd4dac2c1c Mon Sep 17 00:00:00 2001 From: Matteo De Stefano Date: Mon, 30 Sep 2024 18:57:17 +0200 Subject: [PATCH 1/3] added a dev service --- docker-compose.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/docker-compose.yml b/docker-compose.yml index 0d0d1e3..d5376ad 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -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 From 32a172df0747440240d70a0d372f8be8ba197393 Mon Sep 17 00:00:00 2001 From: mdsnor Date: Mon, 30 Sep 2024 19:09:44 +0200 Subject: [PATCH 2/3] substituted ffmpeg with av (warning: function not used) --- .../find_overlapping_videos.py | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/tools/find_already_annotated_videos/find_overlapping_videos.py b/tools/find_already_annotated_videos/find_overlapping_videos.py index dc763f2..45a07cf 100644 --- a/tools/find_already_annotated_videos/find_overlapping_videos.py +++ b/tools/find_already_annotated_videos/find_overlapping_videos.py @@ -9,6 +9,7 @@ import cv2 import ffmpeg +import av import numpy as np import tqdm from imagehash import dhash, phash @@ -36,6 +37,38 @@ def extract_images_from_video(video_path, output_folder): cap.release() +# The following 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): + 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 From d7c2443afe35a4e35e5f219fda5cf7981edf726c Mon Sep 17 00:00:00 2001 From: mdsnor Date: Mon, 30 Sep 2024 19:14:59 +0200 Subject: [PATCH 3/3] fix #6 - av replaces ffmpeg --- tools/find_already_annotated_videos/find_overlapping_videos.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/find_already_annotated_videos/find_overlapping_videos.py b/tools/find_already_annotated_videos/find_overlapping_videos.py index 45a07cf..ec24879 100644 --- a/tools/find_already_annotated_videos/find_overlapping_videos.py +++ b/tools/find_already_annotated_videos/find_overlapping_videos.py @@ -37,7 +37,7 @@ def extract_images_from_video(video_path, output_folder): cap.release() -# The following is my attempt to substitute the function "extract_images_from_video_ffmpeg to avoid using ffmpeg" +# 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): video_path = Path(video_path) # Ensure it's a Path object video_name = video_path.stem # Get the file name without extension