基于WOWZA的录制开发和rtsp流的发布:
public class WowzaLiveStreamRecord extends HTTProvider2Base {
private static final Class<WowzaLiveStreamRecord> CLASS = WowzaLiveStreamRecord.class;
public void onHTTPRequest(IVHost vhost, IHTTPRequest req, IHTTPResponse resp) {
if (!doHTTPAuthentication(vhost, req, resp))
return;
IApplication application=vhost.getApplication("live");
IApplicationInstance appInstance=application.getAppInstance("_definst_");
OutputStream out = resp.getOutputStream();
String action=req.getParameter("action");
String fileformat=req.getParameter("fileformat");
String filepath=req.getParameter("filepath");
String parameters=req.getParameter("parameters");
StringBuffer resstr=new StringBuffer();
WowzaDaoImpl wowza=new WowzaDaoImpl();
try{
if(action==null || action.equals("")){
Common.setRetInfo(resstr,"","fail","action is required");
out.write(resstr.toString().getBytes());
resstr=null;
return;
}
if(action.equals("startRecording") || action.equals("stopRecording") || action.equals("streamInfo")){
if(parameters==null || parameters.equals("")){
Common.setRetInfo(resstr,"","fail","parameters is required");
out.write(resstr.toString().getBytes());
resstr=null;
return;
}
List l=Common.jsonToList(parameters,Response.class);
for(int i=0;i<l.size();i++){
Response p=(Response)l.get(i);
String streamname=p.getStreamname();
if(streamname==null || streamname.equals("")){
Common.setRetInfo(resstr,"","fail","streamname is required");
out.write(resstr.toString().getBytes());
resstr=null;
return;
}
}
for(int j=0;j<l.size();j++){
Response p=(Response)l.get(j);
String streamname=p.getStreamname();
//开始录制
if(action.equals("startRecording")){
String filename=p.getFilename();
if(filename==null || filename.equals("")) filename=Common.getFileName();
StreamRecorderParameters recordParams = new StreamRecorderParameters(appInstance);
if(fileformat==null ||fileformat.equals("")) fileformat="1";
if(filepath!=null && !filepath.equals("")){
recordParams.outputPath=filepath;
//若文件路径不存在,自行建立
File fDir = new File(filepath);
if (!fDir.exists()) {
fDir.mkdir();
}
File file = new File(filepath);
if(!file.exists()) file.mkdirs();
}
if(fileformat.equals("1")) recordParams.fileFormat=IStreamRecorderConstants.FORMAT_FLV;
if(fileformat.equals("2")) recordParams.fileFormat=IStreamRecorderConstants.FORMAT_MP4;
recordParams.outputFile=filename;
recordParams.segmentationType = IStreamRecorderConstants.SEGMENT_NONE;
recordParams.versioningOption = IStreamRecorderConstants.OVERWRITE_FILE;
IStreamRecorder rec=vhost.getLiveStreamRecordManager().getRecorder(appInstance,streamname);
if(rec==null){
vhost.getLiveStreamRecordManager().startRecording(appInstance,streamname,recordParams);
Common.setRetInfo(resstr,streamname,"succ","");
}else{
Common.setRetInfo(resstr,streamname,"fail","record stream exist");
}
resstr.append(",");
}
//结束录制
if(action.equals("stopRecording")){
IStreamRecorder rec=vhost.getLiveStreamRecordManager().getRecorder(appInstance,streamname);
if(rec==null){//判断是否有录制流
Common.setRetStreamInfo(resstr,streamname, "","record stream not exist", "", "");
resstr.append(",");
continue;
}
wowza.streamInfo(rec,resstr);
resstr.append(",");
vhost.getLiveStreamRecordManager().stopRecording(appInstance,streamname);
}
//流信息查询
if(action.equals("streamInfo")){
IStreamRecorder rec=vhost.getLiveStreamRecordManager().getRecorder(appInstance,streamname);
if(rec==null){//判断是否有录制流
Common.setRetStreamInfo(resstr,streamname, "","record stream not exist", "", "");
resstr.append(",");
continue;
}
wowza.streamInfo(rec,resstr);
resstr.append(",");
}
}
String resstrs=resstr.toString();
if(!resstrs.toString().equals("")) resstrs=resstrs.substring(0,resstrs.length()-1);
out.write(resstrs.getBytes());
resstr=null;
}
//录制流列表
if(action.equals("streamRecordList")){
List lx=vhost.getLiveStreamRecordManager().getRecordersList(appInstance);
for(int i=0;i<lx.size();i++){
IStreamRecorder rec=(IStreamRecorder)lx.get(i);
if(rec.getStream()==null){//判断是否有录制流
Common.setRetStreamInfo(resstr,rec.getStreamName(), "","record stream not exist", "", "");
resstr.append(",");
continue;
}
wowza.streamInfo(rec,resstr);
resstr.append(",");
}
String resstrs=resstr.toString();
if(!resstrs.toString().equals("")) resstrs=resstrs.substring(0,resstrs.length()-1);
out.write(resstrs.getBytes());
resstr=null;
}
// 添加流文件,0文件已存在,1添加成功
if(action.toLowerCase().equals("addstreamfile")){
String filesName = req.getParameter("filesName");
String url = req.getParameter("url");
String streamFilePath = new File(appInstance.getStreamStoragePath()).getAbsolutePath() + "/" + filesName;
File streamFile = new File(streamFilePath);
if(streamFile.exists()) {// 流文件存在
out.write("0".getBytes());
} else {
BufferedWriter bos = new BufferedWriter(new FileWriter(streamFile));
bos.write(url);
bos.flush();
bos.close();
out.write("1".getBytes());
}
}
// 删除流文件,0流文件不存在,1删除成功
if(action.toLowerCase().equals("delstreamfile")){
String filesName = req.getParameter("filesName");
appInstance.stopMediaCasterStream(filesName);
String streamFilePath = new File(appInstance.getStreamStoragePath()).getAbsolutePath() + "/" + filesName;
File streamFile = new File(streamFilePath);
if(!streamFile.exists()) {// 流文件不存在
out.write("0".getBytes());
} else {
streamFile.delete();
out.write("1".getBytes());
}
}
// 发布流文件,0发布失败,1发布成功
if(action.toLowerCase().equals("startstreamfile")){
String filesName = req.getParameter("filesName");
String streamFilePath = new File(appInstance.getStreamStoragePath()).getAbsolutePath() + "/" + filesName;
File streamFile = new File(streamFilePath);
if(!streamFile.exists()) {// 流文件存在
out.write("0".getBytes());
} else {
appInstance.startMediaCasterStream(filesName, "rtp");
out.write("1".getBytes());
}
com.wowza.wms.vhost.StartupStream stream = new com.wowza.wms.vhost.StartupStream();
stream.setApplicationName(application.getName() + "/" + appInstance.getName());
stream.setMediaCasterType("rtp");
stream.setStreamName(filesName);
vhost.addStartupStream(stream);
}
}catch(Exception e){
StringWriter sw=new StringWriter();
PrintWriter pw=new PrintWriter(sw);
e.printStackTrace(pw);
try {
Common.setRetInfo(resstr,"","exception",sw.toString());
out.write(resstr.toString().getBytes());
resstr=null;
} catch (IOException ex) {
ex.printStackTrace();
}
WMSLoggerFactory.getLogger(CLASS).info("WowzaLiveStreamRecord:"+sw.toString());
}
}
}
相关推荐
wowAPI能够帮助初学者学习写一些脚本,实现游戏的一些功能
Arctium WoW Client Launcher 27377版本。 HOWTO: 安装方法: 1.Use 7zip/WinRAR to extract the archive into your wow folder. 1.用解压软件将压缩包内容解压到WOW文件夹内,即将Arctium WoW Client Launcher....
传统隐写算法WOW,对文件夹下图像进行隐写,可以是3通道图像
Flutter(抖动)、Wow(晃动)、Drift(漂移)、Scrape Flutter(刮颤)是以移动介质为记录材料做模拟录制和回放的系统所需要面对的几种失真。这些失真是在录制、复制、回放过程中,由记录介质不规则的运动而导致的...
WOW数据库对照表
WOW插件制作指南PDF+WOW魔兽世界的APIs教程。
WOW1.20WOW120WOW120
Wow.js是javascript动画插件,经常配合animate.css一起使用。动画效果会在元素第一次出现在页面中时起作用。 引入wow.js 在需要使用的元素上添加class=”wow” 使用js初始化
wow.js是一个JavaScript库,用于制作网站上的滚动动画效果。它可以帮助您为网站添加动态和视觉吸引力,并使用户在滚动时感到更加舒适和流畅。 wow.js内置了许多不同类型的动画效果,例如淡入、弹跳、旋转、滑动等,...
c# wow服务器happyq
css动画效果 wow插件需要的wow.min.js和animate.css
PHOTOS手机APPS应用官网模板下载_绿色 app 手机 应用 单页 官网 开发 前端 wow 动画 应用开发 .rar
<div class="wow pulse bg-red" data-wow-iteration="5" data-wow-duration="0.15s"> <div class="wow bounceInRight bg-blue">轻量级 <div class="wow bounceInLeft bg-green"> <div class="wow flipInX ...
WoWModelViewer 0.5.08 模組瀏覽器簡體版 文章來源: http://wowbox.tw/bbs/viewtopic.php?f=35&t=2537 會讀取WOW的資料,在遊戲外讓你盡情組裝你喜歡的武器防具造型 來源: ...
SRS WOW HD音效插件很强大,SRS SRS(Sound Retrieval System)是由SRS研究所开发的、最具代表性的3D立体声技术。该技术的核心是可以利用2个扬声器获得环绕立体声的效果。更具体一点说,声波在周边各空间点都有其特定...
Wurth WOW Swift免费下载 伍尔特WOW免费下载最新的适应Windows。它是完全断开安装独立安排伍尔特WOW免费下载。伍尔特WOW是一个有用的应用程序,它是一个点点分类和广泛的数据识别的各种车辆,品牌和制造商。它整合了...
WOW国服客户端修改后可以 登录美服的配置文件
PHOTOS手机APPS应用官网模板下载_绿色 app 手机 应用 单页 官网 开发 前端 wow 动画 应用开发 产品 大气 bootstrap 响应式 企业 苹果应用 安卓.rar
WOW魔兽世界模型提取工具 WowModelViewer0.7.0.3