使用nginx-vod-module hls &&dash &&Thumbnail 处理
备注:
以前写过使用ffmpeg 转换为m3u8进行hls 视频处理,实际上有一个开源的很强大的工具,我们基本不用什么代码就可以实现hls、
dash、Thumbnail ,很强大
安装
- 使用源码编译
./configure --add-module=/path/to/nginx-vod-module
make
make install
- 使用容器
已经有别人做好的镜像了
docker pull nytimes/nginx-vod-module
基本使用
我直接clone 别人的参考代码
docker run -p 3030:80 -v $PWD/videos:/opt/static/videos -v $PWD/nginx.conf:/usr/local/nginx/conf/nginx.conf nytimes/nginx-vod-module
访问
HLS: http://localhost:3030/hls/devito,360p.mp4,480p.mp4,720p.mp4,.en_US.vtt,.urlset/master.m3u8
Dash: http://localhost:3030/dash/devito,360p.mp4,480p.mp4,720p.mp4,.en_US.vtt,.urlset/manifest.mpd
Thumbnail: http://localhost:3030/thumb/devito360p.mp4/thumb-1000.jpg
配置说明
nginx config
hls dash thumb
location /hls/ {
vod hls;
alias /opt/static/videos/;
add_header Access-Control-Allow-Headers '*';
add_header Access-Control-Allow-Origin '*';
add_header Access-Control-Allow-Methods 'GET, HEAD, OPTIONS';
}
location /thumb/ {
vod thumb;
alias /opt/static/videos/;
add_header Access-Control-Allow-Headers '*';
add_header Access-Control-Allow-Origin '*';
add_header Access-Control-Allow-Methods 'GET, HEAD, OPTIONS';
}
location /dash/ {
vod dash;
alias /opt/static/videos/;
add_header Access-Control-Allow-Headers '*';
add_header Access-Control-Allow-Origin '*';
add_header Access-Control-Allow-Methods 'GET, HEAD, OPTIONS';
}
核心vod 配置
vod_mode local;
vod_metadata_cache metadata_cache 16m;
vod_response_cache response_cache 2048m;
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;
参考资料
https://github.com/NYTimes/nginx-vod-module-docker/tree/master/examples
https://github.com/kaltura/nginx-vod-module
https://hub.docker.com/r/nytimes/nginx-vod-module/