A video server serving local video files over local internet using HLS protocol along with many capabilities like searching using text-search engine etc.
- First step is to edit the
config.json
file. One needs to add the video directories to include. This file is not there, app should be run atleast one to generate this file.
{
"version": "1.0.0",
"vide_directory_absolute": [
<video directory 1>
<video directory 2>
],
"max_HLS_folder_size_GB": 1.0
}
There maybe other files other than video like .txt, .mp3 etc, one can determine file type using the mimetype
or the extension
of the file. The extensions are mentioned in Constants.ACCEPT_FILE_FORMATS
2. Once the paths
are added, program calculated the Md5
hash of each file. Whenever the server starts, it also creates a config-lock.json
to preserver the last know image
of config.json
along with hash.
Delete config-loc.json
if one wants to reset everything.
Program then calculates the diff
namely
- which files should be removed from indexing (db & text search engine) -- files removed by user
- Which files should be inserted as a new file
- which files should be renamed (Md5 hash same, maybe video renamed or moved by user)
- For database TinyDB is used and for text search Whoosh is used. The data structure for the database is like
{'id': file_id,
'file_name': ,
'abs_path': ,
'thumbnail_path': ,
'duration': ,
'width': ,
'height': ,
'format_name': ,
'size': ,
'v_bitrate': ,
'a_bitrate': ,
'is_favourite': ,
'hls_processing': ,
'hls_already_processed': ,
'hls_process_location': ,
'cluster_id': ,
'views':
}
- After updating the indexes,
Thumbnails
are generated for the required files using FFmpeg. make sureFFmpeg
installed on the system. and stored inConstants.THUMBNAIL_FOLDER_PATH
- Once it is done, server is ready to accept the requests.
- Once a request is
GET
, server checks if the<file_name>.m3u8
available insideConstants.HLS_OUTPUT_PATH
or not. If not it will start anew process
to process the file and deliver the chunks to client accordingly.
Once processed, the next time the buffering will be less to none. Buffering can be also be affected by the resolution during conversion. This app is using deafult Representation(Size(640, 360), Bitrate(276 * 1024, 128 * 1024))
- Make sure FFmpeg is installed. I worked with Ubuntu, hope will work fine with windows als well.
- Create virtual env
python -m venv venv
- Activate it ex: in ubuntu
source ./venv/bin/activate
- Install the required packages
pip install -r requirements.txt
- Start
python app.py
I have not used any proper servers, it worked fine with Flask-test server for personal project, one can use gunicorn
.