Integration of pre-recorded video with RTC

Perfect. Thanks a lot.

I have deployed the code and MP4 file on server end as you described but still I am getting black video. @mihailj Below is my code

const connect = function (fileName, SESSION_ID) {
  try {
    var postData = JSON.stringify({
      type: "IPCAM",
      rtspUri: "file:///opt/openvidu/recordings/" + fileName + ".mp4",
      adaptativeBitrate: true,
      onlyPlayWithSubscribers: true,
      networkCache: 2000,
      data: "IP-CAM",
    });

    var options = {
      hostname: HOST_NAME,
      port: 4443,
      path: "/openvidu/api/sessions/" + SESSION_ID + "/connection",
      method: "POST",
      headers: {
        Authorization: "Basic " + btoa("OPENVIDUAPP:" + SECRET),
        "Content-Type": "application/json",
        "Content-Length": postData.length,
      },
    };

    var req = https.request(options, (res) => {
      console.log("statusCode:", res.statusCode);
      console.log("headers:", res.headers);

      res.on("data", (d) => {
        console.log("loaded");
      });
    });

    req.on("error", (e) => {
      console.error(e);
    });

    req.write(postData);
    req.end();
  } catch (e) {
    console.log(e.message);
  }
};

Any insights on above issue please @mihailj @pabloFuente @cruizba @micael.gallego . Thanks in advance.

Any update please. I am stuck here.

IDK, what error you are having? Can you show us your OpenVidu logs when you try to do this?

I have black screen and the connection is not getting created. Do you have any working code?

I have black screen and the connection is not getting created. Do you have any working code?

You can also try my code if it works on your end.

This solution not works. You should delete this as its just time wasting.

@Syed_Gilani let me show you…

I will use our https://demos.openvidu.io to show you this is actually working… I will let this file there for a while…

  1. I placed a file under /opt/openvidu/recording, named example.mp4:
    image
    (Original file: https://file-examples.com/storage/fef431be58652d8e49c225d/2017/04/file_example_MP4_640_3MG.mp4)

  2. Go to OpenviduCall

  3. I have created a node project with your code, and modify it to work with https://demos.openvidu.io:

const https = require("https");

const connect = function (fileName, SESSION_ID) {
  try {
    var postData = JSON.stringify({
      type: "IPCAM",
      rtspUri: "file:///opt/openvidu/recordings/" + fileName + ".mp4",
      adaptativeBitrate: true,
      onlyPlayWithSubscribers: true,
      networkCache: 2000,
      data: "IP-CAM",
    });

    var options = {
      hostname: "demos.openvidu.io",
      port: 443,
      path: "/openvidu/api/sessions/" + SESSION_ID + "/connection",
      method: "POST",
      headers: {
        Authorization: "Basic " + btoa("OPENVIDUAPP:MY_SECRET"),
        "Content-Type": "application/json",
        "Content-Length": postData.length,
      },
    };

    var req = https.request(options, (res) => {
      console.log("statusCode:", res.statusCode);
      console.log("headers:", res.headers);

      res.on("data", (d) => {
        console.log("loaded");
      });
    });

    req.on("error", (e) => {
      console.error(e);
    });

    req.write(postData);
    req.end();
  } catch (e) {
    console.log(e.message);
  }
};

connect("example", "test-session")
  1. Execute it.
  2. Result

Again, we try to help with our best effort, nothing is a waste or time… Please check if you can reproduce these steps in your environment.

Make sure to check logs of /opt/openvidu/kurento-logs just to see if, for any reason, the video is not encoded correctly. A command you can run to follow kurento logs is:

tail -f /opt/openvidu/kurento-logs/*.log

Thank you so much for the detailed answer. I will try again on my server and let you know.

Your example works perfectly but when I switch to my OpenVidu server where I have the same setup e.g file, folder etc; its creating the connection but no video. The node app connect function results in 500 code as I have attached the snapshots. There is definitely some extra settings needed, I noticed your file and directory permissions are changed and the response also returns X-Frame-Options: DENY in my case but its X-Frame-Options: SAMEORIGIN when I try your openvidu server. Please check and let me know. Following are my OpenVidu credentials:

URL: streamtwo.wiseup.club
Secret: OV_WU

Regarding file permissions, I’ve implied you’ve notice that as part of the process. Give the video permissions to uid and gid 1000:

chown 1000:1000 <your_video_file>

The reason of the 500 code should appear in your OpenVidu Server.

Try to follow the logs while doing the request and check what the error is saying.

Regards.

I tried that also but the issue was with web server, I have installed the OpenVidu at port 4443 and also setup nginx server on my domain; after that I have moved the .mp4 file to /var/www/html/recordings so that it became accessible. I have changed the .env accordingly and it works now. Thanks a lot for your responses.

Hi,

I switched from CE to Pro version and now the same working code does not work on Pro, The connection is being created with black video. Following is the console message form server end.

[INFO] 2023-11-28 06:52:28,888 [http-nio-0.0.0.0-5443-exec-8] io.openvidu.server.rest.SessionRestController - REST API: POST /openvidu/api/sessions/cayman-sports/connection {type=IPCAM, rtspUri=file:///opt/openvidu/recordings/example.mp4, adaptativeBitrate=true, onlyPlayWithSubscribers=true, networkCache=2000, data=IP-CAM}
openvidu-openvidu-server-1 | [WARN] 2023-11-28 06:52:28,889 [http-nio-0.0.0.0-5443-exec-8] io.openvidu.server.kurento.core.KurentoSessionManager - Error getting address location: The address 127.0.0.1 is not in the database.

and

[WARN] 2023-11-28 06:52:29,231 [AbstractJsonRpcClientWebSocket-reqResEventExec-e3-t186] io.openvidu.server.kurento.core.KurentoParticipant - PARTICIPANT ipc_IPCAM_file_PA0N_null_opt_openvidu_recordings_example_mp4: Media error encountered: INVALID_URI: Invalid URI(errCode=0)
openvidu-openvidu-server-1 | [ERROR] 2023-11-28 06:52:29,231 [AbstractJsonRpcClientWebSocket-reqResEventExec-e3-t186] io.openvidu.server.kurento.core.KurentoParticipantEndpointConfig - KMS event [ERROR]: → endpoint: str_IPC_Bj5N_ipc_IPCAM_file_PA0N_null_opt_openvidu_recordings_example_mp4 (publisher) | errorCode: 0 | description: Invalid URI | timestamp: 1701154349232

It seems like there is some URI issue when I switched to the Pro version and setup master and media nodes of separate instances.

Please check and fix it as soon as possible.

Waiting for your positive response. Thanks

Where did you put the file?

You need to put that file in all your media nodes at /opt/openvidu/recordings/example.mp4 so Kurento is able to reach it.

I tried putting it at /opt/openvidu/recordings/example.mp4 as well as well as at /var/www/html/recordings/example.mp4; in CE version it worked only by putting at /var/www/html path but in Pro version its not working on both of the paths.

An alternative method to ensure that Kurento can access the video across different deployment types (CE or PRO) is to host the video on an HTTP server.

Consider setting up an HTTP server within your internal network and provide a URL that is resolvable within that network.

By doing so, the video will be accessible for both editions.