Explorar el Código

feat(core): update

gemercheung hace 3 años
padre
commit
9c8ee6b5ba
Se han modificado 11 ficheros con 86 adiciones y 7 borrados
  1. 2 0
      concat.txt
  2. 8 0
      cut.sh
  3. 22 5
      index.html
  4. 8 0
      live.sh
  5. 2 0
      t1.txt
  6. 4 0
      t2.txt
  7. 1 1
      webrtc/connection.js
  8. 1 0
      webrtc/trtc.js
  9. 30 0
      webrtc/uuid.js
  10. 4 0
      worker/decodeMessage.js
  11. 4 1
      worker/index.js

+ 2 - 0
concat.txt

@@ -0,0 +1,2 @@
+file '/Users/gemer/codes/outputmp4/0/0_1_0.mp4'
+file '/Users/gemer/codes/outputmp4/0/0_1_1.mp4'

+ 8 - 0
cut.sh

@@ -0,0 +1,8 @@
+#!/usr/bin/env bash
+# bash shell filePath Start end rtmp
+rtspUrl=$1
+videoName=$2
+# echo 'videoFilePath:'$videoFilePath
+
+ffmpeg -y -re  -stream_loop  -1 -f concat -safe 0 -i tt.txt  -c:v libx264 -preset fast -profile:v baseline -g 30 -sc_threshold 0 -b:v 1500k -f flv "$rtspUrl"
+

+ 22 - 5
index.html

@@ -137,21 +137,27 @@
       <script src="./worker/index.js" type="module"></script>
       <script type="module">
         import { Connection } from "./webrtc/connection.js";
