毕设项目要求利用 Nginx 实现一个流媒体服务器,提供视频点播功能
初步设想的处理步骤:
- 利用 Nginx-upload-module 实现视频文件从前端上传到服务器的资源目录
- 编写一个模块,将资源目录下的 .mp4 文件通过 ffmpeg 转码切片成符合 HLS 协议的 .m3u8 和 一系列小 ts 文件,存放到片源目录中
- Nginx 直接发布片源目录中的资源
目前测试了 Nginx 对 .m3u8 的支持,可以直接拉片源目录中的 .m3u8 到播放器里播放;也测试了 Nginx-upload-module 在 upload_pass 中启动其他模块的功能
想请教各位大佬:
- 这个思路是否可行
- 如果可以的话,关于 Nginx-upload-module 这个模块,需要利用其他脚本语言实现对上传资源的存储。因为我不想引入其他语言实现,打算直接在我自己编写的模块中处理上传资源并转码切片。那么下面配置中诸如
$upload_file_name等是变量吗,如何在自己编写的模块中引用他们的数据呢
感谢大佬指点
server {
client_max_body_size 100m;
listen 80;
# Upload form should be submitted to this location
location /upload/ {
# Pass altered request body to this location
upload_pass @test;
# Store files to this directory
# The directory is hashed, subdirectories 0 1 2 3 4 5 6 7 8 9 should exist
upload_store /tmp 1;
# Allow uploaded files to be read only by user
upload_store_access user:r;
# Set specified fields in request body
upload_set_form_field $upload_field_name.name "$upload_file_name";
upload_set_form_field $upload_field_name.content_type "$upload_content_type";
upload_set_form_field $upload_field_name.path "$upload_tmp_path";
# Inform backend about hash and size of a file
upload_aggregate_form_field "$upload_field_name.md5" "$upload_file_md5";
upload_aggregate_form_field "$upload_field_name.size" "$upload_file_size";
upload_pass_form_field "^submit$|^description$";
upload_cleanup 400 404 499 500-505;
}
# Pass altered request body to a backend
location @test {
proxy_pass http://localhost:8080;
}
}