java实现监控rtsp流转flv方法实例

maven配置文件引入坐标:

1

2

3

4

5

6

7

8

9

10

<dependency>

    <groupId>org.bytedeco</groupId>

    <artifactId>javacv-platform</artifactId>

    <version>1.5.1</version>

</dependency>

<dependency>

    <groupId>javax.xml.bind</groupId>

    <artifactId>jaxb-api</artifactId>

    <version>2.3.0</version>

</dependency>

服务器代码

controller层:

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

import com.xr.web.rtspconverterflvspringbootstarter.service.IFLVService;

import io.swagger.annotations.Api;

import org.springframework.beans.factory.annotation.Autowired;

import org.springframework.web.bind.annotation.GetMapping;

import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

  

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

  

/**

 * FLV流转换

 *

 * @author gc.x

 */

@Api(tags = "flv")

@RequestMapping("/flv")

@RestController

public class FLVController {

  

    @Autowired

    private IFLVService service;

  

  

    @GetMapping()

    public void open4(HttpServletResponse response,

                      HttpServletRequest request) {

        String test = "rtsp://admin:sdxr@2022@192.168.0.205:554";

  

        service.open(test, response, request);

    }

}

config层:

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

import org.springframework.context.annotation.Bean;

import org.springframework.context.annotation.Configuration;

import org.springframework.scheduling.TaskScheduler;

import org.springframework.scheduling.annotation.EnableScheduling;

import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;

  

/**

 * 使用多线程执行定时任务

 *

 * @author gc.x

 *

 */

@Configuration

@EnableScheduling

public class SchedulerConfig {

    @Bean

    public TaskScheduler taskScheduler() {

        ThreadPoolTaskScheduler scheduler = new ThreadPoolTaskScheduler();

        // 线程池大小

        scheduler.setPoolSize(3);

        // 线程名字前缀

        scheduler.setThreadNamePrefix("task-thread-");

        return scheduler;

    }

  

}

factories层:

1

2

3

4

5

6

7

8

/**

 * 转换器状态(初始化、打开、关闭、错误、运行)

 *

 * @author gc.x

 */

public enum ConverterState {

    INITIAL, OPEN, CLOSE, ERROR, RUN

}

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

import javax.servlet.AsyncContext;

import java.io.IOException;

  

public interface Converter {

  

    /**

     * 获取该转换的key

     */

    public String getKey();

  

    /**

     * 获取该转换的url

     *

     * @return

     */

    public String getUrl();

  

    /**

     * 添加一个流输出

     *

     * @param entity

     */

    public void addOutputStreamEntity(String key, AsyncContext entity) throws IOException;

  

    /**

     * 退出转换

     */

    public void exit();

  

    /**

     * 启动

     */

    public void start();

  

}

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

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

211

212

213

214

215

216

217

218

219

220

221

222

223

224

import com.alibaba.fastjson.util.IOUtils;

import lombok.extern.slf4j.Slf4j;

import org.bytedeco.ffmpeg.avcodec.AVPacket;

import org.bytedeco.ffmpeg.global.avcodec;

import org.bytedeco.javacv.FFmpegFrameGrabber;

import org.bytedeco.javacv.FFmpegFrameRecorder;

import javax.servlet.AsyncContext;

import java.io.ByteArrayOutputStream;

import java.io.IOException;

import java.util.Iterator;

import java.util.List;

import java.util.Map;

  

/**

 * javacv转包装<br/>

 * 无须转码,更低的资源消耗,更低的延迟<br/>

 * 确保流来源视频H264格式,音频AAC格式

 *

 * @author gc.x

 */

@Slf4j

public class ConverterFactories extends Thread implements Converter {

    public volatile boolean runing = true;

    /**

     * 读流器

     */

    private FFmpegFrameGrabber grabber;

    /**

     * 转码器

     */

    private FFmpegFrameRecorder recorder;

    /**

     * 转FLV格式的头信息<br/>

     * 如果有第二个客户端播放首先要返回头信息

     */

    private byte[] headers;

    /**

     * 保存转换好的流

     */

    private ByteArrayOutputStream stream;

    /**

     * 流地址,h264,aac

     */

    private String url;

    /**

     * 流输出

     */

    private List<AsyncContext> outEntitys;

  

    /**

     * key用于表示这个转换器

     */

    private String key;

  

    /**

     * 转换队列

     */

    private Map<String, Converter> factories;

  

