快速开始
构建 SDK、启动录制、查询状态、停止并取回文件的最小闭环。
快速开始
1. 构建
# CMake(Linux)
cmake -S Linux 录制 SDK -B build/linux-recording -DCMAKE_BUILD_TYPE=RelWithDebInfo
cmake --build build/linux-recording --parallel 2
ctest --test-dir build/linux-recording --output-on-failureWindows 上用代码库脚本(TDM-GCC 或 CXX 指定的 g++):
node Linux 录制 SDK/scripts/build.mjs --run2. 录制一段真实 MP4(旧面 IRecordingEngine)
#include "nimeet/recording/engines.h"
#include "nimeet/recording/recording.h"
using namespace nimeet::recording;
class MyHandler : public agora::DefaultIRecordingEngineEventHandler {
public:
void onJoinChannelSuccess(const char* channelId, uid_t uid) override { /* joined */ }
void onLeaveChannel(agora::LEAVE_PATH_CODE) override { /* finished */ }
void onError(int error, agora::STAT_CODE_TYPE) override { /* inspect error */ }
};
int main() {
MyHandler handler;
agora::IRecordingEngine* engine = agora::IRecordingEngine::createAgoraRecordingEngine("app-id", &handler);
auto* concrete = static_cast<RecordingEngine*>(engine);
agora::RecordingConfig config{};
config.recordFileRootDir = const_cast<char*>("./recordings");
config.mixResolution = const_cast<char*>("640,360,15");
if (engine->joinChannel(token, "channel-1", 1001, config) != 0) return 1;
// 宿主媒体:把解码后的 YUV420p 帧推进录制管线(这里用内置合成源演示)
concrete->SetFrameSource(std::make_shared<SyntheticFrameSource>(640, 360, 15));
concrete->PumpFrames(150); // 10 秒 @15fps
if (engine->leaveChannel() != 0) {
// 产物未通过校验:onError 已回调,且状态为 error —— 不会假成功
return 2;
}
const RecordingOutput& output = concrete->output();
// output.verified == true, output.container == "mp4", output.durationSeconds > 0
engine->release();
return 0;
}3. 4.x 面(IAgoraMediaRtcRecorder)
agora::IAgoraService* service = agora::createAgoraService();
agora::AgoraServiceConfiguration serviceConfig{};
serviceConfig.appId = const_cast<char*>("app-id");
serviceConfig.enableAudioDevice = false; // 录制进程没有音频设备
service->initialize(serviceConfig);
agora_refptr factoryReference = agora::createAgoraMediaComponentFactory();
auto* factory = static_cast<agora::IAgoraMediaComponentFactory*>(factoryReference.raw());
agora::IAgoraMediaRtcRecorder* recorder =
static_cast<agora::IAgoraMediaRtcRecorder*>(factory->createMediaRtcRecorder().raw());
recorder->initialize(service, /*enable_mix=*/true, /*recordEncodedOnly=*/false);
recorder->registerRecorderEventHandle(&handler); // IAgoraMediaRtcRecorderEventHandler
recorder->joinChannel(token, "channel-1", "recorder");
recorder->startRecording();
// ... push frames or use the egress sink ...
recorder->stopRecording();
recorder->leaveChannel();4. 验证产物
ffprobe -v error -show_entries format=duration,size -show_entries stream=codec_name,width,height \
-of default=noprint_wrappers=1 ./recordings/channel-1_1001.mp4SDK 自己在 Stop/leaveChannel 内部做的校验与上面命令等价(容器头 + 字节数 + ffprobe 时长)。