使用 NetStream 类如何检测是否附加了工作视频?
我正在 Flash 中构建视频聊天,除了我试图检测其他用户是否正在发送工作视频流的部分之外,一切都运行良好。
其他用户不发送视频的原因有多种。
- 其他用户没有摄像头
- 其他用户有摄像头,但该摄像头当前被另一个应用程序占用(Skype、Photo Booth、Google Talk 等)
- 其他用户有摄像头,但不允许使用他的摄像头/她的相机。
- (我猜是其他意外问题...)
那么,如何使用 NetStream 类检测从其他用户收到的流是否是黑流(由于上述原因)?
我想出的最接近的方法是添加一个计时器,该计时器从我从其他用户收到的流中轮询 currentFps() 函数。但到目前为止,这似乎相当不可靠,因为我可能会得到 currentFps() == 0 并因此显示错误,即使在某些情况下我实际上从流中获取了视频。这样做的原因是因为我每 4 秒轮询一次 API 的 currentFPS 函数,假设在 00:00:04 根据轮询我得到“无视频”,但在 00:00:05 视频开始播放,因此我需要等到下一个刻度线,直到错误消息消失
这就是我当前的民意调查的样子
function subscribingStatusPoll(e:TimerEvent):void {
if (subscribingStream.currentFPS == 0){
error.text = "No video found from the other user..."
} else {
error.text = "";
}
}
这是我可以想出的唯一黑客来检测此问题,但是这个是不可靠的,实际上我更喜欢一种方法来立即检测我收到的流是否附加了工作视频,而无需进行这种丑陋的民意调查。
I'm building a video chat in flash and everything works really well, except for the part where I'm trying to detect if the other user is sending a working video stream.
There's a couple of reasons why the other user isn't sending video.
- The other user got no camera
- The other user got a camera, but the camera is currently being occupied by another application(Skype, Photo Booth, Google Talk, etc.)
- The other user got a camera but hasn't allowed the use of his/hers camera.
- (Other unexpected problems I guess...)
So how do I detect if the stream I receive from the other user is a black stream(because of the reasons above) using the NetStream class?
The closest thing I have came up with is by adding a timer that polls the currentFps() function from the stream I receive from the other user. But so far this seems pretty unreliable because I might get currentFps() == 0
and show an error because of this even though I actually got video from the stream in some cases. The reason for this is because I poll the API every 4 seconds for the currentFPS function and let's say at 00:00:04 I get "no video" according to the poll but at 00:00:05 the video kicks in, and therefor I need to wait until the next tick until the error message disappears
This is what my current poll looks like
function subscribingStatusPoll(e:TimerEvent):void {
if (subscribingStream.currentFPS == 0){
error.text = "No video found from the other user..."
} else {
error.text = "";
}
}
This is the only hack I that I can come up with to detect this, but this is unreliable and I actually would prefer a way to instantly detect if the stream I receive got a working video attached to it without this ugly poll.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
虽然我同意不从服务器端发送“空白”流,但您可能无权访问服务器端,因此它不适用于您的情况。在客户端,您可以按一定时间间隔从流中抓取一帧并检查更改或仅查看时间戳(查找随时间的推移而增加的情况)。这些选项可能看起来很麻烦,但它们绝对应该在 Flash 中工作。
如果我必须自己开发这个,我会从这个边缘检测代码开始,并将网络摄像头抓取替换为播放流中的帧抓取。
http://www.laserpirate.com/as3edgeandmotion/
While I would agree with not sending a "blank" stream from the server-side, you may not have access to the server-side and thus it would not apply to your situation. On the client-side you could grab a frame from the stream at an interval and check for changes or just look at the timestamps (look for an increase over time). These options may seem hack-ish but they should definitely work in Flash.
If I had to develop this myself, I would start with this edge detection code and replace the webcam grab with a frame grab from the playing stream.
http://www.laserpirate.com/as3edgeandmotion/
错误的方法。
尽管在接收端验证数据是一个好主意,但无法检测流是否是真实数据。
在您的情况下,正在发送的流不是真正的相机流,但它仍然是一个流。
没有检测到这一点。
为什么不在发送客户端上处理验证呢?
Wrong approach.
As much as validating the data on the receiving end is a great idea there is no way to detect if a stream is real data or not.
In your case the stream that is being sent is not a true camera stream but it is a stream none-the-less.
There is no detection for this.
Why not just handle validating on the sending client?