{"id":49766,"date":"2024-10-08T07:19:14","date_gmt":"2024-10-07T23:19:14","guid":{"rendered":"https:\/\/server.hk\/cnblog\/49766\/"},"modified":"2024-10-08T07:19:14","modified_gmt":"2024-10-07T23:19:14","slug":"nginx-%e6%8a%80%e5%b7%a7%ef%bc%9a%e5%af%a6%e7%8f%be-ngx_http_mp4_module-%e9%80%b2%e8%a1%8c-mp4-%e6%b5%81","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/49766\/","title":{"rendered":"Nginx \u6280\u5de7\uff1a\u5be6\u73fe ngx_http_mp4_module \u9032\u884c MP4 \u6d41"},"content":{"rendered":"<h1 id=\"nginx-%e6%8a%80%e5%b7%a7%ef%bc%9a%e5%af%a6%e7%8f%be-ngx_http_mp4_module-%e9%80%b2%e8%a1%8c-mp4-%e6%b5%81-qlEgxeUEYO\">Nginx \u6280\u5de7\uff1a\u5be6\u73fe ngx_http_mp4_module \u9032\u884c MP4 \u6d41<\/h1>\n<p>Nginx \u662f\u4e00\u6b3e\u9ad8\u6548\u80fd\u7684\u7db2\u9801\u4f3a\u670d\u5668\uff0c\u5ee3\u6cdb\u61c9\u7528\u65bc\u975c\u614b\u5167\u5bb9\u7684\u63d0\u4f9b\u548c\u53cd\u5411\u4ee3\u7406\u3002\u96a8\u8457\u8996\u983b\u5167\u5bb9\u7684\u666e\u53ca\uff0c\u8a31\u591a\u7db2\u7ad9\u9700\u8981\u652f\u6301\u8996\u983b\u6d41\u5a92\u9ad4\u7684\u64ad\u653e\u3002\u9019\u6642\uff0cNginx \u7684 <code>ngx_http_mp4_module<\/code> \u6a21\u7d44\u4fbf\u6210\u70ba\u4e86\u4e00\u500b\u7406\u60f3\u7684\u9078\u64c7\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u5982\u4f55\u5229\u7528\u6b64\u6a21\u7d44\u5be6\u73fe MP4 \u6d41\u5a92\u9ad4\u7684\u64ad\u653e\uff0c\u4e26\u63d0\u4f9b\u4e00\u4e9b\u5be6\u7528\u7684\u914d\u7f6e\u6280\u5de7\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af-ngx_http_mp4_module%ef%bc%9f-qlEgxeUEYO\">\u4ec0\u9ebc\u662f ngx_http_mp4_module\uff1f<\/h2>\n<p><code>ngx_http_mp4_module<\/code> \u662f Nginx \u7684\u4e00\u500b\u6a21\u7d44\uff0c\u5c08\u9580\u7528\u65bc\u8655\u7406 MP4 \u683c\u5f0f\u7684\u8996\u983b\u6587\u4ef6\u3002\u5b83\u652f\u6301 HTTP \u5354\u8b70\u7684\u7bc4\u570d\u8acb\u6c42\uff0c\u9019\u610f\u5473\u8457\u7528\u6236\u53ef\u4ee5\u5f9e\u8996\u983b\u7684\u4efb\u610f\u4f4d\u7f6e\u958b\u59cb\u64ad\u653e\uff0c\u800c\u4e0d\u5fc5\u5f9e\u982d\u958b\u59cb\u4e0b\u8f09\u6574\u500b\u6587\u4ef6\u3002\u9019\u5c0d\u65bc\u7528\u6236\u9ad4\u9a57\u81f3\u95dc\u91cd\u8981\uff0c\u7279\u5225\u662f\u5728\u7db2\u7d61\u901f\u5ea6\u4e0d\u7a69\u5b9a\u7684\u60c5\u6cc1\u4e0b\u3002<\/p>\n<h2 id=\"%e5%ae%89%e8%a3%9d-nginx-%e5%92%8c-ngx_http_mp4_module-qlEgxeUEYO\">\u5b89\u88dd Nginx \u548c ngx_http_mp4_module<\/h2>\n<p>\u5728\u4f7f\u7528 <code>ngx_http_mp4_module<\/code> \u4e4b\u524d\uff0c\u9996\u5148\u9700\u8981\u78ba\u4fdd Nginx \u5df2\u7d93\u5b89\u88dd\u4e26\u4e14\u8a72\u6a21\u7d44\u5df2\u7d93\u555f\u7528\u3002\u5927\u591a\u6578 Nginx \u7684\u9810\u7de8\u8b6f\u7248\u672c\u90fd\u5df2\u7d93\u5305\u542b\u4e86\u9019\u500b\u6a21\u7d44\uff0c\u4f46\u5982\u679c\u4f60\u662f\u5f9e\u6e90\u78bc\u7de8\u8b6f Nginx\uff0c\u5247\u9700\u8981\u5728\u7de8\u8b6f\u6642\u6dfb\u52a0 <code>--with-http_mp4_module<\/code> \u53c3\u6578\u3002<\/p>\n<pre><code>.\/configure --with-http_mp4_module\nmake\nmake install\n<\/code><\/pre>\n<h2 id=\"%e9%85%8d%e7%bd%ae-nginx-%e4%bb%a5%e6%94%af%e6%8c%81-mp4-%e6%b5%81-qlEgxeUEYO\">\u914d\u7f6e Nginx \u4ee5\u652f\u6301 MP4 \u6d41<\/h2>\n<p>\u4e00\u65e6 Nginx \u5b89\u88dd\u5b8c\u6210\uff0c\u63a5\u4e0b\u4f86\u9700\u8981\u9032\u884c\u914d\u7f6e\u4ee5\u652f\u6301 MP4 \u6d41\u3002\u4ee5\u4e0b\u662f\u4e00\u500b\u57fa\u672c\u7684\u914d\u7f6e\u7bc4\u4f8b\uff1a<\/p>\n<pre><code>server {\n    listen 80;\n    server_name example.com;\n\n    location \/videos\/ {\n        root \/path\/to\/your\/videos;\n        mp4;\n    }\n}\n<\/code><\/pre>\n<p>\u5728\u9019\u500b\u914d\u7f6e\u4e2d\uff0c<code>server_name<\/code> \u6307\u5b9a\u4e86\u4f3a\u670d\u5668\u7684\u57df\u540d\uff0c\u800c <code>location<\/code> \u6307\u4ee4\u5247\u544a\u8a34 Nginx \u5728\u8a2a\u554f <code>\/videos\/<\/code> \u8def\u5f91\u6642\uff0c\u5f9e\u6307\u5b9a\u7684\u76ee\u9304\u4e2d\u63d0\u4f9b\u8996\u983b\u6587\u4ef6\u3002<code>mp4;<\/code> \u6307\u4ee4\u5247\u555f\u7528\u4e86 MP4 \u6d41\u7684\u652f\u6301\u3002<\/p>\n<h2 id=\"%e7%af%84%e5%9c%8d%e8%ab%8b%e6%b1%82%e7%9a%84%e6%94%af%e6%8c%81-qlEgxeUEYO\">\u7bc4\u570d\u8acb\u6c42\u7684\u652f\u6301<\/h2>\n<p>\u70ba\u4e86\u5be6\u73fe\u66f4\u597d\u7684\u7528\u6236\u9ad4\u9a57\uff0c\u5efa\u8b70\u555f\u7528\u7bc4\u570d\u8acb\u6c42\u3002\u9019\u53ef\u4ee5\u901a\u904e\u5728 <code>location<\/code> \u5340\u584a\u4e2d\u6dfb\u52a0\u4ee5\u4e0b\u6307\u4ee4\u4f86\u5be6\u73fe\uff1a<\/p>\n<pre><code>location \/videos\/ {\n    root \/path\/to\/your\/videos;\n    mp4;\n    add_header Accept-Ranges bytes;\n}\n<\/code><\/pre>\n<p>\u9019\u6a23\uff0c\u7576\u7528\u6236\u8acb\u6c42\u8996\u983b\u7684\u67d0\u4e00\u90e8\u5206\u6642\uff0cNginx \u5c07\u80fd\u5920\u6b63\u78ba\u5730\u8655\u7406\u9019\u4e9b\u8acb\u6c42\uff0c\u4e26\u8fd4\u56de\u76f8\u61c9\u7684\u6578\u64da\u3002<\/p>\n<h2 id=\"%e4%bd%bf%e7%94%a8-html5-%e6%92%ad%e6%94%be%e5%99%a8%e6%92%ad%e6%94%be-mp4-%e6%b5%81-qlEgxeUEYO\">\u4f7f\u7528 HTML5 \u64ad\u653e\u5668\u64ad\u653e MP4 \u6d41<\/h2>\n<p>\u70ba\u4e86\u5728\u7db2\u9801\u4e0a\u64ad\u653e MP4 \u6d41\uff0c\u53ef\u4ee5\u4f7f\u7528 HTML5 \u7684 <code>&lt;video&gt;<\/code> \u6a19\u7c64\u3002\u4ee5\u4e0b\u662f\u4e00\u500b\u7c21\u55ae\u7684\u793a\u4f8b\uff1a<\/p>\n<pre><code>&lt;video controls&gt;\n    &lt;source src=\"http:\/\/example.com\/videos\/sample.mp4\" type=\"video\/mp4\"&gt;\n    Your browser does not support the video tag.\n&lt;\/video&gt;\n<\/code><\/pre>\n<p>\u9019\u6bb5\u4ee3\u78bc\u5c07\u5728\u7db2\u9801\u4e0a\u5d4c\u5165\u4e00\u500b\u8996\u983b\u64ad\u653e\u5668\uff0c\u4e26\u5141\u8a31\u7528\u6236\u63a7\u5236\u64ad\u653e\u3002<\/p>\n<h2 id=\"%e7%b8%bd%e7%b5%90-qlEgxeUEYO\">\u7e3d\u7d50<\/h2>\n<p>\u901a\u904e\u4f7f\u7528 Nginx \u7684 <code>ngx_http_mp4_module<\/code>\uff0c\u7db2\u7ad9\u7ba1\u7406\u54e1\u53ef\u4ee5\u8f15\u9b06\u5be6\u73fe MP4 \u6d41\u5a92\u9ad4\u7684\u64ad\u653e\uff0c\u63d0\u5347\u7528\u6236\u9ad4\u9a57\u3002\u6b63\u78ba\u7684\u914d\u7f6e\u4e0d\u50c5\u80fd\u652f\u6301\u7bc4\u570d\u8acb\u6c42\uff0c\u9084\u80fd\u78ba\u4fdd\u8996\u983b\u7684\u6d41\u66a2\u64ad\u653e\u3002\u5c0d\u65bc\u9700\u8981\u9ad8\u6548\u80fd\u8996\u983b\u670d\u52d9\u7684\u7db2\u7ad9\uff0c\u9078\u64c7\u5408\u9069\u7684 <a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a> \u65b9\u6848\u5c07\u662f\u660e\u667a\u4e4b\u8209\uff0c\u56e0\u70ba\u5b83\u80fd\u63d0\u4f9b\u7a69\u5b9a\u7684\u6027\u80fd\u548c\u9748\u6d3b\u7684\u8cc7\u6e90\u914d\u7f6e\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u63a2\u7d22 Nginx \u6280\u5de7\uff0c\u5b78\u7fd2\u5982\u4f55\u4f7f\u7528 ngx_http_mp4_module \u5be6\u73fe\u9ad8\u6548\u7684 MP4 \u6d41\u5a92\u9ad4\u64ad\u653e\uff0c\u63d0\u5347\u7528\u6236\u9ad4\u9a57\u3002<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4924],"tags":[],"class_list":["post-49766","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/49766","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=49766"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/49766\/revisions"}],"predecessor-version":[{"id":49767,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/49766\/revisions\/49767"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=49766"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=49766"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=49766"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}