這篇文章介紹了如何開(kāi)發(fā)一個(gè)自定義模塊(Module)來(lái)檢測(cè)RTMP輸入流,并計(jì)算它的視頻幀率。

請(qǐng)參考下面的代碼:
注意: 這個(gè)例子中用到的API只能在Wowza Streaming Engine™ 4.0 及以上版本使用。
packagecom.wowza.wms.example;
importcom.wowza.wms.amf.AMFDataList;
import com.wowza.wms.amf.AMFPacket;
importcom.wowza.wms.application.IApplicationInstance;
importcom.wowza.wms.client.IClient;
importcom.wowza.wms.module.ModuleBase;
importcom.wowza.wms.request.RequestFunction;
importcom.wowza.wms.stream.IMediaStream;
import com.wowza.wms.stream.IMediaStreamLivePacketNotify;
public classModuleLiveFrameRate extends ModuleBase
{
class PacketListener implementsIMediaStreamLivePacketNotify
{
/**
* onLivePacket is called forevery packet that is received for the live stream before the packet isprocessed for playback.
* It is very important that thismethod returns quickly and is not delayed in any way.
*/
@Override
public voidonLivePacket(IMediaStream stream, AMFPacket packet)
{
if (packet.isVideo())
{
//packet.getTimecode(); returns the elapsed time, in milliseconds, between thispacket and the last packet of the same type.
double fps =(double)1000 / packet.getTimecode();
stream.getProperties().setProperty("currentFPS",new Double(fps));
}
}
}
private PacketListener packetListener =new PacketListener();
private IApplicationInstanceappInstance;
public voidonAppStart(IApplicationInstance appInstance)
{
this.appInstance = appInstance;
}
public void onStreamCreate(IMediaStreamstream)
{
stream.addLivePacketListener(packetListener);
}
public void onStreamDestroy(IMediaStreamstream)
{
stream.removeLivePacketListener(packetListener);
}
public void getCurrentFPS(IClientclient, RequestFunction function, AMFDataList params)
{
double fps = 0;
String streamName =getParamString(params, PARAM1);
if (streamName != null)
{
fps =getCurrentFPS(streamName);
}
sendResult(client, params, fps);
}
public double getCurrentFPS(StringstreamName)
{
double fps = 0;
IMediaStream stream =appInstance.getStreams().getStream(streamName);
if (stream != null)
{
fps =stream.getProperties().getPropertyDouble("currentFPS", fps);
}
return fps;
}
}
Wowza Streaming Engine 4是業(yè)界功能強(qiáng)大、API接口豐富的流媒體Server產(chǎn)品,采用它作為流媒體服務(wù)器產(chǎn)品的案例很多,直播、在線教育、IPTV都有它的用武之地。
京ICP備09015132號(hào)-996 | 違法和不良信息舉報(bào)電話:4006561155
© Copyright 2000-2026 北京哲想軟件有限公司版權(quán)所有 | 地址:北京市海淀區(qū)西三環(huán)北路50號(hào)豪柏大廈C2座11層1105室
北京哲想軟件集團(tuán)旗下網(wǎng)站:哲想軟件 | 哲想動(dòng)畫