    public ConverterFactories(String url, String key, Map<String, Converter> factories, List<AsyncContext> outEntitys) {

        this.url = url;

        this.key = key;

        this.factories = factories;

        this.outEntitys = outEntitys;

    }

  

    @Override

    public void run() {

        boolean isCloseGrabberAndResponse = true;

        try {

            grabber = new FFmpegFrameGrabber(url);

            if ("rtsp".equals(url.substring(0, 4))) {

                grabber.setOption("rtsp_transport", "tcp");

                grabber.setOption("stimeout", "5000000");

            }

            grabber.start();

            if (avcodec.AV_CODEC_ID_H264 == grabber.getVideoCodec()

                    && (grabber.getAudioChannels() == 0 || avcodec.AV_CODEC_ID_AAC == grabber.getAudioCodec())) {

                log.info("this url:{} converterFactories start", url);

                // 来源视频H264格式,音频AAC格式

                // 无须转码,更低的资源消耗,更低的延迟

                stream = new ByteArrayOutputStream();

                recorder = new FFmpegFrameRecorder(stream, grabber.getImageWidth(), grabber.getImageHeight(),

                        grabber.getAudioChannels());

                recorder.setInterleaved(true);

                recorder.setVideoOption("preset", "ultrafast");

                recorder.setVideoOption("tune", "zerolatency");

                recorder.setVideoOption("crf", "25");

                recorder.setFrameRate(grabber.getFrameRate());

                recorder.setSampleRate(grabber.getSampleRate());

                if (grabber.getAudioChannels() > 0) {

                    recorder.setAudioChannels(grabber.getAudioChannels());

                    recorder.setAudioBitrate(grabber.getAudioBitrate());

                    recorder.setAudioCodec(grabber.getAudioCodec());

                }

                recorder.setFormat("flv");

                recorder.setVideoBitrate(grabber.getVideoBitrate());

                recorder.setVideoCodec(grabber.getVideoCodec());

                recorder.start(grabber.getFormatContext());

                if (headers == null) {

                    headers = stream.toByteArray();

                    stream.reset();

                    writeResponse(headers);

                }

                int nullNumber = 0;

                while (runing) {

                    AVPacket k = grabber.grabPacket();

                    if (k != null) {

                        try {

                            recorder.recordPacket(k);

                        } catch (Exception e) {

                        }

                        if (stream.size() > 0) {

                            byte[] b = stream.toByteArray();

                            stream.reset();

                            writeResponse(b);

                            if (outEntitys.isEmpty()) {

                                log.info("没有输出退出");

                                break;

                            }

                        }

                        avcodec.av_packet_unref(k);

                    } else {

                        nullNumber++;

                        if (nullNumber > 200) {

                            break;

                        }

                    }

                    Thread.sleep(5);

                }

            } else {

                isCloseGrabberAndResponse = false;

                // 需要转码为视频H264格式,音频AAC格式

                ConverterTranFactories c = new ConverterTranFactories(url, key, factories, outEntitys, grabber);

                factories.put(key, c);

                c.start();

            }

        } catch (Exception e) {

            log.error(e.getMessage(), e);

        } finally {

            closeConverter(isCloseGrabberAndResponse);

            completeResponse(isCloseGrabberAndResponse);

            log.info("this url:{} converterFactories exit", url);

  

        }

    }

  

    /**

     * 输出FLV视频流

     *

     * @param b

     */

    public void writeResponse(byte[] b) {

        Iterator<AsyncContext> it = outEntitys.iterator();

        while (it.hasNext()) {

            AsyncContext o = it.next();

            try {

                o.getResponse().getOutputStream().write(b);

            } catch (Exception e) {

                log.info("移除一个输出");

                it.remove();

            }

        }

    }

  

    /**

     * 退出转换

     */

    public void closeConverter(boolean isCloseGrabberAndResponse) {

        if (isCloseGrabberAndResponse) {

            IOUtils.close(grabber);

            factories.remove(this.key);

        }

        IOUtils.close(recorder);

        IOUtils.close(stream);

    }

  

    /**

     * 关闭异步响应

     *

     * @param isCloseGrabberAndResponse

     */

    public void completeResponse(boolean isCloseGrabberAndResponse) {

        if (isCloseGrabberAndResponse) {

            Iterator<AsyncContext> it = outEntitys.iterator();

            while (it.hasNext()) {

                AsyncContext o = it.next();

                o.complete();

            }

        }

    }

  

    @Override

    public String getKey() {

        return this.key;

    }

  

    @Override

    public String getUrl() {

        return this.url;

    }

  

