Download scripts/slicer.py from fsl-app-2526/fsl-express: direct link, hf CLI and curl.
- Browser
- Download file 1.54 kB
-
https://huggingface.co/fsl-app-2526/fsl-express/resolve/main/scripts/slicer.py
- Command line
-
hf download hf://fsl-app-2526/fsl-express/scripts/slicer.py
-
curl -L -o slicer.py https://huggingface.co/fsl-app-2526/fsl-express/resolve/main/scripts/slicer.py
1.54 kB
| import pandas as pd | |
| import subprocess | |
| import os | |
| from tqdm import tqdm | |
| def slice_sign_dataset(csv_path, video_dir="fsl-data/raw_videos", output_dir="fsl-data/sliced_dataset"): | |
| df = pd.read_csv(csv_path) | |
| print(f"[*] Beginning slicing of {len(df)} samples...") | |
| for idx, row in tqdm(df.iterrows(), total=len(df)): | |
| filename = row['filename'] | |
| label = row['label'] | |
| start_f = int(row['start_frame']) | |
| end_f = int(row['end_frame']) | |
| video_stem = os.path.splitext(filename)[0] | |
| target_folder = os.path.join(output_dir, video_stem, label) | |
| os.makedirs(target_folder, exist_ok=True) | |
| output_filename = f"sample_{idx:04d}.mp4" | |
| output_path = os.path.join(target_folder, output_filename) | |
| if os.path.exists(output_path): | |
| continue | |
| start_sec = start_f / 30.0 | |
| duration_sec = (end_f - start_f) / 30.0 | |
| input_path = os.path.join(video_dir, filename) | |
| cmd = [ | |
| 'ffmpeg', | |
| '-y', | |
| '-ss', str(start_sec), | |
| '-i', input_path, | |
| '-t', str(duration_sec), | |
| '-c', 'copy', | |
| '-loglevel', 'error', | |
| output_path | |
| ] | |
| try: | |
| subprocess.run(cmd, check=True) | |
| except subprocess.CalledProcessError as e: | |
| print(f"[!] Error slicing {filename} at index {idx}: {e}") | |
| if __name__ == "__main__": | |
| slice_sign_dataset("master_annotations.csv") | |