File size: 2,813 Bytes
a005c19
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
65
66
67
68
69
70
71
72
73
import os
import cv2
import pandas as pd
import gradio as gr
import matplotlib.pyplot as plt
from utils.except_dir import cust_listdir
def get_video_metadata(video_path, category, benchmark):
    """Extract metadata from a video file."""
    cap = cv2.VideoCapture(video_path)
    
    if not cap.isOpened():
        return None
    # Extract metadata
    video_name = os.path.basename(video_path)
    frame_count = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
    fps = cap.get(cv2.CAP_PROP_FPS)
    frame_width = int(cap.get(cv2.CAP_PROP_FRAME_WIDTH))
    frame_height = int(cap.get(cv2.CAP_PROP_FRAME_HEIGHT))
    resolution = f"{frame_width}x{frame_height}"
    duration_seconds = frame_count / fps if fps > 0 else 0
    aspect_ratio = round(frame_width / frame_height, 2) if frame_height > 0 else 0
    file_size = os.path.getsize(video_path) / (1024 * 1024)  # MB
    file_format = os.path.splitext(video_name)[1].lower()
    cap.release()
    
    return {
        "video_name": video_name,
        "resolution": resolution,
        "video_duration": f"{duration_seconds // 60:.0f}:{duration_seconds % 60:.0f}",
        "category": category,
        "benchmark": benchmark,
        "duration_seconds": duration_seconds,
        "total_frames": frame_count,
        "file_format": file_format,
        "file_size_mb": round(file_size, 2),
        "aspect_ratio": aspect_ratio,
        "fps": fps
    }

def process_videos_in_directory(root_dir):
    """Process all videos in the given directory structure."""
    video_metadata_list = []
    
    # 벀치마크 폴더듀을 순회
    for benchmark in cust_listdir(root_dir):
        benchmark_path = os.path.join(root_dir, benchmark)
        if not os.path.isdir(benchmark_path):
            continue
        
        # dataset 폴더 경둜
        dataset_path = os.path.join(benchmark_path, "dataset")
        if not os.path.isdir(dataset_path):
            continue
            
        # dataset 폴더 μ•ˆμ˜ μΉ΄ν…Œκ³ λ¦¬ 폴더듀을 순회
        for category in cust_listdir(dataset_path):
            category_path = os.path.join(dataset_path, category)
            if not os.path.isdir(category_path):
                continue
                
            # 각 μΉ΄ν…Œκ³ λ¦¬ 폴더 μ•ˆμ˜ λΉ„λ””μ˜€ νŒŒμΌλ“€μ„ 처리
            for file in cust_listdir(category_path):
                file_path = os.path.join(category_path, file)
                
                if file_path.lower().endswith(('.mp4', '.avi', '.mkv', '.mov', 'MOV')):
                    metadata = get_video_metadata(file_path, category, benchmark)
                    if metadata:
                        video_metadata_list.append(metadata)
    # df = pd.DataFrame(video_metadata_list)
    # df.to_csv('sample.csv', index=False)
    return pd.DataFrame(video_metadata_list)