    @Override

    public void addOutputStreamEntity(String key, AsyncContext entity) throws IOException {

        if (headers == null) {

            outEntitys.add(entity);

        } else {

            entity.getResponse().getOutputStream().write(headers);

            entity.getResponse().getOutputStream().flush();

            outEntitys.add(entity);

        }

    }

  

    @Override

    public void exit() {

        this.runing = false;

        try {

            this.join();

        } catch (Exception e) {

            log.error(e.getMessage(), e);

        }

    }

  

}

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

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

135

136

137

138

139

140

141

142

143

144

145

146

147

148

149

150

151

152

153

154

155

156

157

158

159

160

161

162

163

164

165

166

167

168

169

170

171

172

173

174

175

176

177

178

179

180

181

182

183

184

185

186

187

188

189

190

191

192

193

194

195

196

197

198

199

200

201

202

203

204

205

206

207

208

209

210

import com.alibaba.fastjson.util.IOUtils;

import lombok.extern.slf4j.Slf4j;

import org.bytedeco.ffmpeg.global.avcodec;

import org.bytedeco.javacv.FFmpegFrameGrabber;

import org.bytedeco.javacv.FFmpegFrameRecorder;

import org.bytedeco.javacv.Frame;

  

import javax.servlet.AsyncContext;

import java.io.ByteArrayOutputStream;

import java.io.IOException;

import java.util.Iterator;

import java.util.List;

import java.util.Map;

  

/**

 * javacv转码<br/>

 * 流来源不是视频H264格式,音频AAC格式 转码为视频H264格式,音频AAC格式

 *

 * @author gc.x

 */

@Slf4j

public class ConverterTranFactories extends Thread implements Converter {

    public volatile boolean runing = true;

    /**

     * 读流器

     */

    private FFmpegFrameGrabber grabber;

    /**

     * 转码器

     */

    private FFmpegFrameRecorder recorder;

    /**

     * 转FLV格式的头信息<br/>

     * 如果有第二个客户端播放首先要返回头信息

     */

    private byte[] headers;

    /**

     * 保存转换好的流

     */

    private ByteArrayOutputStream stream;

    /**

     * 流地址,h264,aac

     */

    private String url;

    /**

     * 流输出

     */

    private List<AsyncContext> outEntitys;

  

    /**

     * key用于表示这个转换器

     */

    private String key;

  

    /**

     * 转换队列

     */

    private Map<String, Converter> factories;

  

    public ConverterTranFactories(String url, String key, Map<String, Converter> factories,

            List<AsyncContext> outEntitys, FFmpegFrameGrabber grabber) {

        this.url = url;

        this.key = key;

        this.factories = factories;

        this.outEntitys = outEntitys;

        this.grabber = grabber;

    }

  

    @Override

    public void run() {

        try {

            log.info("this url:{} converterTranFactories start", url);

            grabber.setFrameRate(25);

            if (grabber.getImageWidth() > 1920) {

                grabber.setImageWidth(1920);

            }

            if (grabber.getImageHeight() > 1080) {

                grabber.setImageHeight(1080);

            }

            stream = new ByteArrayOutputStream();

            recorder = new FFmpegFrameRecorder(stream, grabber.getImageWidth(), grabber.getImageHeight(),

                    grabber.getAudioChannels());

            recorder.setInterleaved(true);

            recorder.setVideoOption("preset", "ultrafast");

            recorder.setVideoOption("tune", "zerolatency");

            recorder.setVideoOption("crf", "25");

            recorder.setGopSize(50);

            recorder.setFrameRate(25);

            recorder.setSampleRate(grabber.getSampleRate());

            if (grabber.getAudioChannels() > 0) {

                recorder.setAudioChannels(grabber.getAudioChannels());

                recorder.setAudioBitrate(grabber.getAudioBitrate());

                recorder.setAudioCodec(avcodec.AV_CODEC_ID_AAC);

            }

            recorder.setFormat("flv");

            recorder.setVideoBitrate(grabber.getVideoBitrate());

            recorder.setVideoCodec(avcodec.AV_CODEC_ID_H264);

            recorder.start();

            if (headers == null) {

                headers = stream.toByteArray();

                stream.reset();

                writeResponse(headers);

            }

            int nullNumber = 0;

            while (runing) {

                // 抓取一帧

                Frame f = grabber.grab();

                if (f != null) {

                    try {

                        // 转码

                        recorder.record(f);

                    } catch (Exception e) {

                    }

                    if (stream.size() > 0) {

                        byte[] b = stream.toByteArray();

                        stream.reset();

                        writeResponse(b);

                        if (outEntitys.isEmpty()) {

                            log.info("没有输出退出");

                            break;

                        }

                    }

                } else {

                    nullNumber++;

                    if (nullNumber > 200) {

                        break;

                    }

                }

                Thread.sleep(5);

            }

        } catch (Exception e) {

            log.error(e.getMessage(), e);

        } finally {

            closeConverter();

            completeResponse();

            log.info("this url:{} converterTranFactories exit", url);

            factories.remove(this.key);

        }

    }

  

