计算的响应的档案大小? [英] calculating filesize of a response?

查看:214
本文介绍了计算的响应的档案大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

IM来试图code脚本做的视频和音频(可能只是声音现在)的动态转换和流媒体到移动设备上,使用上其他地方在这里张贴的脚本目前IM(<一个href=\"http://stackoverflow.com/questions/1608571/how-do-you-convert-audio-files-on-the-fly-to-the-browser\">http://stackoverflow.com/questions/1608571/how-do-you-convert-audio-files-on-the-fly-to-the-browser)但这种seemsto有问题,因为我不知道如何计算输出的数据文件大小,任何人都可以建议如何我会计算这个动态地,并通过正确的头?

im tryingto code a script to do dynamic transcoding of video and audio (likely just audio for now) and streaming to mobile devices, currently im using the script posted elsewhere on here (http://stackoverflow.com/questions/1608571/how-do-you-convert-audio-files-on-the-fly-to-the-browser) but this seemsto have problems as i do not know how to calculate the filesize of the outputted data, can anyone suggest how i might calculate this dynamicly and pass the correct header?

推荐答案

(更新了最终解决方案在回答底部的具体问题。)

音频和视频编码,在这种情况下,(和大多数其他人),而不是predictable当涉及到确切的文件的大小。请记住一个事实,即对最终文件大小的源材料的特点和影响不能同时既编码pdicted $ P $。如果您是飞转码,你正在做的两件事情1)COM pressing,2)丢失数据。它只是不能带MP3输出格式来实现。

Audio and video encoding is, in this case (and most others), not predictable when it comes to the exact resulting file size. Remember the fact that your source material's characteristic and impact on the final file size cannot be predicted while encoding either. If you are transcoding 'on the fly', you are doing two things 1) compressing, 2) losing data. It just cannot be done with an mp3 output format.

你会......如果:编码是无损的,和你的算法调整到非常具体的源材料特性(采样率,样品量等)以及源和目标格式都在那里uncom pressed。但是,这不是你的情况。

You might...if: the encoding was lossless, and your algorithm was tuned to very specific source material characteristics (sample rate, sample size, etc.) and both the source and target formats where uncompressed. But that is not your situation.

至于标题:不要送呢!在的Content-Length 头不是HTTP 1.1的要求。有缺点这个(进度条永远不能知道,直到结束的文件做什么100%;无'剩余时间'可能不是),但我的猜测是,你可以没有它

As for the header: don't sent it! The Content-Length header is not an HTTP 1.1 requirement. There are disadvantages to this (progress bars cannot ever know what 100% done until end-of-file; no 'time remaining' is possible either) but my guess is you can live without it.


根据反馈意见的讨论:

Final discussion based on comments:

通过一个浏览器,我得到你所描述的行为。而与此curl命令(用于调试这样的低水平疼痛有用),它也不会工作:

With a browser, I get the behavior you are describing. And with with this curl command (helpful for debugging low level pain like this), it also does not work:

curl --trace-ascii trace0.txt "http://dmpwap.net/playmp3.php?b=128&file=Red_Hot_Chili_Peppers_-_15_-_Fortune_Faded.mp3" > test0.mp3

我得到0字节,看到这个在我的跟踪:

I get 0 bytes, and see this in my trace:

