010-68421378
sales@cogitosoft.com
当前您所在的位置:首页>新闻中心>新品发布

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

发布时间:2021/04/28 浏览量:2281
如何开发一个自定义模块(Module)来检测RTMP输入流

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

下一篇:ASN.1 查看器/编辑器 :用于分析和编辑使用ASN.1编码规则的编码数据
上一篇:Splashtop :网络安全领导者:Mark Lee 对话 Sramana Mitra

                               

 京ICP备09015132号-996网络文化经营许可证京网文[2017]4225-497号 | 违法和不良信息举报电话:4006561155

                                   © Copyright 2000-2023 北京哲想软件有限公司版权所有 | 地址:北京市海淀区西三环北路50号豪柏大厦C2座11层1105室

                         北京哲想软件集团旗下网站:哲想软件 | 哲想动画

                            华滋生物