    /**

     * 输出FLV视频流

     *

     * @param b

     */

    public void writeResponse(byte[] b) {

        Iterator<AsyncContext> it = outEntitys.iterator();

        while (it.hasNext()) {

            AsyncContext o = it.next();

            try {

                o.getResponse().getOutputStream().write(b);

            } catch (Exception e) {

                log.info("移除一个输出");

                it.remove();

            }

        }

    }

  

    /**

     * 退出转换

     */

    public void closeConverter() {

        IOUtils.close(grabber);

        IOUtils.close(recorder);

        IOUtils.close(stream);

    }

  

    /**

     * 关闭异步响应

     */

    public void completeResponse() {

        Iterator<AsyncContext> it = outEntitys.iterator();

        while (it.hasNext()) {

            AsyncContext o = it.next();

            o.complete();

        }

    }

  

    @Override

    public String getKey() {

        return this.key;

    }

  

    @Override

    public String getUrl() {

        return this.url;

    }

  

    @Override

    public void addOutputStreamEntity(String key, AsyncContext entity) throws IOException {

        if (headers == null) {

            outEntitys.add(entity);

        } else {

            entity.getResponse().getOutputStream().write(headers);

            entity.getResponse().getOutputStream().flush();

            outEntitys.add(entity);

        }

    }

  

    @Override

    public void exit() {

        this.runing = false;

        try {

            this.join();

        } catch (Exception e) {

            log.error(e.getMessage(), e);

        }

    }

  

}

result层:

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

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

import com.alibaba.fastjson.JSONObject;

  

import java.io.Serializable;

import java.util.HashMap;

  

/**

 * 封装返回结果

 *

 */

public class JsonResult extends HashMap<String, Object> implements Serializable {

  

    private static final long serialVersionUID = 1L;

    public static final int SUCCESS = 200;

  

    public JsonResult() {

    }

  

    /**

     * 返回成功

     */

    public static JsonResult ok() {

        return ok("操作成功");

    }

  

    /**

     * 返回成功

     */

    public static JsonResult okFallBack() {

        return okFallBack("操作成功");

    }

  

    /**

     * 返回成功

     */

    public JsonResult put(Object obj) {

        return this.put("data", obj);

    }

  

    /**

     * 返回成功

     */

    public static JsonResult ok(String message) {

        return result(200, message);

    }

  

    /**

     * 降级函数 - 返回成功

     */

    public static JsonResult okFallBack(String message) {

        return result(205, message);

    }

  

    /**

     * 返回成功

     */

    public static JsonResult result(int code, String message) {

        JsonResult jsonResult = new JsonResult();

        jsonResult.put("timestamp", System.currentTimeMillis());

        jsonResult.put("status", code);

        jsonResult.put("message", message);

        return jsonResult;

    }

  

    /**

     * 返回失败

     */

    public static JsonResult error() {

        return error("操作失败");

    }

  

    /**

     * 返回失败

     */

    public static JsonResult error(String message) {

        return error(500, message);

    }

  

    /**

     * 返回失败

     */

    public static JsonResult error(int code, String message) {

        JsonResult jsonResult = new JsonResult();

        jsonResult.put("timestamp", System.currentTimeMillis());

        jsonResult.put("status", code);

        jsonResult.put("message", message);

        return jsonResult;

    }

  

    /**

     * 设置code

     */

    public JsonResult setCode(int code) {

        super.put("status", code);

        return this;

    }

  

    /**

     * 设置message

     */

    public JsonResult setMessage(String message) {

        super.put("message", message);

        return this;

    }

  

    /**

     * 放入object

     */

    @Override

    public JsonResult put(String key, Object object) {

        super.put(key, object);

        return this;

    }

  

    /**

     * 权限禁止

     */

