This proof-of-concept demonstrates local video stitching and HLS streaming using Python, OpenCV, FFmpeg, and HLS.js. It is designed for local testing and can be adapted for cloud workflows (e.g., AWS Lambda + S3 triggers).
- Input Videos: Place
.mp4files in thevideo-inputdirectory. - Processing: Run
make processto:- Convert each
.mp4into segments (either.tsor.mp4format) - Generate a
playlist.m3u8HLS playlist in theoutputdirectory, referencing all segments in order.
- Convert each
- Serving: Run
make serveto start a local HTTP server in theoutputdirectory. - Playback: Open http://localhost:8000/player.html in your browser to view the stitched video stream using a simple HLS.js-based player.
The POC supports two segment formats:
-
HLS TS Segments (default):
make process-ts # or just make process- Generates
.tssegments using MPEG-TS container format - Best for HLS streaming
- Compatible with most HLS players
- Generates
-
MP4 Segments:
make process-mp4
- Generates
.mp4segments - Useful for direct MP4 playback or when MP4 segments are required
- Still works with HLS.js for streaming
- Generates
- HLS streaming requires HTTP(S): Browsers and HLS.js fetch the playlist and video segments over HTTP. Opening
player.htmldirectly from the filesystem will not work due to browser security restrictions (CORS, file access). - Local server:
make serveuses Python's built-in HTTP server to serve the playlist, segments, and player page, simulating a real streaming environment.
- Supported: The player supports scrubbing (seeking) within the stitched video timeline, as all segments are referenced in the playlist and the playlist is finalized for VOD.
- How it works: HLS.js loads the playlist and segments, allowing you to jump to any point in the video after it is loaded.
make clean # Clean output directory
make download-samples # Download sample videos to video-input/
make process-ts # Process videos into HLS segments (TS format)
make process-mp4 # Process videos into MP4 segments
make serve # Start local HTTP server in output/Then open http://localhost:8000/player.html in your browser.
video-input/— Place your input.mp4files hereoutput/— Contains generated segments (.tsor.mp4),playlist.m3u8, andplayer.htmlsrc/video_stitching/local_processor.py— Processes and stitches videos into HLS formatoutput/player.html— Simple HTML5 player using HLS.js
- Python 3.8+
- FFmpeg (must be installed and available in your PATH)
- uv for dependency management
For further improvements, see the TODO section in the code or open an issue.