Oct-26-2020, 09:30 PM
I ended up using cv2:
I finished the first version of my timestamp finder, I works... sort of, its a bit of a hit or miss on some chapter timestamps and sometimes there's a dark scene getting flagged.
0:11:39
0:22:10
0:35:06
0:45:28
0:45:57
I just wanted to give an update.
Thanks for Reading,
Daring_T
I finished the first version of my timestamp finder, I works... sort of, its a bit of a hit or miss on some chapter timestamps and sometimes there's a dark scene getting flagged.
import cv2 import numpy as np import time import os from TS import TS def convert(seconds): seconds = seconds % (24 * 3600) hour = seconds // 3600 seconds %= 3600 minutes = seconds // 60 seconds %= 60 return "%d:%02d:%02d" % (hour, minutes, seconds) def frames_to_secs(input_frame_num, fps): # Python Program to Convert seconds # into hours, minutes and seconds secs = input_frame_num / fps return convert(secs) def get_file_data(f): import re f = os.path.basename(f) ep_seires, ep_se, ep_title = f.split(" - ") match = re.match(r"[S|s](\d\d?)[E|e](\d\d?)", ep_se) seasion_num, ep_num = match.groups() return ep_seires, seasion_num, ep_num def remove_duplicates(input_list): print('Removing Duplicates from list') cleaned_list = list(set(input_list)) return sorted(cleaned_list) def get_dark_frames(input_loc): """Function to extract frames from input video file and save them as timestamps in an output directory. Args: input_loc: Input video file path. Returns: list: Found Timestamps """ # Log the time time_start = time.time() # Start capturing the feed cap = cv2.VideoCapture(input_loc) fps = cap.get(cv2.CAP_PROP_FPS) # Find the number of frames video_length = int(cap.get(cv2.CAP_PROP_FRAME_COUNT)) - 1 print("Number of frames: ", video_length) count = 0 old_found_TS = "" # Start converting the video black = num_of_frames = 0 found_TS_list = [] while cap.isOpened(): # Extract the frame ret, frame = cap.read() num_of_frames = num_of_frames + 1 # print(num_of_frames) gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY) if np.average(gray) < 7: # Write the results back to output location. black = black + 1 found_TS = frames_to_secs(num_of_frames, fps=fps) # print("Found_TS:", found_TS) found_TS_list.append(found_TS) count = count + 1 # If there are no more frames left if count > video_length - 1: # Log the time again time_end = time.time() # Release the feed cap.release() # print("Found_TS:",TS) print("It took %d seconds forconversion." % (time_end - time_start)) print(f"black frames:{black}") print("video_length:", video_length) print(get_file_data(input_loc)) return remove_duplicates(found_TS_list) input_loc = r"C:\Users\Daren\Videos\Little_House_in_the_Parie\S1\D1 S1\Little_House_in_the_Parie - s01e01 - A Harvest of Friends.mkv" output_loc = "C:\\Users\\Daren\\Videos\\Testing_Video_files\\" print(get_dark_frames(input_loc))
Output:Number of frames: 82677
It took 174 seconds forconversion.
black frames:425
video_length: 82677
Removing Duplicates from list
['0:00:00', '0:00:01', '0:02:25', '0:02:26', '0:02:27', '0:02:28', '0:02:29', '0:02:30', '0:02:31', '0:11:39', '0:11:40', '0:22:10', '0:22:11', '0:35:06', '0:35:07', '0:35:08', '0:43:12', '0:43:18', '0:43:20', '0:43:22', '0:43:23', '0:43:26', '0:45:28', '0:45:29', '0:45:57', '0:45:58']
The actual chapter timestamps are:0:11:39
0:22:10
0:35:06
0:45:28
0:45:57
I just wanted to give an update.
Thanks for Reading,
Daring_T