Based nytimes alpine dockerfile
Go to file
2023-06-05 13:38:23 +02:00
docker-compose.yml Add: Basic Docker based on Kaltura HLS Nginx Module 2023-06-05 13:29:45 +02:00
Dockerfile Add: Basic Docker based on Kaltura HLS Nginx Module 2023-06-05 13:29:45 +02:00
nginx.conf Add: Basic Docker based on Kaltura HLS Nginx Module 2023-06-05 13:29:45 +02:00
README.md Add: Basic Docker based on Kaltura HLS Nginx Module 2023-06-05 13:38:23 +02:00

Based on https://github.com/nytimes/nginx-vod-module-docker

Basic config

Included nginx.conf:

worker_processes  auto;
pid /run/nginx.pid;

events {
	use epoll;
}

http {
	log_format  main  '$remote_addr $remote_user [$time_local] "$request" '
		'$status "$http_referer" "$http_user_agent"';

	access_log  /dev/stdout  main;
	error_log   stderr debug;

	default_type  application/octet-stream;
	include       /usr/local/nginx/conf/mime.types;

	sendfile    on;
	tcp_nopush  on;
	tcp_nodelay on;

	vod_mode                           local;
	vod_metadata_cache                 metadata_cache 16m;
	vod_response_cache                 response_cache 512m;
	vod_last_modified_types            *;
	vod_segment_duration               9000;
	vod_align_segments_to_key_frames   on;
	vod_dash_fragment_file_name_prefix "segment";
	vod_hls_segment_file_name_prefix   "segment";

	vod_manifest_segment_durations_mode accurate;

	open_file_cache          max=1000 inactive=5m;
	open_file_cache_valid    2m;
	open_file_cache_min_uses 1;
	open_file_cache_errors   on;

	aio on;
	
	server {
		listen 80;
		server_name localhost;
		root /var/www/html;

		location ~ ^/videos/.+$ {
			autoindex on;
		}

		location /hls/ {
			vod hls;
			alias /var/www/html/videos/;
			
			if ($arg_token) {
			 set $input_token $arg_token;
			}
			
			add_header Access-Control-Allow-Headers '*';
			add_header Access-Control-Allow-Origin '*';
			add_header Access-Control-Allow-Methods 'GET, HEAD, OPTIONS';

			#secure_token $secure_token;
			#secure_token_types application/vnd.apple.mpegurl;
			#secure_token_expires_time 100d;
			#secure_token_query_token_expires_time 1h;
		}

		location /thumb/ {
			vod thumb;
			alias /var/www/html/videos/;
			add_header Access-Control-Allow-Headers '*';
			add_header Access-Control-Allow-Origin '*';
			add_header Access-Control-Allow-Methods 'GET, HEAD, OPTIONS';
		}
	}
}

Use

Create videos directory, map to docker-compose and copy a video.mp4 file:

$ mkdir videos
$ vim docker-compose.yml
...
  volumes:
   - ./videos:/var/www/html/videos:ro
   ...

Example

Get thumbnail second 300:

$ http://localhost:8001/thumb/video.mp4/thumb-300.jpg

Play HLS:

$ mpv http://localhost:8001/hls/video.mp4,.urlset/master.m3u8

References

https://en.acodeof.com/video-on-demand-nginx-vod-module/ https://github.com/kaltura/nginx-vod-module https://docs.jwplayer.com/platform/reference/studio-drm-standalone-nginx-vod-module