    public static JsonResult forbidden(String message) {

        JsonResult jsonResult = new JsonResult();

        jsonResult.put("timestamp", System.currentTimeMillis());

        jsonResult.put("status", 401);

        jsonResult.put("message", message);

        return jsonResult;

    }

  

    @Override

    public String toString() {

        return JSONObject.toJSONString(this);

    }

  

    public JSONObject toJSONObject() {

        return JSONObject.parseObject(toString());

    }

  

}

service层:

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

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

103

104

105

106

107

108

109

110

111

112

113

114

115

116

117

118

119

120

121

122

123

124

125

126

127

128

129

130

131

132

133

134

import com.alibaba.fastjson.JSONObject;

  

import java.io.Serializable;

import java.util.HashMap;

  

/**

 * 封装返回结果

 *

 */

public class JsonResult extends HashMap<String, Object> implements Serializable {

  

    private static final long serialVersionUID = 1L;

    public static final int SUCCESS = 200;

  

    public JsonResult() {

    }

  

    /**

     * 返回成功

     */

    public static JsonResult ok() {

        return ok("操作成功");

    }

  

    /**

     * 返回成功

     */

    public static JsonResult okFallBack() {

        return okFallBack("操作成功");

    }

  

    /**

     * 返回成功

     */

    public JsonResult put(Object obj) {

        return this.put("data", obj);

    }

  

    /**

     * 返回成功

     */

    public static JsonResult ok(String message) {

        return result(200, message);

    }

  

    /**

     * 降级函数 - 返回成功

     */

    public static JsonResult okFallBack(String message) {

        return result(205, message);

    }

  

    /**

     * 返回成功

     */

    public static JsonResult result(int code, String message) {

        JsonResult jsonResult = new JsonResult();

        jsonResult.put("timestamp", System.currentTimeMillis());

        jsonResult.put("status", code);

        jsonResult.put("message", message);

        return jsonResult;

    }

  

    /**

     * 返回失败

     */

    public static JsonResult error() {

        return error("操作失败");

    }

  

    /**

     * 返回失败

     */

    public static JsonResult error(String message) {

        return error(500, message);

    }

  

    /**

     * 返回失败

     */

    public static JsonResult error(int code, String message) {

        JsonResult jsonResult = new JsonResult();

        jsonResult.put("timestamp", System.currentTimeMillis());

        jsonResult.put("status", code);

        jsonResult.put("message", message);

        return jsonResult;

    }

  

    /**

     * 设置code

     */

    public JsonResult setCode(int code) {

        super.put("status", code);

        return this;

    }

  

    /**

     * 设置message

     */

    public JsonResult setMessage(String message) {

        super.put("message", message);

        return this;

    }

  

    /**

     * 放入object

     */

    @Override

    public JsonResult put(String key, Object object) {

        super.put(key, object);

        return this;

    }

  

    /**

     * 权限禁止

     */

    public static JsonResult forbidden(String message) {

        JsonResult jsonResult = new JsonResult();

        jsonResult.put("timestamp", System.currentTimeMillis());

        jsonResult.put("status", 401);

        jsonResult.put("message", message);

        return jsonResult;

    }

  

    @Override

    public String toString() {

        return JSONObject.toJSONString(this);

    }

  

    public JSONObject toJSONObject() {

        return JSONObject.parseObject(toString());

    }

  

}

1

2

3

4

5

6

7

8

9

10

11

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

public interface IFLVService {

    /**

     * 打开一个流地址

     *

     * @param url

     * @param response

     */

    public void open(String url, HttpServletResponse response, HttpServletRequest request);

}

二.客户端代码基于flv.js进行播放

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

<!-- @format -->

<!DOCTYPE html>

<html lang="en">

    <head>

        <meta charset="UTF-8" />

        <meta http-equiv="X-UA-Compatible" content="IE=edge" />

        <meta name="viewport" content="width=device-width, initial-scale=1.0" />

        <title>Document</title>

    </head>

    <body>

        <script src="flv.min.js"></script>

        <video id="videoElement"></video>

        <button onclick="playflv()">点击播放</button>

        <script>

            if (flvjs.isSupported()) {

                var videoElement = document.getElementById('videoElement');

                var flvPlayer = flvjs.createPlayer({

                    type: 'flv',

                    url: 'http://127.0.0.1:10010/xr/flv',

                });

                flvPlayer.attachMediaElement(videoElement);

                flvPlayer.load();

            }

            //自动播放,浏览器不支持

            function playflv() {

                flvPlayer.play();

            }

        </script>

    </body>

</html>

引入的flv.js文件在如下网站下载即可

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值