obs-outputs: Allow enabling BPM for Hybrid MP4 output

This commit is contained in:
derrod
2025-01-30 10:42:51 +01:00
committed by Ryan Foster
parent 505b76e8a7
commit 2eabfdad55
2 changed files with 20 additions and 0 deletions

View File

@@ -13,6 +13,10 @@ if(NOT TARGET OBS::opts-parser)
add_subdirectory("${CMAKE_SOURCE_DIR}/shared/opts-parser" "${CMAKE_BINARY_DIR}/shared/opts-parser")
endif()
if(NOT TARGET OBS::bpm)
add_subdirectory("${CMAKE_SOURCE_DIR}/shared/bpm" bpm)
endif()
add_library(obs-outputs MODULE)
add_library(OBS::outputs ALIAS obs-outputs)
@@ -73,6 +77,7 @@ target_link_libraries(
OBS::libobs
OBS::happy-eyeballs
OBS::opts-parser
OBS::bpm
MbedTLS::mbedtls
ZLIB::ZLIB
$<$<PLATFORM_ID:Windows>:OBS::w32-pthreads>

View File

@@ -25,6 +25,7 @@
#include <util/dstr.h>
#include <util/threading.h>
#include <util/buffered-file-serializer.h>
#include <bpm.h>
#include <opts-parser.h>
@@ -49,6 +50,8 @@ struct mp4_output {
size_t chunk_size;
struct serializer serializer;
bool enable_bpm;
volatile bool active;
volatile bool stopping;
uint64_t stop_ts;
@@ -298,6 +301,8 @@ static void parse_custom_options(struct mp4_output *out, const char *opts_str)
out->buffer_size = strtoull(opt.value, 0, 10) * 1048576ULL;
} else if (strcmp(opt.name, "chunk_size") == 0) {
out->chunk_size = strtoull(opt.value, 0, 10) * 1048576ULL;
} else if (strcmp(opt.name, "bpm") == 0) {
out->enable_bpm = !!atoi(opt.value);
} else {
blog(LOG_WARNING, "Unknown muxer option: %s = %s", opt.name, opt.value);
}
@@ -343,6 +348,11 @@ static bool mp4_output_start(void *data)
obs_data_release(settings);
if (out->enable_bpm) {
info("Enabling BPM");
obs_output_add_packet_callback(out->output, bpm_inject, NULL);
}
if (!buffered_file_serializer_init(&out->serializer, out->path.array, out->buffer_size, out->chunk_size)) {
warn("Unable to open file '%s'", out->path.array);
return false;
@@ -503,6 +513,11 @@ static void mp4_output_actual_stop(struct mp4_output *out, int code)
mp4_mux_finalise(out->muxer);
if (out->enable_bpm) {
obs_output_remove_packet_callback(out->output, bpm_inject, NULL);
bpm_destroy(out->output);
}
if (code) {
obs_output_signal_stop(out->output, code);
} else {