Spaces:
Build error
Build error
Julian Bilcke commited on
Commit ·
a529bb7
1
Parent(s): 1b19314
add automatic FPS tracking
Browse filesFiles changed (2)
3 unmodified lines45677891099 unmodified lines1101111121131141151161171181191201211221233 unmodified linesimport shutilfrom typing import Any, Optional, Dict, List, Union, Tuplefrom config import STORAGE_PATH, TRAINING_PATH, STAGING_PATH, TRAINING_VIDEOS_PATH, MODEL_PATH, OUTPUT_PATH, HF_API_TOKEN, MODEL_TYPESfrom utils import extract_scene_info, make_archive, is_image_file, is_video_filefrom utils import get_video_fps, extract_scene_info, make_archive, is_image_file, is_video_file
logger = logging.getLogger(__name__)
99 unmodified lines if parent_caption and not caption.endswith(parent_caption): caption = f"{caption}\n{parent_caption}"
# Add FPS information for videos if is_video_file(file_path) and caption: # Only add FPS if not already present if not any(f"FPS, " in line for line in caption.split('\n')): fps_info = get_video_fps(file_path) if fps_info: caption = f"{fps_info}{caption}"
if prompt_prefix and not caption.startswith(prompt_prefix): caption = f"{prompt_prefix}{caption}" 1234567891011121314156 unmodified lines2223242526272829303132333435363738394041424344454647484950515253545556575859606162636465import osimport shutilimport subprocessfrom huggingface_hub import HfApi, create_repofrom pathlib import Pathimport jsonimport reimport loggingfrom typing import Any, Optional, Dict, List, Union, Tuple
logger = logging.getLogger(__name__)
def make_archive(source: str | Path, destination: str | Path): source = str(source) destination = str(destination)6 unmodified lines shutil.make_archive(name, format, archive_from, archive_to) shutil.move('%s.%s'%(name,format), destination)
def get_video_fps(video_path: Path) -> Optional[str]: """Get FPS information from video file using ffprobe Args: video_path: Path to video file Returns: FPS string (e.g. "24 FPS, ") or None if unable to determine """ try: cmd = [ 'ffprobe', '-v', 'error', '-select_streams', 'v:0', '-show_entries', 'stream=avg_frame_rate', '-of', 'default=noprint_wrappers=1:nokey=1', str(video_path) ] result = subprocess.run(cmd, capture_output=True, text=True) if result.returncode != 0: logger.warning(f"Error getting FPS for {video_path}: {result.stderr}") return None fps = result.stdout.strip() if '/' in fps: # Convert fraction to decimal num, den = map(int, fps.split('/')) if den == 0: return None fps = str(round(num / den)) return f"{fps} FPS, " except Exception as e: logger.warning(f"Failed to get FPS for {video_path}: {e}") return None
def extract_scene_info(filename: str) -> Tuple[str, Optional[int]]: """Extract base name and scene number from filename finetrainers_utils.py+9-1
utils.py+42