- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我已经在 Windows 8 系统上安装了 RED5 1.0 Final,并且正在尝试让录音正常工作。我读过的一个教程说要在客户端(在Flash中)缓冲数据,然后一旦缓冲区为空就关闭连接。
我遇到的问题是,当我开始记录缓冲区时,立即报告缓冲区为空(NetStream.Buffer.Empty)。我已经让它工作了一两次,缓冲区确实填满了,但由于某种原因它停止了这种工作方式。
即使我将相机与网络流分离,我也可以看到客户端仍在向服务器发送数据,因为服务器端的文件继续增长。我目前的解决方案是在录制停止后等待 60 秒再关闭连接。
有趣的是,当没有更多数据包要发送时,我在服务器端看到文件从 mystream.ser 切换到 mystream.flv 并停止大小增长。我正在考虑在服务器端编写一些代码来等待此事件发生,然后让客户端知道它可以关闭流。
这是我第一次尝试 ActionScript ,所以我可能在这里做了一些完全错误的事情。请告诉我。
编辑这是客户端代码
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
xmlns:ns1="*"
minWidth="955" minHeight="600" applicationComplete="init()" >
<fx:Script>
<![CDATA[
import flash.display.DisplayObject;
import flash.display.Sprite;
import flash.events.NetStatusEvent;
import flash.media.Camera;
import flash.media.H264Level;
import flash.media.H264Profile;
import flash.media.H264VideoStreamSettings;
import flash.media.Video;
import flash.net.NetConnection;
import flash.net.NetStream;
var cam:Camera = Camera.getCamera();
var mic:Microphone = Microphone.getMicrophone();
var nc:NetConnection = new NetConnection();
var activeStream:NetStream;
private var bufferCheckTimer:Timer;
var recordHalted:Boolean = false;
protected function init(): void{
recordButton.enabled = false;
stopButton.enabled = false;
nc.addEventListener(NetStatusEvent.NET_STATUS, onNetStatus);
nc.connect("rtmp://localhost/oflaDemo");
nc.client = this;
}
public function onMetaData(info:Object):void {
trace("playback called onMetaData");
}
public function onBWDone(... rest) : void {
// have to have this for an RTMP connection
trace('onBWDone');
}
public function onBWCheck(... rest) : uint {
trace('onBWCheck');
//have to return something, so returning anything :)
return 0;
}
protected function onNetStatus(event:NetStatusEvent):void{
trace(event.info.code);
if(nc.connected)
{
SetupCameraAndMic();
recordButton.enabled = true;
stopButton.enabled = true;
}
}
protected function SetupCameraAndMic(): void{
activeStream = new NetStream(nc);
activeStream.bufferTime = 60;
activeStream.client = this;
activeStream.addEventListener(NetStatusEvent.NET_STATUS, handleStreamStatus,false,0,true);
var h264Settings:H264VideoStreamSettings = new H264VideoStreamSettings();
h264Settings.setProfileLevel(H264Profile.BASELINE, H264Level.LEVEL_2);
activeStream.videoStreamSettings = h264Settings;
cam.addEventListener(StatusEvent.STATUS, handleCameraStatus, false, 0, true);
mic.addEventListener(StatusEvent.STATUS, handleMicrophoneStatus, false, 0, true);
cam.setMode(320,240, 15);
cam.setQuality(0, 80);
cam.setKeyFrameInterval(7);
mic.rate = 44;
mic.gain = 75;
mic.setSilenceLevel(0);
mic.setUseEchoSuppression(true);
activeStream.attachCamera(cam);
activeStream.attachAudio(mic);
videoContainer.attachCamera(cam);
}
private function handleCameraStatus(e:StatusEvent):void {
trace("handleCameraStatus - " + e.code);
switch(e.code) {
case 'Camera.muted':
// Show a message
break;
case 'Camera.Unmuted':
//finishCamAndMicSetup();
break;
}
}
private function handleMicrophoneStatus(e:StatusEvent):void {
trace("handleMicrophoneStatus - " + e.code);
switch(e.code) {
case 'Microphone.Muted':
// Show a message
break;
case 'Microphone.Unmuted':
//finishCamAndMicSetup();
break;
}
}
private function handleStreamStatus(e:NetStatusEvent):void {
switch(e.info.code) {
case 'NetStream.Buffer.Empty':
trace("NetStream.Buffer.Empty");
break;
case 'NetStream.Buffer.Full':
trace("NetStream.Buffer.Full");
break;
case 'NetStream.Buffer.Flush':
trace("NetStream.Buffer.Flush");
break;
}
}
protected function recordButton_clickHandler(event:MouseEvent):void
{
if(activeStream == null)
{
SetupCameraAndMic();
}
if(activeStream != null){
var tempDate:Date = new Date();
var uniqueFileName:String = "RecordME_" + String(tempDate.getMinutes()) + String(tempDate.getMilliseconds());
bufferLabel.text = ""+ activeStream.bufferTime;
activeStream.publish(uniqueFileName, "record");
bufferCheckTimer = new Timer(100);
bufferCheckTimer.addEventListener(TimerEvent.TIMER, handleBufferCheck, false, 0, true);
bufferCheckTimer.start();
}
}
private function handleBufferCheck(e:TimerEvent):void {
if(activeStream != null) {
trace("Buffer: " + activeStream.bufferLength);
statusLabel.text = "Buffer: " + activeStream.bufferLength;
if (recordHalted == true) {
if ( activeStream.bufferLength == 0 ) {
activeStream.close();
activeStream = null;
bufferCheckTimer.stop();
bufferCheckTimer.removeEventListener(TimerEvent.TIMER, handleBufferCheck);
bufferCheckTimer = null;
// OK - playback time
//doRecordingPlayback();
}
}
if (bufferCheckTimer != null) {
bufferCheckTimer.reset();
bufferCheckTimer.start();
}
}
}
protected function stopButton_clickHandler(event:MouseEvent):void
{
activeStream.attachCamera(null);
activeStream.attachAudio(null);
videoContainer.attachCamera(null);
recordHalted = true;
}
]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>
<mx:VideoDisplay id="videoContainer" x="158" y="53" width="640" height="480"
chromeColor="#3C2020" />
<s:Button id="recordButton" x="396" y="546" label="Record"
click="recordButton_clickHandler(event)"/>
<s:Button id="stopButton" x="491" y="546" label="Stop Recording"
click="stopButton_clickHandler(event)"/>
<s:Label id="statusLabel" x="158" y="555" width="207"/>
<s:Label x="14" y="408" text="Buffer Set to:"/>
<s:Label id="bufferLabel" x="91" y="408" text="0"/>
</s:Application>
谢谢
最佳答案
我现在没有正在运行的 RTMP 服务器,所以我只是评论我在您的代码中看到的内容。
我认为在发布(记录)流时,您首先得到的关于缓冲内容的建议可能不是一个好主意。也许本教程不是关于发布,而是关于订阅现有流,在这种情况下缓冲是一个好主意。
您将 bufferTime
设置为 60 秒。 docs假设您应该将 bufferTime 设置为 0 以进行现场录音。也就是说,您希望在摄像头/麦克风生成数据后立即发送数据。
接下来是您正在使用的计时器
。这似乎是在检查缓冲区长度,以检测录制是否已停止。实际上只有两种情况会停止录制:
我建议使用您的 NetStatusEvent
处理程序方法 (handleStreamStatus()
) 来检查消息“NetStream.Record.Stop”,而不是使用计时器来检查缓冲区长度
。这允许您的代码检测录制何时因用户单击“停止”之外的其他原因而停止。
计时器可能是导致问题的原因。即使您设置了较大的 bufferTime
值,它也可能无法在 Red 5 服务器上工作或表现不同,或者可能会被服务器端设置覆盖。无论如何,重点是不要使用 bufferLength
来检测录制是否已停止。
有一堆useful messages通过 NetStatusEvent
调度,我建议仔细阅读它们,看看它们是否对您的场景有用。他们非常可靠,似乎可以处理几乎所有可能出现的情况。
我注意到的最后一件事(不是问题,但值得纠正):您在麦克风上启用了回声抑制,但除非您获得增强型麦克风,否则这不会起作用:
var mic:Microphone = Microphone.getEnhancedMicrophone();
关于flash - RED5 1.0 录制问题 NetStream.Buffer.Empty,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13944136/
我期望 new Buffer(buffer.toString()) 始终是逐字节相等的。但是,我遇到的情况并非如此。 首先,这是一个真实的案例: var buf1 = new Buffer(32);
我有用于记录数据的 Protocol Buffer 。 message Message { required double val1 = 1; optional int val2 =
请注意以下简单程序(基于 protobuf-net 项目 v1 wiki 中的示例): using System.Collections.Generic; using System.Diagnosti
在 Protocol Buffer 中,有没有办法让消息包含嵌套消息的集合?例如,消息主管可能有一个员工集合以及主管的姓名和部门。 最佳答案 是的。您使用 repeated领域; message Em
我想知道 Protocol Buffer 在解析流时如何处理损坏的数据。有没有办法知道数据是否已损坏。 Protocol Buffer 是否提供任何内置的数据完整性检查机制? 谢谢, 最佳答案 没有任
Protocol Buffer 如何处理类型版本控制? 例如,当我需要随时间更改类型定义时?就像添加和删除字段一样。 最佳答案 Google 设计的 protobuf 对版本控制非常宽容: 意外数据要
我尝试阅读 Protobuf 文档,但无法想象它可以用于许多用例。我想知道一些实际的 Protocol Buffer 性能改进用例。 谢谢 最佳答案 Protocol buffers 是一个序列化库,
给定 Protocol Buffer 模式和一些数据, Protocol Buffer 序列化是否跨库和语言具有确定性? 基本上,无论使用什么库,我是否可以保证相同的数据总是以相同的方式(直到字节)序
我正在使用一个示例 UWP C++/CX 程序,该程序创建两个 UDP 网络通信线程,它们使用 Windows::Storage::Streams::DataWriter 相互发送数据。和 Windo
我正在使用以下代码 int lenSend = odl->ByteSize(); char* buf = (char *)malloc(lenSend); odl->SerializeToArray(
Protocol Buffer 文档警告说...... You should never add behaviour to the generated classes by inheriting fr
我有一个定义如下的原型(prototype)模式, message User { int64 id = 1; bool email_subscribed = 2; bool sms_
我试图了解 Protocol Buffer 编码方法,将消息转换为二进制(或十六进制)格式时,我无法理解嵌入消息的编码方式。 我猜可能和内存地址有关,但我找不到准确的关系。 这是我所做的。 第 1 步
我需要序列化和反序列化一系列与字节流之间的 Protocol Buffer 消息。有一些预先确定的消息类型。编码类型信息的推荐方法是什么,以便我的应用程序可以知道它应该读取哪种类型? 最佳答案 最常见
与GSON相比, Protocol Buffer (protobuf)的优缺点是什么? 在什么情况下,protobuf比GSON更合适? 对于一个非常笼统的问题,我感到抱歉。 最佳答案 json(通过
message Person { required Empid = 1 [default = 100]; required string name = 2 [default = "Raju"]
我正在研究一个小型设备,该设备具有相当大的一组配置参数(~100 KB),这些参数是从 PC 软件生成的。过去,我们将参数存储在二进制文件中并将它们加载到数据结构中。维护有点烦人(不同的语言,确保结构
来自Encoding - Protocol Buffers - Google Code上的“签名类型”: ZigZag encoding maps signed integers to unsigne
我正在使用 Protocol Buffer ,一切正常。除了我不明白的事实 - 为什么我需要 proto 中的编号标签文件 : message SearchRequest { required s
Protocol Buffer 的吸引人的功能之一是它允许您扩展消息定义,而不会破坏使用较旧定义的代码。对于枚举according to the documentation: a field with
我是一名优秀的程序员,十分优秀!