項目統計模型準確率
項目會保存大量視頻,為了統計模型的精度,我們想要十五分鐘抽取一個視頻用來統計。
import os
import shutil
from datetime import datetime, timedelta
#抽取視頻的代碼,會在每個小時的0分、15分、30分、45分取一個命名中有h264的視頻
# 源文件夾路徑
source_folder = 'E:/59test/8a7b1e1bd47d4e7fbe4fd122322/'
# 目標文件夾路徑
target_folder = 'E:/59test/test'# 獲取源文件夾中的所有文件
files = os.listdir(source_folder)
# 用于記錄已保存的時間點
saved_timepoints = set()# 遍歷文件
for file in files:# 檢查文件是否為mp4文件,并且文件名中包含"h264"if file.endswith('.mp4') and 'h264' in file:file_path = os.path.join(source_folder, file)# 獲取文件的修改時間modification_time = datetime.fromtimestamp(os.path.getmtime(file_path))# 檢查文件大小是否大于200KBif os.path.getsize(file_path) > 200 * 1024:# 檢查是否滿足每個小時的0分、15分、30分、45分的條件if modification_time.minute in [0, 15, 30, 45]:# 構造時間點的字符串表示timepoint = modification_time.strftime('%Y-%m-%d %H:%M')# 檢查當前時間點是否已保存過視頻if timepoint not in saved_timepoints:# 構造目標文件夾中的子文件夾路徑subfolder_path = os.path.join(target_folder, modification_time.strftime('%Y-%m-%d'))# 如果子文件夾不存在,則創建子文件夾if not os.path.exists(subfolder_path):os.makedirs(subfolder_path)# 構造目標文件路徑target_file_path = os.path.join(subfolder_path, file)# 將文件復制到目標文件夾,并保留元數據shutil.copy2(file_path, target_file_path)# 將當前時間點添加到已保存的時間點集合中saved_timepoints.add(timepoint)# 結束當前時間點的循環,繼續處理下一個時間點的視頻文件continue