Endpoint
Path Parameters
The filename of the video to stream. This is returned in the
video_filename field from the Generate endpoint.Example: "Introduction_to_Machine_Learning_final.mp4"Request Headers
Optional range header for partial content requests following RFC 7233 format.Format:
bytes=start-endExamples:bytes=0-1023- First 1024 bytesbytes=1024-- From byte 1024 to endbytes=0-- Entire file (same as no Range header)
Response Headers
Always set to
video/mp4Set to
bytes to indicate range request supportSize of the content being returned (full file size or range size)
Only present for range requests (206 responses).Format:
bytes start-end/totalExample: bytes 0-1023/5242880Set to
identity to indicate no encodingCORS header exposing content metadata headers to the client
Response Status Codes
200 OK
Returned when streaming the entire file (no Range header):206 Partial Content
Returned when streaming a range of bytes:404 Not Found
Returned when the video file doesn’t exist:416 Range Not Satisfiable
Returned when the Range header is invalid:- Start position greater than end position
- Start position is negative
- End position exceeds file size
Range Request Behavior
Chunk Size
The server streams video in chunks of 10,000 bytes (10 KB) for optimal performance.Valid Range Examples
| Range Header | Description |
|---|---|
bytes=0-1023 | First 1024 bytes |
bytes=1024-2047 | Second kilobyte |
bytes=1024- | From byte 1024 to end |
bytes=-1024 | Last 1024 bytes (not supported by this implementation) |
The implementation requires an explicit start position. Open-ended ranges like
bytes=-1024 (last N bytes) are not supported.Example Requests
Stream Full Video
Stream with Range Request
JavaScript (Fetch API)
HTML5 Video Element
HTML5 video players automatically use range requests for seeking, so no special client-side code is needed.
Implementation Details
Storage Location
Videos are stored in theConfig.FINAL_DIR directory (configured in backend/config.py).
File Format
All generated videos are in MP4 format with H.264 video codec.Streaming Process
- Server receives request with optional Range header
- Validates file exists in final output directory
- Parses Range header (if present) and validates bounds
- Streams file in 10 KB chunks
- Closes file handle after streaming completes
CORS Support
The endpoint supports CORS for video streaming from web applications:- Allowed origins:
http://localhost:5173,http://127.0.0.1:5173 - Exposed headers include content metadata for proper video playback
Performance Considerations
Range requests enable efficient video streaming by allowing:
- Instant seeking: Jump to any point without downloading entire file
- Bandwidth efficiency: Only download the portions being watched
- Resume capability: Continue downloads from interruption point