RTMPPublisher.java
1.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//
package com.genersoft.iot.vmp.jt1078.subscriber;
import com.genersoft.iot.vmp.jt1078.util.Configs;
import java.io.InputStream;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class RTMPPublisher extends Thread {
static Logger logger = LoggerFactory.getLogger(RTMPPublisher.class);
String tag = null;
private Integer port;
Process process = null;
public RTMPPublisher(String tag, Integer port) {
this.tag = tag;
this.port = port;
}
@Override
public void run()
{
InputStream stderr = null;
int len = -1;
byte[] buff = new byte[512];
boolean debugMode = "on".equalsIgnoreCase(Configs.get("debug.mode"));
try
{
String rtmpUrl = Configs.get("rtmp.url").replaceAll("\\{TAG\\}", tag);
String cmd = String.format("%s -i http://localhost:%d/video/%s -vcodec copy -acodec aac -f flv %s",
Configs.get("ffmpeg.path"),
Configs.getInt("server.http.port", 3333),
tag,
rtmpUrl
);
logger.info("Execute: {}", cmd);
process = Runtime.getRuntime().exec(cmd);
stderr = process.getErrorStream();
while ((len = stderr.read(buff)) > -1)
{
if (debugMode) System.out.print(new String(buff, 0, len));
}
logger.info("Process FFMPEG exited...");
}
catch(Exception ex)
{
logger.error("publish failed", ex);
}
}
public void close()
{
try { if (process != null) process.destroyForcibly(); } catch(Exception e) { }
}
}