Skip to content

Commit

Permalink
requesthandler: Add CreateRecordChapter
Browse files Browse the repository at this point in the history
The new `Hybrid MP4 [BETA]` output added in OBS adds support for
writing chapter markers to the file.
  • Loading branch information
tt2468 committed Jun 7, 2024
1 parent 71920c4 commit 6483dca
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/requesthandler/RequestHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ const std::unordered_map<std::string, RequestMethodHandler> RequestHandler::_han
{"PauseRecord", &RequestHandler::PauseRecord},
{"ResumeRecord", &RequestHandler::ResumeRecord},
{"SplitRecordFile", &RequestHandler::SplitRecordFile},
{"CreateRecordChapter", &RequestHandler::CreateRecordChapter},

// Media Inputs
{"GetMediaInputStatus", &RequestHandler::GetMediaInputStatus},
Expand Down
1 change: 1 addition & 0 deletions src/requesthandler/RequestHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ class RequestHandler {
RequestResult PauseRecord(const Request &);
RequestResult ResumeRecord(const Request &);
RequestResult SplitRecordFile(const Request &);
RequestResult CreateRecordChapter(const Request &);

// Media Inputs
RequestResult GetMediaInputStatus(const Request &);
Expand Down
35 changes: 35 additions & 0 deletions src/requesthandler/RequestHandler_Record.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -211,3 +211,38 @@ RequestResult RequestHandler::SplitRecordFile(const Request &)

return RequestResult::Success();
}

/**
* Adds a new chapter marker to the file currently being recorded.
*
* Note: As of OBS 30.2.0, the only file format supporting this feature is Hybrid MP4.
*
* @requestField ?chapterName | String | Name of the new chapter
*
* @requestType CreateRecordChapter
* @complexity 2
* @rpcVersion -1
* @initialVersion 5.5.0
* @api requests
* @category record
*/
RequestResult RequestHandler::CreateRecordChapter(const Request &request)
{
std::string chapterName;
if (request.Contains("chapterName")) {
RequestStatus::RequestStatus statusCode;
std::string comment;
if (!request.ValidateOptionalString("chapterName", statusCode, comment))
return RequestResult::Error(statusCode, comment);
chapterName = request.RequestData["chapterName"];
}

if (!obs_frontend_recording_active())
return RequestResult::Error(RequestStatus::OutputNotRunning);

if (!obs_frontend_recording_add_chapter(chapterName.empty() ? nullptr : chapterName.c_str()))
return RequestResult::Error(RequestStatus::RequestProcessingFailed,
"Verify that the output being used supports chapter markers.");

return RequestResult::Success();
}

0 comments on commit 6483dca

Please sign in to comment.