Complete VOD Engine (HLS, HTTP Range, Thumbnails, JSON API)
Open‑source project (MIT / Apache / GPL)Version 1.0
I am pleased to share a complete VOD engine built in B4X, ready to use, and easy to integrate into your own applications.
It automatically processes videos, generates HLS, MP4 progressive streaming with HTTP Range support, creates thumbnails, and exposes a RESTFul JSON API.
It is composed of two parts: an encoder and a server. The B4A client is provided as an example.
Prerequisites
- FFmpeg installed and available in the PATH
- Java 11+
- SQLite database
- Latest version of B4J
- JShell
- JSON
- JSQL
- JRandomAccessFile
- JServer
- JSON
- JSQL
- ExoPlayer
- JSON
- OkHttpUtils2
- xCustomListView
Main Features
Encoder (VODEncoder)
- Automatic folder structure generation
- HLS generation (ffmpeg → .m3u8 + .ts segments)
- Automatic thumbnail generation
- Non‑destructive encoding (source files remain untouched)
- Robust encoding (FFmpeg error handling)
- Automatic extraction of video duration
- Automatic insertion into SQLite database
- Safe naming (safe_name) to avoid URL issues
- Supports MP4 / MKV / MOV / AVI (depending on FFmpeg)
Server (VODServer)
- MP4 streaming with HTTP Range support (compatible with ExoPlayer, VLC, Chrome)
- HLS streaming (/master.m3u8)
- Full RESTful API (JSON)
- /api/videos
- /api/video/{id}
- /api/search?q=…
- /api/status
- /api/mp4/{id}
- Compatible with ExoPlayer
- Compatible with VLC
- Compatible with browsers (Chrome, Firefox, Edge)
Native HLS streaming
- Compatible with Safari / iOS
- Compatible with ExoPlayer
- Compatible with VLC
- Automatic Content‑Type handling
- HTTP error handling (400, 404, 500)
- Static server for thumbnails and HLS segments
RESTFul API Endpoints
1 – Video list
GET /api/videos Returns the full list of videos (with HLS + thumbnails).2 – Video details
GET /api/video/{id} Returns complete information about a video.3 – Search
GET /api/search?q=keyword Returns videos matching the keyword.4 – Server status
GET /api/status Checks:- DB connection
- Number of videos
- Existence of VOD and thumbnail folders
- General server health
5 – MP4 Stream
GET /api/mp4/{id} Returns the information required to stream the MP4 file.Example JSON Response
{
"id": 1,
"title": "Avatar",
"safe_name": "01042022_as12d",
"duration": 7200,
"hls_url": "http://localhost:8080/vod/avatar/master.m3u8",
"thumb_url": "http://localhost:8080/thumbs/avatar.jpg"
}
Installation & Configuration
This section explains how to install and configure the VODEncoder and VODServer system. Both modules share the same file structure, defined in a single file:config.properties
This file is mandatory and must be strictly identical for:
- VODEncoder
- VODServer
1) Folder structure
The config.properties file defines the location of all folders used by the system.Example structure:
# Web server root pathbase_path=d:/www/
# Folder containing HLS directories
vod_path=d:/www/vod/
# Folder containing thumbnails
thumbs_path=d:/www/thumbs/
# Folder where original files are placed
input_path=d:/www/input/
server_port=8080
Static_Folder=d:/www
# Database location and name
DB_path=d:/wwwdata
DB_Name=vod.db3
VODEncoder will read config.properties and automatically create all required folders.
Summary
- Create the config.properties file
- Copy it into the objects folder of both VODEncoder and VODServer
- Run VODEncoder (folders and database will be created automatically)
- Select the folder containing the videos to process
- Wait for the process to finish
- Start VODServer
- Launch VODClient
Client-side example (B4A)
Dim j As HttpJob
j.Initialize("", Me)
j.Download("http://SERVER/api/videos")
Wait For (j) JobDone(j As HttpJob)
If j.Success Then
Dim parser As JSONParser
parser.Initialize(j.GetString)
Dim videos As List = parser.NextArray
' Display in a list
End If
j.Release
Security
- Optional IP‑based access restriction
- Compatible with reverse proxies (Nginx / Apache)
- HTTPS support via proxy
Roadmap
- Add API key and token
- Category / tag management
- DASH support (MPEG‑DASH)
- Web administration interface
- Multi‑quality transcoding (240p / 480p / 720p / 1080p)
- Thumbnail caching
- Pagination in /api/videos
This project was designed to be simple, robust, and easy to integrate into your B4X applications. Feedback, suggestions, and contributions are welcome.
Feel free to modify, improve, or fork the project.