+        import { uuid } from "./webrtc/uuid.js";
         document.addEventListener("DOMContentLoaded", async () => {
           const connection = new Connection();
           window.connection = connection;
           const testConfig = {
-            userId: "11use2221ttttt2553",
-            roomId: "tk12291",
+            userId: uuid(16, 16),
+            roomId: "22s1111ss",
             sdkAppId: 1400653314,
-            // role: "audience",
-            role: "audience",
             sceneCode: "2111",
           };
+          console.log("testConfig", testConfig);
           connection.init(testConfig, async () => {
             if (connection.client) {
               await connection.client.join({ roomId: testConfig.roomId });
               console.log("userSig", connection.userSig);
+
+              //   connection.socket.on("init-scene", {
+              //     videos: ["0/0_1_0", "1/0_2_0"],
+              //     range: [start, end],
+              //     isRotate: true,
+              //   });
               connection.socket.emit("getPush", {
                 userId: testConfig.userId,
                 roomId: testConfig.roomId,
@@ -161,18 +167,23 @@
               connection.socket.on("getPush", (data) => {
                 console.log(
                   "getPush",
-                  `ffmpeg -loglevel info -re -stream_loop -1 -i  test.mkv  -c:v libx264 -preset fast -profile:v baseline -g 30 -sc_threshold 0 -b:v 1500k -f flv "${data}"`
+                  `ffmpeg -loglevel info -re -stream_loop -1 -i  output.mp4 -c:v libx264 -preset fast -profile:v baseline -g 30 -sc_threshold 0 -b:v 1500k -f flv "${data}"`
                 );
               });
+              connection.socket.emit("init-webrtc");
               console.log("connection.client", connection.client);
 
               connection.client.on("peer-join", (event) => {
                 console.log("peer-join", event);
               });
 
+              connection.client.on("client-banned", () => {
+                location.reload();
+              });
               connection.client.on("stream-added", (event) => {
                 const remoteStream = event.stream;
                 const remoteUserId = remoteStream.getUserId();
+                console.warn("stream-added", remoteStream);
                 console.warn(
                   "received a remoteStream ID: " +
                     remoteStream.getId() +
@@ -180,6 +191,7 @@
                     remoteUserId
                 );
                 // 若需要观看该远端流,则需要订阅它
+
                 connection.client.subscribe(remoteStream);
               });
               // connection.client.on('network-quality', event => {
@@ -242,3 +254,8 @@
     <script src="https://web.sdk.qcloud.com/trtc/webrtc/demo/latest/dist/trtc.js"></script>
   </html>
 </html>
+ffmpeg -i 'rtmp://127.0.0.1/live?B1wrZUZQc' -i
+'http://120.24.252.95:8080/live/livestream.flv' -filter_complex overlay -c:v
+libx264 -r 30 -preset ultrafast -tune zerolatency -crf 25 -pix_fmt yuv420p -f
+flv
+"rtmp://rtmp.rtc.qq.com/push/22s1111ss?sdkappid=1400653314&userid=007E83817D55C01F&usersig=eJw1jsEKgkAURf9l1iFvnHF8CK3UaBFUaGFLYUZ5ijLaoEH074nW8p7Dgftm*SnzzMvSaFikQCLAbmWTGVnEfA-Ytp*6La0lzSIuAVQgBJebIW16RxWtAUCYokAeJkEQAz-8a6oXWVzaeh6HfO6mFl2ZNnOvlZvO13CQVWl4o*OuuD9Udrztf6GjbjnGlUQlBaL-*QLFzTO7"

+ 8 - 0
live.sh

@@ -0,0 +1,8 @@
+#!/usr/bin/env bash
+
+rtspUrl=$1
+videoName=$2
+# echo 'videoFilePath:'$videoFilePath
+
+ffmpeg -y -re  -stream_loop  -1 -f concat -safe 0 -i tt.txt  -c:v libx264 -preset fast -profile:v baseline -g 30 -sc_threshold 0 -b:v 1500k -f flv "$rtspUrl"
+

+ 2 - 0
t1.txt

@@ -0,0 +1,2 @@
+file '/Users/gemer/codes/outputmp4/0/0_1_0.mp4'
+file '/Users/gemer/codes/outputmp4/0/0_1_1.mp4'

+ 4 - 0
t2.txt

@@ -0,0 +1,4 @@
+file '/Users/gemer/codes/outputmp4/0/0_1_0.mp4'
+file '/Users/gemer/codes/outputmp4/0/0_1_1.mp4'
+file '/Users/gemer/codes/outputmp4/0/0_1_2.mp4'
+

+ 1 - 1
webrtc/connection.js

@@ -41,7 +41,7 @@ export class Connection {
       this.userSig = userSig;
       try {
         const client = TRTC.createClient({
-          mode: "live",
+          mode: "rtc",
           sdkAppId: sdkAppId,
           userId: userId,
           role: role,

La diferencia del archivo ha sido suprimido porque es demasiado grande
+ 1 - 0
webrtc/trtc.js


+ 30 - 0
webrtc/uuid.js

@@ -0,0 +1,30 @@
+export function uuid(len, radix) {
+  var chars =
+    "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz".split("");
+  var uuid = [],
+    i;
+  radix = radix || chars.length;
+
+  if (len) {
+    // Compact form
+    for (i = 0; i < len; i++) uuid[i] = chars[0 | (Math.random() * radix)];
+  } else {
+    // rfc4122, version 4 form
+    var r;
+
+    // rfc4122 requires these characters
+    uuid[8] = uuid[13] = uuid[18] = uuid[23] = "-";
+    uuid[14] = "4";
+
+    // Fill in random data.  At i==19 set the high bits of clock sequence as
+    // per rfc4122, sec. 4.1.5
+    for (i = 0; i < 36; i++) {
+      if (!uuid[i]) {
+        r = 0 | (Math.random() * 16);
+        uuid[i] = chars[i == 19 ? (r & 0x3) | 0x8 : r];
+      }
+    }
+  }
+
+  return uuid.join("");
+}

+ 4 - 0
worker/decodeMessage.js

@@ -0,0 +1,4 @@
+export const decodeMessage = (event) => {
+  console.log("event", event);
+  // 视频接收点
+};

+ 4 - 1
worker/index.js

@@ -1,6 +1,6 @@
 // const decoderWorker = new Worker("./worker/decoderWorker.js");
 
-// import decoder from "./decoderWorker.js";
+import { decodeMessage } from "./decodeMessage.js";
 
 var worker = `
 const Events = {
@@ -83,6 +83,9 @@ console.log("decoderWorker", decoderWorker);
 decoderWorker.onmessage = (event) => {
   //   console.log("Message received from worker", event);
   switch (event.data.event) {
+    case workEvents.decodeMessage:
+      decodeMessage(event);
+      break;
     case workEvents.ConsoleLog:
       console.log(event.data.printMsg);
       break;