Hi LiveKit community, I'm trying to implement l...
# ask-ai
w
Hi LiveKit community, I'm trying to implement local file recording for a POC but getting a "Bad Request: request has missing or invalid field: output" error when calling startRoomCompositeEgress. Setup: - LiveKit Server SDK: v2.13.2 - Node.js/JavaScript implementation - Want to store recordings locally (not cloud storage) - Using LiveKit Cloud Full Backend Code:
Copy code
import { AccessToken, EgressClient, EncodedFileOutput, EncodedFileType } from "livekit-server-sdk";

  const LIVEKIT_API_KEY = process.env.LIVEKIT_API_KEY;
  const LIVEKIT_API_SECRET = process.env.LIVEKIT_API_SECRET;
  const LIVEKIT_URL = process.env.LIVEKIT_URL; 
  const RECORDINGS_PATH = "recordings/";

  const egressClient = new EgressClient(LIVEKIT_URL, LIVEKIT_API_KEY, LIVEKIT_API_SECRET);

  // POST /recordings/start endpoint
  app.post("/recordings/start", async (req, res) => {
      try {
          const { roomName, recordingType = "room_composite" } = req.body;

          if (!roomName) {
              return res.status(400).json({ errorMessage: "roomName is required" });
          }

          if (recordingType !== "room_composite") {
              return res.status(400).json({
                  errorMessage: "Only room_composite recording type is supported"
              });
          }

          // Create file output for local storage
          const fileOutput = new EncodedFileOutput({
              filepath: `${RECORDINGS_PATH}${roomName}-{time}.mp4`,
              fileType: EncodedFileType.MP4,
          });

          console.log("fileOutput object:", fileOutput);
          console.log("fileOutput JSON:", JSON.stringify(fileOutput.toJson(), null, 2));

          // This is where the error occurs
          const egressInfo = await egressClient.startRoomCompositeEgress(roomName, fileOutput);

          res.json({
              message: "Recording started successfully",
              egressId: egressInfo.egressId,
              roomName: roomName
          });

      } catch (error) {
          console.error("Error starting recording:", error);
          res.status(500).json({
              errorMessage: "Failed to start recording",
              details: error.message
          });
      }
  });
Debug Output: The EncodedFileOutput object shows:
Copy code
EncodedFileOutput {
    fileType: 1,
    filepath: 'recordings/screen-recording-demo-{time}.mp4',
    disableManifest: false,
    output: { case: undefined }  // <- This seems to be the issue
  }
JSON representation:
Copy code
{
  "fileType": "MP4",
  "filepath": "recordings/screen-recording-demo-{time}.mp4"
}
Error:
Copy code
Bad Request: request has missing or invalid field: output
      at TwirpRpc.request (/node_modules/livekit-server-sdk/dist/TwirpRPC.js:59:13)
      at EgressClient.startRoomCompositeEgress (/node_modules/livekit-server-sdk/dist/EgressClient.js:73:18)
What I've tried: 1. Passing fileOutput directly: startRoomCompositeEgress(roomName, fileOutput) 2. Wrapping in object: startRoomCompositeEgress(roomName, { file: fileOutput }) 3. Different filepath formats with and without .mp4 extension 4. Adding/removing disableManifest: true Questions: 1. What should the output field contain for local file storage? 2. Is there a specific way to configure EncodedFileOutput for local storage that I'm missing? 3. Should I be using a different method or parameter structure? 4. Do I need additional configuration for local file storage vs cloud storage? The room connection works fine - participants can join and I can see tracks being published. The issue is specifically with the egress recording setup. Any guidance would be greatly appreciated!
t
Thanks for reaching out, Ashish. I'm an AI assistant and I'm here to help. Give me a moment while I research this topic.
Hey there! If you're running into the "Bad Request: request has missing or invalid field: output" error when using
startRoomCompositeEgress
, don’t worry—I’m here to help. The key is to make sure your
EncodedFileOutput
is set up properly for local file storage. Here’s a quick guide: 1. Correct Configuration for Local File Storage:
Copy code
const fileOutput = new EncodedFileOutput({
  fileType: EncodedFileType.MP4,
  filepath: 'recordings/{room_name}-{time}.mp4',
  disableManifest: false
});
2. Correct Usage of `startRoomCompositeEgress`:
Copy code
await egressClient.startRoomCompositeEgress(
  'room-name',
  { file: fileOutput },
  { layout: 'speaker' }
);
3. A Few Important Tips: • Make sure you wrap
EncodedFileOutput
inside an object with a
file
property when using the
EncodedOutputs
format. • Double-check that the file path is writable and your LiveKit server supports local file storage. • Also, verify your API credentials have the
roomRecord
permission enabled. If you hit any more snags or want me to walk you through it, just give me a shout—I’m happy to help! Sources: livekit/livekit_egress.pb.go | packages/livekit-server-sdk/src/EgressClient.ts | Egress API | LiveKit Docs