H2V is an intelligent video conversion pipeline that transforms horizontal (landscape) videos into vertical (portrait) format while maintaining the main point of interest in frame. Unlike simple cropping solutions, H2V uses computer vision to track faces, detect speech, and follow motion to ensure the most important content remains visible.
- Intelligent Focus Tracking: Automatically identifies and follows faces, speakers, and motion
- Scene-Aware Processing: Detects scene changes to maintain context across cuts
- Speech Detection: Prioritizes speakers during dialogue scenes
- Smooth Transitions: Applies temporal smoothing to prevent jarring camera movements
- API Option: Use via command line, or API server.
H2V uses a modular pipeline architecture with specialized components:
- Scene Detection: Identifies scene boundaries to process each scene independently
- Face Detection: Uses MediaPipe to locate and track faces
- Speech Detection: Analyzes audio to identify when someone is speaking
- Motion Tracking: Falls back to optical flow tracking when no faces are detected
- Focus Point Selection: Combines all signals to determine the optimal focus point
- Temporal Smoothing: Reduces jitter by smoothing focus point transitions
- Video Creation: Crops and renders the final vertical video
- Batch Processing: Processes frames in batches to manage memory usage
- Keyframe Analysis: Analyzes keyframes and interpolates between them for efficiency
- Downscaling: Optionally downscales frames during analysis for faster processing
- Configurable Parameters: Adjustable settings for detection thresholds, performance, etc.
- Python 3.10+
- mediapipe (for face detection)
- moviepy (for video processing)
- scenedetect (for scene detection)
- librosa (for speech detection)
- opencv-python (for optical flow tracking)
- uvicorn (for API server)
- fastapi (for API server)
- python-multipart (for API server)
- aiofiles (for API server)
- Clone the repository:
git clone https://github.com/felixLandlord/h2v.git
cd h2v- Create a virtual environment: macOS/Linux:
python -m venv .venv
source .venv/bin/activateWindows:
python -m venv .venv
.venv\Scripts\activate- Install dependencies:
pip install -r requirements.txtRun the pipeline:
- Through the Command Line:
python main.py input_video.mp4 --output output_video.mp4- Through an API Server:
python main.py --apiOR
uvicorn api:app --reloadThis will start a local server at http://localhost:8000.
The H2V API provides the following endpoints for video processing:
- URL : /upload/
- Method : POST
- Content-Type : multipart/form-data
- Parameters :
- file : The video file to be processed (MP4, MOV, AVI, MKV)
- Response :
{
"job_id": "11cee74f-4af5-4850-8385-8c419a615ecd",
"status": "processing",
"message": "Video upload successful. Processing started."
}Uploads a horizontal video and starts the conversion process. Returns a job ID for tracking the process.
- URL : /status/{job_id}
- Method : GET
- Parameters :
- job_id : The ID of the job to check the status for
- Response :
{
"status": "completed",
"input_file": "temp/uploads/11cee74f-4af5-4850-8385-8c419a615ecd.mp4",
"output_file": "temp/outputs/11cee74f-4af5-4850-8385-8c419a615ecd.mp4",
"metadata_file": "temp/metadata/11cee74f-4af5-4850-8385-8c419a615ecd_focus_points.json",
"original_filename": "example.mp4"
}Checks the current status of a video processing job. Possible status values: "processing", "completed", "failed".
- URL : /download/{job_id}
- Method : GET
- Parameters :
- job_id : The ID of the job to download the processed video for
- Response : The processed video file in MP4 format.
- URL : /metadata/{job_id}
- Method : GET
- Parameters :
- job_id : The ID of the job to download the metadata for
- Response : The focus points metadata for the processed video file in JSON format.
Check out this sample conversion result: Sample Vertical Video
This sample demonstrates how H2V intelligently tracks the main subject while converting from horizontal to vertical format.
Additionally, you can view the focus points metadata used in the conversion: Sample Focus Points
This JSON file provides detailed information about the focus points tracked during the video conversion process.