The Face Crop component converts horizontal videos to vertical 9:16 format with intelligent face-centered or motion-tracked cropping.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/SamurAIGPT/AI-Youtube-Shorts-Generator/llms.txt
Use this file to discover all available pages before exploring further.
Functions
crop_to_vertical
Crops a video to vertical 9:16 aspect ratio with intelligent face detection or motion tracking.Path to the input video file to crop
Path where the cropped vertical video will be saved
Cropping Modes
The function automatically detects the best cropping strategy:- Face Detection Mode
- Motion Tracking Mode
When: A face is detected in the first 30 framesBehavior:
- Analyzes first 30 frames to detect faces
- Uses median face position for stability
- Applies 60px right offset to prevent cutoff
- Uses static crop position (no tracking)
- Best for: Talking head videos, interviews, vlogs
Output Specifications
- Aspect Ratio: 9:16 (vertical/portrait)
- Height: Preserves original video height
- Width: Calculated as
height * 9/16 - Dimensions: Always even numbers (codec requirement)
- Codec: XVID (Windows) or mp4v (Linux/Mac)
- FPS: Preserves original frame rate
Features
Face Detection
- Uses OpenCV’s Haar Cascade classifier
- Samples first 30 frames for stable detection
- Selects largest face if multiple detected
- Uses median position to avoid outliers
- 60px right offset prevents edge cutoff
Motion Tracking
- Optical flow using Farneback algorithm
- Updates every 1 second (once per
fpsframes) - Focuses on significant motion (threshold: 2.0)
- Smooth tracking with 90/10 interpolation
- Prevents abrupt camera movements
Scaling and Letterboxing
For screen recordings:- Scales to show 67% of original width
- Adds letterboxing if needed to maintain aspect ratio
- Uses LANCZOS4 interpolation for quality
The function sets a global
Fps variable used by combine_videos() to ensure frame rate consistency.combine_videos
Combines audio from one video with visuals from another, used to add original audio to cropped videos.Path to video file containing the audio track to use
Path to video file containing the visual content to use
Path where the combined video will be saved
Output Specifications
- Video Codec: libx264 (H.264)
- Audio Codec: AAC
- Preset: medium (balanced speed/quality)
- Bitrate: 3000k
- FPS: Uses global
Fpsvariable fromcrop_to_vertical()
Error Handling
Progress Tracking
Both functions provide progress updates:Performance Tips
- Face Detection: Only samples first 30 frames for speed
- Motion Tracking: Updates once per second (not every frame)
- Smooth Tracking: Uses 90/10 interpolation to reduce jitter
- Codec Selection: Platform-specific codec for compatibility
- Dimension Alignment: Ensures even dimensions for codec compatibility
Platform Compatibility
- Windows: Uses XVID codec
- Linux/Mac: Uses mp4v codec
