index.js 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // vDecoder example
  2. import { VDecoder } from "./VDecoder.js";
  3. // 测试用
  4. import { initWebGLCanvas, draw } from "../video/test.js";
  5. // decoder
  6. // const socket = io("ws://192.168.0.150:3000", {
  7. // reconnectionDelayMax: 10000,
  8. // });
  9. // socket.on("connect", (data) => {
  10. // console.log("socket connect");
  11. // });
  12. const vDecoder = new VDecoder({
  13. maxChip: 100,
  14. });
  15. vDecoder.on("ready", () => {
  16. console.log("ready");
  17. // 测试canvas
  18. initWebGLCanvas();
  19. vDecoder.mutiFetch([
  20. {
  21. path: "https://laser-data.oss-cn-shenzhen.aliyuncs.com/test-video/1011",
  22. frame: 1,
  23. },
  24. {
  25. path: "https://laser-data.oss-cn-shenzhen.aliyuncs.com/test-video/1011",
  26. frame: 1,
  27. }, {
  28. path: "https://laser-data.oss-cn-shenzhen.aliyuncs.com/test-video/1011",
  29. frame: 1,
  30. }, {
  31. path: "https://laser-data.oss-cn-shenzhen.aliyuncs.com/test-video/1011",
  32. frame: 1,
  33. }, {
  34. path: "https://laser-data.oss-cn-shenzhen.aliyuncs.com/test-video/1011",
  35. frame: 1,
  36. }, {
  37. path: "https://laser-data.oss-cn-shenzhen.aliyuncs.com/test-video/1011",
  38. frame: 1,
  39. }, {
  40. path: "https://laser-data.oss-cn-shenzhen.aliyuncs.com/test-video/1011",
  41. frame: 1,
  42. }, {
  43. path: "https://laser-data.oss-cn-shenzhen.aliyuncs.com/test-video/1011",
  44. frame: 1,
  45. },
  46. {
  47. path: "https://laser-data.oss-cn-shenzhen.aliyuncs.com/test-video/2",
  48. frame: 2,
  49. },
  50. ]);
  51. vDecoder.on("fetchDone", (clip) => {
  52. console.log("fetchDone", clip);
  53. });
  54. //监听 decodeData
  55. vDecoder.on("decodeData", (data) => {
  56. // console.log("decodeData", data);
  57. const { width, height, data: buffer } = data;
  58. draw(new Uint8Array(buffer), width, height);
  59. // window.updateTexture( new Uint8Array(buffer) );
  60. // window.up
  61. });
  62. vDecoder.on("decodeDone", async (id) => {
  63. let clipId = null;
  64. // vDecoder.flush();
  65. // vDecoder.fetch({
  66. // path: "https://laser-data.oss-cn-shenzhen.aliyuncs.com/test-video/1011",
  67. // range: [0, 66],
  68. // });
  69. // console.log("clipId", clipId);
  70. });
  71. });