当前位置:   article > 正文

java SSM框架使用WebSocket推送视频流_java如何通过websocket推送flv流

java如何通过websocket推送flv流

依赖

  1. <dependency>
  2. <groupId>org.springframework</groupId>
  3. <artifactId>spring-websocket</artifactId>
  4. <version>5.2.5.RELEASE</version>
  5. <scope>compile</scope>
  6. </dependency>

1.视频工具类

  1. import org.apache.log4j.Logger;
  2. import org.springframework.web.socket.BinaryMessage;
  3. import org.springframework.web.socket.WebSocketSession;
  4. import java.io.InputStream;
  5. import java.util.List;
  6. /**
  7. * <pre>
  8. * TODO:视频工具类
  9. * </pre>
  10. *
  11. * @author zhangjunchao
  12. * @date 2019/8/19
  13. */
  14. public class VideoUtils {
  15. private final static Logger logger = Logger.getLogger(VideoUtils.class);
  16. // 声明的ffmpeg.exe固定路径变量
  17. public String FFMPEG_PATH = "D:/ffmpeg/bin/ffmpeg.exe";
  18. public String channel = "";
  19. public WebSocketSession webSocketSession = null;
  20. private Process process;
  21. public VideoUtils(String channel, WebSocketSession webSocketSession) {
  22. // ffmpeg路径需要更换自己的
  23. FFMPEG_PATH = "D:\\developsoftware\\wisdom_screen_ds1200\\server\\ETCMornitoring\\src\\main\\resources" +
  24. "\\export_template" +
  25. "\\ffmpeg.exe";
  26. this.channel = channel;
  27. this.webSocketSession = webSocketSession;
  28. }
  29. /**
  30. * 视频转换
  31. *
  32. * @param video_path
  33. */
  34. public void convertCommand() {
  35. String channel = this.channel;
  36. WebSocketSession webSocketSession = this.webSocketSession;
  37. System.out.println("start");
  38. System.out.println(FFMPEG_PATH);
  39. InputStream errorStream = null;
  40. InputStream inputStream = null;
  41. try {
  42. List<String> commands = new java.util.ArrayList<String>();
  43. commands.add(FFMPEG_PATH);
  44. commands.add("-rtsp_transport");
  45. commands.add("tcp");
  46. commands.add("-i");
  47. commands.add(channel);
  48. commands.add("-vcodec");
  49. co
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/菜鸟追梦旅行/article/detail/196443
推荐阅读
相关标签
  

闽ICP备14008679号