这篇文章介绍了如何开发一个自定义模块(Module)来检测RTMP输入流,并计算它的视频帧率。
请参考下面的代码:
注意: 这个例子中用到的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是业界功能强大、API接口丰富的流媒体Server产品,采用它作为流媒体服务器产品的案例很多,直播、在线教育、IPTV都有它的用武之地。
京ICP备09015132号-996 | 网络文化经营许可证京网文[2017]4225-497号 | 违法和不良信息举报电话:4006561155
© Copyright 2000-2023 北京哲想软件有限公司版权所有 | 地址:北京市海淀区西三环北路50号豪柏大厦C2座11层1105室