使用 lighttpd 流式传输时,视频文件具有不同的大小

A video file has different sizes when it streams with lighttpd

我正在使用 wget 下载数学讲座视频。我不小心按了 Ctrl+C 并继续 wget --continue。在这里,我注意到服务器响应了具有不同文件大小的文件。服务器使用 lighttpd.

我想知道为什么 lighttpd 对同一文件使用不同的文件大小进行响应?

服务器响应如下。

第一次尝试:

$ wget -S http://www.server.com/lecture11940.mp4

--2015-07-23 20:04:28--  http://www.server.com/lecture/11940.mp4
Resolving www.server.com... 1.2.3.4
Connecting to www.server.com|1.2.3.4|:80... connected.
HTTP request sent, awaiting response... 
  HTTP/1.1 302 Found
  Date: Thu, 23 Jul 2015 18:03:33 GMT
  Server: Apache
  Location: http://www.server.com:8080/lecture11940.mp4
  Vary: Accept-Encoding
  Content-Length: 239
  Keep-Alive: timeout=15, max=100
  Connection: Keep-Alive
  Content-Type: text/html; charset=iso-8859-1
Location: http://www.server.com:8080/lecture11940.mp4 [following]

重定向:

--2015-07-23 20:04:35--  http://www.server.com:8080/lecture11940.mp4

Connecting to www.server.com|1.2.3.4|:8080... connected.
HTTP request sent, awaiting response... 
  HTTP/1.1 200 OK
  X-Mod-H264-Streaming: version=2.2.9
  Content-Type: video/mp4
  ETag: "745841726"
  Last-Modified: Thu, 23 Jul 2015 12:24:08 GMT
  Content-Length: 533771778
  Date: Thu, 23 Jul 2015 18:03:36 GMT
  Server: lighttpd/1.4.19
Length: 533771778 (509M) [video/mp4]
Saving to: '11940.mp4'

第二次尝试:

$ wget -S --continue http://www.server.com/lecture11940.mp4

--2015-07-23 20:04:51--  http://www.server.com/lecture11940.mp4
Resolving www.server.com... 1.2.3.4
Connecting to www.server.com|1.2.3.4|:80... connected.
HTTP request sent, awaiting response... 
  HTTP/1.1 302 Found
  Date: Thu, 23 Jul 2015 18:03:49 GMT
  Server: Apache
  Location: http://www.server.com:8080/lecture11940.mp4
  Vary: Accept-Encoding
  Content-Length: 239
  Keep-Alive: timeout=15, max=100
  Connection: Keep-Alive
  Content-Type: text/html; charset=iso-8859-1
Location: http://www.server.com:8080/lecture11940.mp4 [following]

重定向:

--2015-07-23 20:04:51--  http://www.server.com:8080/lecture11940.mp4

Connecting to www.server.com|1.2.3.4|:8080... connected.
HTTP request sent, awaiting response... 
  HTTP/1.1 206 Partial Content
  Expires: Thu, 23 Jul 2015 22:03:49 GMT
  Cache-Control: max-age=14400
  Content-Type: video/mp4
  Accept-Ranges: bytes
  ETag: "1834748875"
  Last-Modified: Thu, 23 Jul 2015 12:24:08 GMT
  Content-Range: bytes 122057-533786493/533786494
  Content-Length: 533664437
  Date: Thu, 23 Jul 2015 18:03:49 GMT
  Server: lighttpd/1.4.19
Length: 533786494 (509M), 533664437 (509M) remaining [video/mp4]
Saving to: '11940.mp4'

初始wget请求响应为H264 Streaming,表示为

X-Mod-H264-Streaming: version=2.2.9

而对第二个 wget 请求(wget --continue,Range 请求)的响应是对文件一部分的字节范围响应(不是 H264 流),表示为

Content-Range: bytes 122057-533786493/533786494

这是lighttpd的视频流机制。 Here have some discuss

When a Range Request header is present, the request is forwarded to the >mod_staticfile module and the H264 module is skipped.

When there is no range request header, the file is processed by the H264 >module and may differ in size from the original as it rewrites the headers (and/or moves the moov atom to the front of the file, etc...).