添加网页自动转码,以支持h265 g.711的播放
This commit is contained in:
@@ -128,29 +128,29 @@ public class ZLMHttpHookListener {
|
||||
}
|
||||
String app = json.getString("app");
|
||||
String streamId = json.getString("id");
|
||||
if ("rtp".equals(app)) {
|
||||
String ssrc = new DecimalFormat("0000000000").format(Integer.parseInt(streamId, 16));
|
||||
StreamInfo streamInfoForPlay = storager.queryPlayBySSRC(ssrc);
|
||||
if ("rtp".equals(app) && streamInfoForPlay != null ) {
|
||||
MediaServerConfig mediaInfo = storager.getMediaInfo();
|
||||
streamInfoForPlay.setFlv(String.format("http://%s:%s/rtp/%s.flv", mediaInfo.getWanIp(), mediaInfo.getHttpPort(), streamId));
|
||||
streamInfoForPlay.setWs_flv(String.format("ws://%s:%s/rtp/%s.flv", mediaInfo.getWanIp(), mediaInfo.getHttpPort(), streamId));
|
||||
streamInfoForPlay.setRtmp(String.format("rtmp://%s:%s/rtp/%s", mediaInfo.getWanIp(), mediaInfo.getRtmpPort(), streamId));
|
||||
streamInfoForPlay.setHls(String.format("http://%s:%s/rtp/%s/hls.m3u8", mediaInfo.getWanIp(), mediaInfo.getHttpPort(), streamId));
|
||||
streamInfoForPlay.setRtsp(String.format("rtsp://%s:%s/rtp/%s", mediaInfo.getWanIp(), mediaInfo.getRtspPort(), streamId));
|
||||
storager.startPlay(streamInfoForPlay);
|
||||
}
|
||||
|
||||
|
||||
String ssrc = new DecimalFormat("0000000000").format(Integer.parseInt(streamId, 16));
|
||||
StreamInfo streamInfoForPlay = storager.queryPlayBySSRC(ssrc);
|
||||
if ("rtp".equals(app) && streamInfoForPlay != null ) {
|
||||
MediaServerConfig mediaInfo = storager.getMediaInfo();
|
||||
streamInfoForPlay.setFlv(String.format("http://%s:%s/rtp/%s.flv", mediaInfo.getWanIp(), mediaInfo.getHttpPort(), streamId));
|
||||
streamInfoForPlay.setWs_flv(String.format("ws://%s:%s/rtp/%s.flv", mediaInfo.getWanIp(), mediaInfo.getHttpPort(), streamId));
|
||||
streamInfoForPlay.setRtmp(String.format("rtmp://%s:%s/rtp/%s", mediaInfo.getWanIp(), mediaInfo.getRtmpPort(), streamId));
|
||||
streamInfoForPlay.setHls(String.format("http://%s:%s/rtp/%s/hls.m3u8", mediaInfo.getWanIp(), mediaInfo.getHttpPort(), streamId));
|
||||
streamInfoForPlay.setRtsp(String.format("rtsp://%s:%s/rtp/%s", mediaInfo.getWanIp(), mediaInfo.getRtspPort(), streamId));
|
||||
storager.startPlay(streamInfoForPlay);
|
||||
}
|
||||
|
||||
StreamInfo streamInfoForPlayBack = storager.queryPlaybackBySSRC(ssrc);
|
||||
if ("rtp".equals(app) && streamInfoForPlayBack != null ) {
|
||||
MediaServerConfig mediaInfo = storager.getMediaInfo();
|
||||
streamInfoForPlayBack.setFlv(String.format("http://%s:%s/rtp/%s.flv", mediaInfo.getWanIp(), mediaInfo.getHttpPort(), streamId));
|
||||
streamInfoForPlayBack.setWs_flv(String.format("ws://%s:%s/rtp/%s.flv", mediaInfo.getWanIp(), mediaInfo.getHttpPort(), streamId));
|
||||
streamInfoForPlayBack.setRtmp(String.format("rtmp://%s:%s/rtp/%s", mediaInfo.getWanIp(), mediaInfo.getRtmpPort(), streamId));
|
||||
streamInfoForPlayBack.setHls(String.format("http://%s:%s/rtp/%s/hls.m3u8", mediaInfo.getWanIp(), mediaInfo.getHttpPort(), streamId));
|
||||
streamInfoForPlayBack.setRtsp(String.format("rtsp://%s:%s/rtp/%s", mediaInfo.getWanIp(), mediaInfo.getRtspPort(), streamId));
|
||||
storager.startPlayback(streamInfoForPlayBack);
|
||||
StreamInfo streamInfoForPlayBack = storager.queryPlaybackBySSRC(ssrc);
|
||||
if ("rtp".equals(app) && streamInfoForPlayBack != null ) {
|
||||
MediaServerConfig mediaInfo = storager.getMediaInfo();
|
||||
streamInfoForPlayBack.setFlv(String.format("http://%s:%s/rtp/%s.flv", mediaInfo.getWanIp(), mediaInfo.getHttpPort(), streamId));
|
||||
streamInfoForPlayBack.setWs_flv(String.format("ws://%s:%s/rtp/%s.flv", mediaInfo.getWanIp(), mediaInfo.getHttpPort(), streamId));
|
||||
streamInfoForPlayBack.setRtmp(String.format("rtmp://%s:%s/rtp/%s", mediaInfo.getWanIp(), mediaInfo.getRtmpPort(), streamId));
|
||||
streamInfoForPlayBack.setHls(String.format("http://%s:%s/rtp/%s/hls.m3u8", mediaInfo.getWanIp(), mediaInfo.getHttpPort(), streamId));
|
||||
streamInfoForPlayBack.setRtsp(String.format("rtsp://%s:%s/rtp/%s", mediaInfo.getWanIp(), mediaInfo.getRtspPort(), streamId));
|
||||
storager.startPlayback(streamInfoForPlayBack);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO Auto-generated method stub
|
||||
|
||||
@@ -89,6 +89,22 @@ public class ZLMRESTfulUtils {
|
||||
return sendPost("getRtpInfo",param);
|
||||
}
|
||||
|
||||
public JSONObject addFFmpegSource(String src_url, String dst_url, String timeout_ms){
|
||||
System.out.println(src_url);
|
||||
System.out.println(dst_url);
|
||||
Map<String, Object> param = new HashMap<>();
|
||||
param.put("src_url", src_url);
|
||||
param.put("dst_url", dst_url);
|
||||
param.put("timeout_ms", timeout_ms);
|
||||
return sendPost("addFFmpegSource",param);
|
||||
}
|
||||
|
||||
public JSONObject delFFmpegSource(String key){
|
||||
Map<String, Object> param = new HashMap<>();
|
||||
param.put("key", key);
|
||||
return sendPost("delFFmpegSource",param);
|
||||
}
|
||||
|
||||
public JSONObject getMediaServerConfig(){
|
||||
return sendPost("getServerConfig",null);
|
||||
}
|
||||
|
||||
@@ -101,7 +101,8 @@ public class ZLMRunner implements CommandLineRunner {
|
||||
|
||||
String hookPrex = String.format("http://%s:%s/index/hook", hookIP, serverPort);
|
||||
Map<String, Object> param = new HashMap<>();
|
||||
param.put("secret",mediaSecret);
|
||||
param.put("api.secret",mediaSecret); // -profile:v Baseline
|
||||
param.put("ffmpeg.cmd","%s -fflags nobuffer -rtsp_transport tcp -i %s -c:a aac -strict -2 -ar 44100 -ab 48k -c:v libx264 -f flv %s");
|
||||
param.put("hook.enable","1");
|
||||
param.put("hook.on_flow_report","");
|
||||
param.put("hook.on_play","");
|
||||
|
||||
@@ -29,7 +29,7 @@ public class ZLMUtils {
|
||||
param.put("enable_tcp", 1);
|
||||
param.put("stream_id", streamId);
|
||||
JSONObject jsonObject = zlmresTfulUtils.openRtpServer(param);
|
||||
if (jsonObject.getInteger("code") == 0) {
|
||||
if (jsonObject != null && jsonObject.getInteger("code") == 0) {
|
||||
return newPort;
|
||||
} else {
|
||||
return getNewRTPPort(ssrc);
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.genersoft.iot.vmp.vmanager.play;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.genersoft.iot.vmp.common.StreamInfo;
|
||||
import com.genersoft.iot.vmp.conf.MediaServerConfig;
|
||||
import com.genersoft.iot.vmp.media.zlm.ZLMRESTfulUtils;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -46,7 +47,7 @@ public class PlayController {
|
||||
Integer getEncoding) {
|
||||
|
||||
if (getEncoding == null) getEncoding = 0;
|
||||
getEncoding = closeWaitRTPInfo ? 0: getEncoding;
|
||||
getEncoding = closeWaitRTPInfo ? 0 : getEncoding;
|
||||
Device device = storager.queryVideoDevice(deviceId);
|
||||
StreamInfo streamInfo = storager.queryPlayByDevice(deviceId, channelId);
|
||||
|
||||
@@ -149,5 +150,73 @@ public class PlayController {
|
||||
return new ResponseEntity<String>(HttpStatus.INTERNAL_SERVER_ERROR);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 将不是h264的视频通过ffmpeg 转码为h264 + aac
|
||||
* @param ssrc
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/play/{ssrc}/convert")
|
||||
public ResponseEntity<String> playConvert(@PathVariable String ssrc) {
|
||||
StreamInfo streamInfo = storager.queryPlayBySSRC(ssrc);
|
||||
if (streamInfo == null) {
|
||||
logger.warn("视频转码API调用失败!, 视频流已经停止!");
|
||||
return new ResponseEntity<String>("未找到视频流信息, 视频流可能已经停止", HttpStatus.OK);
|
||||
}
|
||||
String streamId = String.format("%08x", Integer.parseInt(ssrc)).toUpperCase();
|
||||
JSONObject rtpInfo = zlmresTfulUtils.getRtpInfo(streamId);
|
||||
if (!rtpInfo.getBoolean("exist")) {
|
||||
logger.warn("视频转码API调用失败!, 视频流已停止推流!");
|
||||
return new ResponseEntity<String>("推流信息在流媒体中不存在, 视频流可能已停止推流", HttpStatus.OK);
|
||||
} else {
|
||||
MediaServerConfig mediaInfo = storager.getMediaInfo();
|
||||
String dstUrl = String.format("rtmp://%s:%s/convert/%s", "127.0.0.1", mediaInfo.getRtmpPort(),
|
||||
streamId );
|
||||
JSONObject jsonObject = zlmresTfulUtils.addFFmpegSource(streamInfo.getRtsp(), dstUrl, "1000000");
|
||||
System.out.println(jsonObject);
|
||||
JSONObject result = new JSONObject();
|
||||
if (jsonObject != null && jsonObject.getInteger("code") == 0) {
|
||||
result.put("code", 0);
|
||||
JSONObject data = jsonObject.getJSONObject("data");
|
||||
if (data != null) {
|
||||
result.put("key", data.getString("key"));
|
||||
result.put("rtmp", dstUrl);
|
||||
result.put("flv", String.format("http://%s:%s/convert/%s.flv", mediaInfo.getWanIp(), mediaInfo.getHttpPort(), streamId));
|
||||
result.put("ws_flv", String.format("ws://%s:%s/convert/%s.flv", mediaInfo.getWanIp(), mediaInfo.getHttpPort(), streamId));
|
||||
}
|
||||
}else {
|
||||
result.put("code", 1);
|
||||
result.put("msg", "cover fail");
|
||||
}
|
||||
return new ResponseEntity<String>( result.toJSONString(), HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 结束转码
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
@PostMapping("/play/convert/stop/{key}")
|
||||
public ResponseEntity<String> playConvertStop(@PathVariable String key) {
|
||||
|
||||
JSONObject jsonObject = zlmresTfulUtils.delFFmpegSource(key);
|
||||
System.out.println(jsonObject);
|
||||
JSONObject result = new JSONObject();
|
||||
if (jsonObject != null && jsonObject.getInteger("code") == 0) {
|
||||
result.put("code", 0);
|
||||
JSONObject data = jsonObject.getJSONObject("data");
|
||||
if (data != null && data.getBoolean("flag")) {
|
||||
result.put("code", "0");
|
||||
result.put("msg", "success");
|
||||
}else {
|
||||
|
||||
}
|
||||
}else {
|
||||
result.put("code", 1);
|
||||
result.put("msg", "delFFmpegSource fail");
|
||||
}
|
||||
return new ResponseEntity<String>( result.toJSONString(), HttpStatus.OK);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user