Recently had an idea, want to do something like the following video URL security verification;
1、URL Tag Validation 2、Special format of URL for preventing unauthorized usage and access、 sample Original: http://www.baidu.com/2016/0704/8025915_HD-60i_7198.mp4 Using UTV:http://www.baidu.com/2016/0704/8025915_HD-60i_7198.mp4?px-time=1467685158&px-hash=a08a3c149514aae2aea14755a45a29c2 px-time : current time or expire time px-hash : hash(secret + url_path +expire_time)
Here are my thoughts, in accordance with the idea to do it;
1. A simple test streaming media server.
2. knowledge to figure out the link page security needs, such as opening video link and then verify referer, as well as add args check and so on.
3. optimization, it adds functionality.
4. Verify that meets these requirements.
Tengine build streaming media using the new module comes with mp4
Download Source: http://tenine.taobao.org/download.html
./configure --prefix=/web --with-http_sub_module --with-http_stub_status_module --with-http_gzip_static_module --with-http_v2_module --with-http_ssl_module --with-http_image_filter_module --with-http_image_filter_module=dynamic --with-http_sub_module --with-http_mp4_module && make && make install
Nginx configuration file:
#### server { listen 80; server_name xxxxxx; access_log logs/vhost/xxxxxx_access.log main; #access_log "pipe:rollback logs/vhost/xxxxxx.access_log interval=1d baknum=7 maxsize=2G" main; location / { root xxxxxx; index index.html index.htm; mp4; #mp4配置,没有做优化 } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html { root html; } }
Player selection Jwplayer
https://www.jwplayer.com PS: Sign up ☑️ check the developer can get JS links; jdk, etc. used to test the free huh ^ ^.
Editing test page:
index.html
<!DOCTYPE heml> <html> <head> <!-- 在这里替换自己的JW Player id --> <script type="text/javascript" src="https://cdn.jwplayer.com/libraries/xxxx.js"></script> <script type="text/javascript" src="getParam.js"></script> <meta http-equiv="Content-Type" content="text/html;charset=utf-8" /> </head> <body bgcolor="#000000"> <div id="myElement">Loading the page...</div> <script type="text/javascript"> var file_name=getParam('id'); console.log(file_name); jwplayer("myElement").setup({ file: "http://x.x.x.x:8081/" + file_name, // image: "data/myposter.jpg", title: file_name, }); </script> </body> </html>
Get file getParam.js
function getParam(paramName) { paramValue = "", isFound = !1; if (this.location.search.indexOf("?") == 0 && this.location.search.indexOf("=") > 1) { arrSource = unescape(this.location.search).substring(1, this.location.search.length).split("&"), i = 0; while (i < arrSource.length && !isFound) arrSource[i].indexOf("=") > 0 && arrSource[i].split("=")[0].toLowerCase() == paramName.toLowerCase() && (paramValue = arrSource[i].split("=")[1], isFound = !0), i++; } return paramValue == "" && (paramValue = null), paramValue; }
Streaming test server on the basic set up ok, the next test:
The following url everyone can play, tomatoes need at the next dig will know.
http://www.agawater.cn/mp4/?id=xzz.mp4
Incidentally a mouth: young nice.
References:
https://www.xiaohulu.com/video/user_detail?plat=201&roomid=61936357840
https://www.cnblogs.com/nopnog/p/7452405.html
https://www.cnblogs.com/vinyuan/p/3556218.html
https://leefige.github.io/2019/03/05/%E5%9F%BA%E4%BA%8ENginx%E9%85%8D%E7%BD%AEWeb%E8%A7%86%E9%A2%91%E6%B5%81%E5%AA%92%E4%BD%93%E6%9C%8D%E5%8A%A1%E5%99%A8/