manoa:~ stu$ cat trace0.txt == Info: About to connect() to dmpwap.net port 80 (#0)
== Info:   Trying 64.191.50.69... == Info: connected
== Info: Connected to dmpwap.net (64.191.50.69) port 80 (#0)
=> Send header, 213 bytes (0xd5)
0000: GET /playmp3.php?b=128&file=Red_Hot_Chili_Peppers_-_15_-_Fortune
0040: _Faded.mp2 HTTP/1.1
0055: User-Agent: curl/7.19.4 (universal-apple-darwin10.0) libcurl/7.1
0095: 9.4 OpenSSL/0.9.8k zlib/1.2.3
00b4: Host: dmpwap.net
00c6: Accept: */*
00d3: 
<= Recv header, 17 bytes (0x11)
0000: HTTP/1.1 200 OK
<= Recv header, 19 bytes (0x13)
0000: Connection: close
<= Recv header, 37 bytes (0x25)
0000: Date: Fri, 11 Dec 2009 14:04:58 GMT
<= Recv header, 27 bytes (0x1b)
0000: Server: Microsoft-IIS/6.0
<= Recv header, 27 bytes (0x1b)
0000: X-Powered-By: PHP/5.2.9-2
<= Recv header, 35 bytes (0x23)
0000: Content-Transfer-Encoding: binary
<= Recv header, 26 bytes (0x1a)
0000: Content-Type: audio/mpeg
<= Recv header, 2 bytes (0x2)
0000: 
<= Recv data, 0 bytes (0x0)
== Info: Closing connection #0

但是....

如果我添加一个 - TCP-NODELAY 选项,的只是正常工作的!例如:

curl --tcp-nodelay --trace-ascii trace1.txt "http://dmpwap.net/playmp3.php?b=128&file=Red_Hot_Chili_Peppers_-_15_-_Fortune_Faded.mp3" > test1.mp3

这回3219104字节。该trace.txt看起来是这样的:

It returned 3219104 bytes. The trace.txt looks like this:

== Info: About to connect() to dmpwap.net port 80 (#0)
== Info:   Trying 64.191.50.69... == Info: TCP_NODELAY set
== Info: connected
== Info: Connected to dmpwap.net (64.191.50.69) port 80 (#0)
=> Send header, 213 bytes (0xd5)
0000: GET /playmp3.php?b=128&file=Red_Hot_Chili_Peppers_-_15_-_Fortune
0040: _Faded.mp3 HTTP/1.1
0055: User-Agent: curl/7.19.4 (universal-apple-darwin10.0) libcurl/7.1
0095: 9.4 OpenSSL/0.9.8k zlib/1.2.3
00b4: Host: dmpwap.net
00c6: Accept: */*
00d3: 
<= Recv header, 17 bytes (0x11)
0000: HTTP/1.1 200 OK
<= Recv header, 19 bytes (0x13)
0000: Connection: close
<= Recv header, 37 bytes (0x25)
0000: Date: Fri, 11 Dec 2009 13:56:47 GMT
<= Recv header, 27 bytes (0x1b)
0000: Server: Microsoft-IIS/6.0
<= Recv header, 27 bytes (0x1b)
0000: X-Powered-By: PHP/5.2.9-2
<= Recv header, 35 bytes (0x23)
0000: Content-Transfer-Encoding: binary
<= Recv header, 26 bytes (0x1a)
0000: Content-Type: audio/mpeg
<= Recv header, 2 bytes (0x2)
0000: 
<= Recv data, 1258 bytes (0x4ea)
0000: ID3.......TENC.......Lavf52.23.1...d.... ..=....w......oq......0
   ...  {many lines}
0180: UUUUUU
== Info: Closing connection #0

我可以听这首歌(3m21s,音响,MPGA,48kHz的,128kbps的),没有任何问题。

I can listen to the song (3m21s, stereo, mpga, 48kHz, 128kbps) with no problems.

所以,我的理论是,因为有连续的0×00字节流中,客户端都在思考的OK,我得到了0×00,0×00 ......没有别的已发送,该连接必须通过。的但与 - TCP-NODELAY 选项卷曲客户端设置,它不会发生。

So, my theory is, that because there are consecutive 0x00 bytes in the stream, the clients are thinking "OK, I got 0x00, 0x00...and nothing else has been sent, the connection must be over." But with the --tcp-nodelay option set on the curl client, it does not happen.

我的候选解决方案:停用格尔的算法 (设定的TCP套接字选项无延迟)服务器侧,至少对这些转码请求的连接。这将prevent缓冲,我怀疑是导致连接被丢弃。

My candidate solution: Disable Nagel's algorithm (set TCP no delay on socket options) server side, at least for these transcoding request connections. This will prevent buffering, which I suspect is leading to the connections being dropped.

这篇关于计算的响应的档案大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