当前您所在的位置:首页>新闻中心>新品发布
新品发布
行业动态
营销活动

如何用Wowza自定义模块计算一个RTMP输入流的帧率?

发布时间:2020/12/08 浏览量:1992

这篇文章介绍了如何开发一个自定义模块(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都有它的用武之地。

北京哲想软件有限公司