mp4-output.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685
  1. /******************************************************************************
  2. Copyright (C) 2024 by Dennis Sädtler <[email protected]>
  3. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU General Public License as published by
  5. the Free Software Foundation, either version 2 of the License, or
  6. (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ******************************************************************************/
  14. #include "mp4-mux.h"
  15. #include <inttypes.h>
  16. #include <obs-module.h>
  17. #include <util/platform.h>
  18. #include <util/deque.h>
  19. #include <util/dstr.h>
  20. #include <util/threading.h>
  21. #include <util/buffered-file-serializer.h>
  22. #include <bpm.h>
  23. #include <opts-parser.h>
  24. #define do_log(level, format, ...) \
  25. blog(level, "[%s output: '%s'] " format, out->muxer_flavor == FLAVOR_MOV ? "mov" : "mp4", \
  26. obs_output_get_name(out->output), ##__VA_ARGS__)
  27. #define warn(format, ...) do_log(LOG_WARNING, format, ##__VA_ARGS__)
  28. #define info(format, ...) do_log(LOG_INFO, format, ##__VA_ARGS__)
  29. struct chapter {
  30. uint64_t ts;
  31. char *name;
  32. };
  33. struct mp4_output {
  34. obs_output_t *output;
  35. struct dstr path;
  36. /* File serializer buffer configuration */
  37. size_t buffer_size;
  38. size_t chunk_size;
  39. struct serializer serializer;
  40. bool enable_bpm;
  41. volatile bool active;
  42. volatile bool stopping;
  43. uint64_t stop_ts;
  44. bool allow_overwrite;
  45. uint64_t total_bytes;
  46. pthread_mutex_t mutex;
  47. struct mp4_mux *muxer;
  48. enum mp4_flavor muxer_flavor;
  49. int flags;
  50. size_t chapter_ctr;
  51. struct deque chapters;
  52. /* File splitting stuff */
  53. bool split_file_enabled;
  54. bool split_file_ready;
  55. volatile bool manual_split;
  56. size_t cur_size;
  57. size_t max_size;
  58. int64_t start_time;
  59. int64_t max_time;
  60. bool found_video[MAX_OUTPUT_VIDEO_ENCODERS];
  61. bool found_audio[MAX_OUTPUT_AUDIO_ENCODERS];
  62. int64_t video_pts_offsets[MAX_OUTPUT_VIDEO_ENCODERS];
  63. int64_t audio_dts_offsets[MAX_OUTPUT_AUDIO_ENCODERS];
  64. /* Buffer for packets while we reinitialise the muxer after splitting */
  65. DARRAY(struct encoder_packet) split_buffer;
  66. };
  67. static inline bool stopping(struct mp4_output *out)
  68. {
  69. return os_atomic_load_bool(&out->stopping);
  70. }
  71. static inline bool active(struct mp4_output *out)
  72. {
  73. return os_atomic_load_bool(&out->active);
  74. }
  75. static inline int64_t packet_pts_usec(struct encoder_packet *packet)
  76. {
  77. return packet->pts * 1000000 / packet->timebase_den;
  78. }
  79. static inline void ts_offset_clear(struct mp4_output *out)
  80. {
  81. for (size_t i = 0; i < MAX_OUTPUT_VIDEO_ENCODERS; i++) {
  82. out->found_video[i] = false;
  83. out->video_pts_offsets[i] = 0;
  84. }
  85. for (size_t i = 0; i < MAX_OUTPUT_AUDIO_ENCODERS; i++) {
  86. out->found_audio[i] = false;
  87. out->audio_dts_offsets[i] = 0;
  88. }
  89. }
  90. static inline void ts_offset_update(struct mp4_output *out, struct encoder_packet *packet)
  91. {
  92. int64_t *offset;
  93. int64_t ts;
  94. bool *found;
  95. if (packet->type == OBS_ENCODER_VIDEO) {
  96. offset = &out->video_pts_offsets[packet->track_idx];
  97. found = &out->found_video[packet->track_idx];
  98. ts = packet->pts;
  99. } else {
  100. offset = &out->audio_dts_offsets[packet->track_idx];
  101. found = &out->found_audio[packet->track_idx];
  102. ts = packet->dts;
  103. }
  104. if (*found)
  105. return;
  106. *offset = ts;
  107. *found = true;
  108. }
  109. static const char *mp4_output_name(void *unused)
  110. {
  111. UNUSED_PARAMETER(unused);
  112. return obs_module_text("MP4Output");
  113. }
  114. static const char *mov_output_name(void *unused)
  115. {
  116. UNUSED_PARAMETER(unused);
  117. return obs_module_text("MOVOutput");
  118. }
  119. static void mp4_clear_chapters(struct mp4_output *out)
  120. {
  121. while (out->chapters.size) {
  122. struct chapter *chap = deque_data(&out->chapters, 0);
  123. bfree(chap->name);
  124. deque_pop_front(&out->chapters, NULL, sizeof(struct chapter));
  125. }
  126. out->chapter_ctr = 0;
  127. }
  128. static void mp4_output_destroy(void *data)
  129. {
  130. struct mp4_output *out = data;
  131. pthread_mutex_destroy(&out->mutex);
  132. mp4_clear_chapters(out);
  133. deque_free(&out->chapters);
  134. dstr_free(&out->path);
  135. bfree(out);
  136. }
  137. void mp4_pkt_callback(obs_output_t *output, struct encoder_packet *pkt, struct encoder_packet_time *pkt_time,
  138. void *param)
  139. {
  140. UNUSED_PARAMETER(output);
  141. struct mp4_output *out = param;
  142. /* Only the primary video track is used as the reference for the chapter track. */
  143. if (!pkt_time || !pkt || pkt->type != OBS_ENCODER_VIDEO || pkt->track_idx != 0)
  144. return;
  145. pthread_mutex_lock(&out->mutex);
  146. struct chapter *chap = NULL;
  147. /* Write all queued chapters with a timestamp <= the current frame's composition time. */
  148. while (out->chapters.size) {
  149. chap = deque_data(&out->chapters, 0);
  150. if (chap->ts > pkt_time->cts)
  151. break;
  152. /* Video frames can be out of order (b-frames), so instead of using the video packet's dts_usec we need to calculate
  153. * the chapter DTS from the frame's PTS (for chapters DTS == PTS). */
  154. int64_t chap_dts_usec = pkt->pts * 1000000 / pkt->timebase_den;
  155. int64_t chap_dts_msec = chap_dts_usec / 1000;
  156. int64_t chap_dts_sec = chap_dts_msec / 1000;
  157. int milliseconds = (int)(chap_dts_msec % 1000);
  158. int seconds = (int)chap_dts_sec % 60;
  159. int minutes = ((int)chap_dts_sec / 60) % 60;
  160. int hours = (int)chap_dts_sec / 3600;
  161. info("Adding chapter \"%s\" at %02d:%02d:%02d.%03d", chap->name, hours, minutes, seconds, milliseconds);
  162. mp4_mux_add_chapter(out->muxer, chap_dts_usec, chap->name);
  163. /* Free name and remove chapter from queue. */
  164. bfree(chap->name);
  165. deque_pop_front(&out->chapters, NULL, sizeof(struct chapter));
  166. }
  167. pthread_mutex_unlock(&out->mutex);
  168. }
  169. static void mp4_add_chapter_proc(void *data, calldata_t *cd)
  170. {
  171. struct mp4_output *out = data;
  172. struct dstr name = {0};
  173. dstr_copy(&name, calldata_string(cd, "chapter_name"));
  174. if (name.len == 0) {
  175. /* Generate name if none provided. */
  176. dstr_catf(&name, "%s %zu", obs_module_text("MP4Output.UnnamedChapter"), out->chapter_ctr + 1);
  177. }
  178. pthread_mutex_lock(&out->mutex);
  179. /* Enqueue chapter marker to be inserted once a packet containing the video frame with the corresponding timestamp is
  180. * being processed. */
  181. struct chapter chap = {0};
  182. chap.ts = obs_get_video_frame_time();
  183. chap.name = name.array;
  184. deque_push_back(&out->chapters, &chap, sizeof(struct chapter));
  185. out->chapter_ctr++;
  186. pthread_mutex_unlock(&out->mutex);
  187. }
  188. static void split_file_proc(void *data, calldata_t *cd)
  189. {
  190. struct mp4_output *out = data;
  191. calldata_set_bool(cd, "split_file_enabled", out->split_file_enabled);
  192. if (!out->split_file_enabled)
  193. return;
  194. os_atomic_set_bool(&out->manual_split, true);
  195. }
  196. static void *mp4_output_create_internal(obs_data_t *settings, obs_output_t *output, enum mp4_flavor flavor)
  197. {
  198. struct mp4_output *out = bzalloc(sizeof(struct mp4_output));
  199. out->output = output;
  200. out->muxer_flavor = flavor;
  201. pthread_mutex_init(&out->mutex, NULL);
  202. signal_handler_t *sh = obs_output_get_signal_handler(output);
  203. signal_handler_add(sh, "void file_changed(string next_file)");
  204. proc_handler_t *ph = obs_output_get_proc_handler(output);
  205. proc_handler_add(ph, "void split_file(out bool split_file_enabled)", split_file_proc, out);
  206. proc_handler_add(ph, "void add_chapter(string chapter_name)", mp4_add_chapter_proc, out);
  207. UNUSED_PARAMETER(settings);
  208. return out;
  209. }
  210. static void *mp4_output_create(obs_data_t *settings, obs_output_t *output)
  211. {
  212. return mp4_output_create_internal(settings, output, FLAVOR_MP4);
  213. }
  214. static void *mov_output_create(obs_data_t *settings, obs_output_t *output)
  215. {
  216. return mp4_output_create_internal(settings, output, FLAVOR_MOV);
  217. }
  218. static inline void apply_flag(int *flags, const char *value, int flag_value)
  219. {
  220. if (atoi(value))
  221. *flags |= flag_value;
  222. else
  223. *flags &= ~flag_value;
  224. }
  225. static void parse_custom_options(struct mp4_output *out, const char *opts_str)
  226. {
  227. int flags = MP4_USE_NEGATIVE_CTS;
  228. struct obs_options opts = obs_parse_options(opts_str);
  229. for (size_t i = 0; i < opts.count; i++) {
  230. struct obs_option opt = opts.options[i];
  231. if (strcmp(opt.name, "skip_soft_remux") == 0) {
  232. apply_flag(&flags, opt.value, MP4_SKIP_FINALISATION);
  233. } else if (strcmp(opt.name, "write_encoder_info") == 0) {
  234. apply_flag(&flags, opt.value, MP4_WRITE_ENCODER_INFO);
  235. } else if (strcmp(opt.name, "use_metadata_tags") == 0) {
  236. apply_flag(&flags, opt.value, MP4_USE_MDTA_KEY_VALUE);
  237. } else if (strcmp(opt.name, "use_negative_cts") == 0) {
  238. apply_flag(&flags, opt.value, MP4_USE_NEGATIVE_CTS);
  239. } else if (strcmp(opt.name, "buffer_size") == 0) {
  240. out->buffer_size = strtoull(opt.value, 0, 10) * 1048576ULL;
  241. } else if (strcmp(opt.name, "chunk_size") == 0) {
  242. out->chunk_size = strtoull(opt.value, 0, 10) * 1048576ULL;
  243. } else if (strcmp(opt.name, "bpm") == 0) {
  244. out->enable_bpm = !!atoi(opt.value);
  245. } else {
  246. blog(LOG_WARNING, "Unknown muxer option: %s = %s", opt.name, opt.value);
  247. }
  248. }
  249. obs_free_options(opts);
  250. out->flags = flags;
  251. }
  252. static void generate_filename(struct mp4_output *out, struct dstr *dst, bool overwrite);
  253. static bool mp4_output_start(void *data)
  254. {
  255. struct mp4_output *out = data;
  256. if (!obs_output_can_begin_data_capture(out->output, 0))
  257. return false;
  258. if (!obs_output_initialize_encoders(out->output, 0))
  259. return false;
  260. os_atomic_set_bool(&out->stopping, false);
  261. obs_data_t *settings = obs_output_get_settings(out->output);
  262. out->max_time = obs_data_get_int(settings, "max_time_sec") * 1000000LL;
  263. out->max_size = obs_data_get_int(settings, "max_size_mb") * 1024 * 1024;
  264. out->split_file_enabled = obs_data_get_bool(settings, "split_file");
  265. out->allow_overwrite = obs_data_get_bool(settings, "allow_overwrite");
  266. out->cur_size = 0;
  267. /* Get path */
  268. const char *path = obs_data_get_string(settings, "path");
  269. if (path && *path) {
  270. dstr_copy(&out->path, path);
  271. } else {
  272. generate_filename(out, &out->path, out->allow_overwrite);
  273. info("Output path not specified. Using generated path '%s'", out->path.array);
  274. }
  275. /* Allow skipping the remux step for debugging purposes. */
  276. const char *muxer_settings = obs_data_get_string(settings, "muxer_settings");
  277. parse_custom_options(out, muxer_settings);
  278. obs_data_release(settings);
  279. if (out->enable_bpm) {
  280. info("Enabling BPM");
  281. obs_output_add_packet_callback(out->output, bpm_inject, NULL);
  282. }
  283. if (!buffered_file_serializer_init(&out->serializer, out->path.array, out->buffer_size, out->chunk_size)) {
  284. warn("Unable to open file '%s'", out->path.array);
  285. return false;
  286. }
  287. /* Add packet callback for accurate chapter markers. */
  288. obs_output_add_packet_callback(out->output, mp4_pkt_callback, (void *)out);
  289. /* Initialise muxer and start capture */
  290. out->muxer = mp4_mux_create(out->output, &out->serializer, out->flags, out->muxer_flavor);
  291. os_atomic_set_bool(&out->active, true);
  292. obs_output_begin_data_capture(out->output, 0);
  293. info("Writing Hybrid MP4/MOV file '%s'...", out->path.array);
  294. return true;
  295. }
  296. static inline bool should_split(struct mp4_output *out, struct encoder_packet *packet)
  297. {
  298. /* split at video frame on primary track */
  299. if (packet->type != OBS_ENCODER_VIDEO || packet->track_idx > 0)
  300. return false;
  301. /* don't split group of pictures */
  302. if (!packet->keyframe)
  303. return false;
  304. if (os_atomic_load_bool(&out->manual_split))
  305. return true;
  306. /* reached maximum file size */
  307. if (out->max_size > 0 && out->cur_size + (int64_t)packet->size >= out->max_size)
  308. return true;
  309. /* reached maximum duration */
  310. if (out->max_time > 0 && packet->dts_usec - out->start_time >= out->max_time)
  311. return true;
  312. return false;
  313. }
  314. static void find_best_filename(struct dstr *path, bool space)
  315. {
  316. int num = 2;
  317. if (!os_file_exists(path->array))
  318. return;
  319. const char *ext = strrchr(path->array, '.');
  320. if (!ext)
  321. return;
  322. size_t extstart = ext - path->array;
  323. struct dstr testpath;
  324. dstr_init_copy_dstr(&testpath, path);
  325. for (;;) {
  326. dstr_resize(&testpath, extstart);
  327. dstr_catf(&testpath, space ? " (%d)" : "_%d", num++);
  328. dstr_cat(&testpath, ext);
  329. if (!os_file_exists(testpath.array)) {
  330. dstr_free(path);
  331. dstr_init_move(path, &testpath);
  332. break;
  333. }
  334. }
  335. }
  336. static void generate_filename(struct mp4_output *out, struct dstr *dst, bool overwrite)
  337. {
  338. obs_data_t *settings = obs_output_get_settings(out->output);
  339. const char *dir = obs_data_get_string(settings, "directory");
  340. const char *fmt = obs_data_get_string(settings, "format");
  341. const char *ext = obs_data_get_string(settings, "extension");
  342. bool space = obs_data_get_bool(settings, "allow_spaces");
  343. char *filename = os_generate_formatted_filename(ext, space, fmt);
  344. dstr_copy(dst, dir);
  345. dstr_replace(dst, "\\", "/");
  346. if (dstr_end(dst) != '/')
  347. dstr_cat_ch(dst, '/');
  348. dstr_cat(dst, filename);
  349. char *slash = strrchr(dst->array, '/');
  350. if (slash) {
  351. *slash = 0;
  352. os_mkdirs(dst->array);
  353. *slash = '/';
  354. }
  355. if (!overwrite)
  356. find_best_filename(dst, space);
  357. bfree(filename);
  358. obs_data_release(settings);
  359. }
  360. static bool change_file(struct mp4_output *out, struct encoder_packet *pkt)
  361. {
  362. uint64_t start_time = os_gettime_ns();
  363. /* finalise file */
  364. mp4_mux_finalise(out->muxer);
  365. info("Waiting for file writer to finish...");
  366. /* flush/close file and destroy old muxer */
  367. buffered_file_serializer_free(&out->serializer);
  368. mp4_mux_destroy(out->muxer);
  369. mp4_clear_chapters(out);
  370. info("File split complete. Finalization took %" PRIu64 " ms.", (os_gettime_ns() - start_time) / 1000000);
  371. /* open new file */
  372. generate_filename(out, &out->path, out->allow_overwrite);
  373. info("Changing output file to '%s'", out->path.array);
  374. if (!buffered_file_serializer_init(&out->serializer, out->path.array, out->buffer_size, out->chunk_size)) {
  375. warn("Unable to open file '%s'", out->path.array);
  376. return false;
  377. }
  378. out->muxer = mp4_mux_create(out->output, &out->serializer, out->flags, out->muxer_flavor);
  379. calldata_t cd = {0};
  380. signal_handler_t *sh = obs_output_get_signal_handler(out->output);
  381. calldata_set_string(&cd, "next_file", out->path.array);
  382. signal_handler_signal(sh, "file_changed", &cd);
  383. calldata_free(&cd);
  384. out->cur_size = 0;
  385. out->start_time = pkt->dts_usec;
  386. ts_offset_clear(out);
  387. return true;
  388. }
  389. static void mp4_output_stop(void *data, uint64_t ts)
  390. {
  391. struct mp4_output *out = data;
  392. out->stop_ts = ts / 1000;
  393. os_atomic_set_bool(&out->stopping, true);
  394. }
  395. static void mp4_mux_destroy_task(void *ptr)
  396. {
  397. struct mp4_mux *muxer = ptr;
  398. mp4_mux_destroy(muxer);
  399. }
  400. static void mp4_output_actual_stop(struct mp4_output *out, int code)
  401. {
  402. os_atomic_set_bool(&out->active, false);
  403. obs_output_remove_packet_callback(out->output, mp4_pkt_callback, NULL);
  404. uint64_t start_time = os_gettime_ns();
  405. mp4_mux_finalise(out->muxer);
  406. if (out->enable_bpm) {
  407. obs_output_remove_packet_callback(out->output, bpm_inject, NULL);
  408. bpm_destroy(out->output);
  409. }
  410. if (code) {
  411. obs_output_signal_stop(out->output, code);
  412. } else {
  413. obs_output_end_data_capture(out->output);
  414. }
  415. info("Waiting for file writer to finish...");
  416. /* Flush/close output file and destroy muxer */
  417. buffered_file_serializer_free(&out->serializer);
  418. obs_queue_task(OBS_TASK_DESTROY, mp4_mux_destroy_task, out->muxer, false);
  419. out->muxer = NULL;
  420. /* Clear chapter data */
  421. mp4_clear_chapters(out);
  422. info("File output complete. Finalization took %" PRIu64 " ms.", (os_gettime_ns() - start_time) / 1000000);
  423. }
  424. static void push_back_packet(struct mp4_output *out, struct encoder_packet *packet)
  425. {
  426. struct encoder_packet pkt;
  427. obs_encoder_packet_ref(&pkt, packet);
  428. da_push_back(out->split_buffer, &pkt);
  429. }
  430. static inline bool submit_packet(struct mp4_output *out, struct encoder_packet *pkt)
  431. {
  432. out->total_bytes += pkt->size;
  433. if (!out->split_file_enabled)
  434. return mp4_mux_submit_packet(out->muxer, pkt);
  435. out->cur_size += pkt->size;
  436. /* Apply DTS/PTS offset local packet copy */
  437. struct encoder_packet modified = *pkt;
  438. if (modified.type == OBS_ENCODER_VIDEO) {
  439. modified.dts -= out->video_pts_offsets[modified.track_idx];
  440. modified.pts -= out->video_pts_offsets[modified.track_idx];
  441. } else {
  442. modified.dts -= out->audio_dts_offsets[modified.track_idx];
  443. modified.pts -= out->audio_dts_offsets[modified.track_idx];
  444. }
  445. return mp4_mux_submit_packet(out->muxer, &modified);
  446. }
  447. static void mp4_output_packet(void *data, struct encoder_packet *packet)
  448. {
  449. struct mp4_output *out = data;
  450. pthread_mutex_lock(&out->mutex);
  451. if (!active(out))
  452. goto unlock;
  453. if (!packet) {
  454. mp4_output_actual_stop(out, OBS_OUTPUT_ENCODE_ERROR);
  455. goto unlock;
  456. }
  457. if (stopping(out)) {
  458. if (packet->sys_dts_usec >= (int64_t)out->stop_ts) {
  459. mp4_output_actual_stop(out, 0);
  460. goto unlock;
  461. }
  462. }
  463. if (out->split_file_enabled) {
  464. if (out->split_buffer.num) {
  465. int64_t pts_usec = packet_pts_usec(packet);
  466. struct encoder_packet *first_pkt = out->split_buffer.array;
  467. int64_t first_pts_usec = packet_pts_usec(first_pkt);
  468. if (pts_usec >= first_pts_usec) {
  469. if (packet->type != OBS_ENCODER_AUDIO) {
  470. push_back_packet(out, packet);
  471. goto unlock;
  472. }
  473. if (!change_file(out, first_pkt)) {
  474. mp4_output_actual_stop(out, OBS_OUTPUT_ERROR);
  475. goto unlock;
  476. }
  477. out->split_file_ready = true;
  478. }
  479. } else if (should_split(out, packet)) {
  480. push_back_packet(out, packet);
  481. goto unlock;
  482. }
  483. }
  484. if (out->split_file_ready) {
  485. for (size_t i = 0; i < out->split_buffer.num; i++) {
  486. struct encoder_packet *pkt = &out->split_buffer.array[i];
  487. ts_offset_update(out, pkt);
  488. submit_packet(out, pkt);
  489. obs_encoder_packet_release(pkt);
  490. }
  491. da_free(out->split_buffer);
  492. out->split_file_ready = false;
  493. os_atomic_set_bool(&out->manual_split, false);
  494. }
  495. if (out->split_file_enabled)
  496. ts_offset_update(out, packet);
  497. submit_packet(out, packet);
  498. if (serializer_get_pos(&out->serializer) == -1)
  499. mp4_output_actual_stop(out, OBS_OUTPUT_ERROR);
  500. unlock:
  501. pthread_mutex_unlock(&out->mutex);
  502. }
  503. static obs_properties_t *mp4_output_properties(void *unused)
  504. {
  505. UNUSED_PARAMETER(unused);
  506. obs_properties_t *props = obs_properties_create();
  507. obs_properties_add_text(props, "path", obs_module_text("MP4Output.FilePath"), OBS_TEXT_DEFAULT);
  508. obs_properties_add_text(props, "muxer_settings", "muxer_settings", OBS_TEXT_DEFAULT);
  509. return props;
  510. }
  511. uint64_t mp4_output_total_bytes(void *data)
  512. {
  513. struct mp4_output *out = data;
  514. return out->total_bytes;
  515. }
  516. struct obs_output_info mp4_output_info = {
  517. .id = "mp4_output",
  518. .flags = OBS_OUTPUT_AV | OBS_OUTPUT_ENCODED | OBS_OUTPUT_MULTI_TRACK_AV | OBS_OUTPUT_CAN_PAUSE,
  519. .encoded_video_codecs = "h264;hevc;av1",
  520. .encoded_audio_codecs = "aac;alac;flac;opus",
  521. .get_name = mp4_output_name,
  522. .create = mp4_output_create,
  523. .destroy = mp4_output_destroy,
  524. .start = mp4_output_start,
  525. .stop = mp4_output_stop,
  526. .encoded_packet = mp4_output_packet,
  527. .get_properties = mp4_output_properties,
  528. .get_total_bytes = mp4_output_total_bytes,
  529. };
  530. struct obs_output_info mov_output_info = {
  531. .id = "mov_output",
  532. .flags = OBS_OUTPUT_AV | OBS_OUTPUT_ENCODED | OBS_OUTPUT_MULTI_TRACK_AV | OBS_OUTPUT_CAN_PAUSE,
  533. .encoded_video_codecs = "h264;hevc;prores",
  534. .encoded_audio_codecs = "aac;alac",
  535. .get_name = mov_output_name,
  536. .create = mov_output_create,
  537. .destroy = mp4_output_destroy,
  538. .start = mp4_output_start,
  539. .stop = mp4_output_stop,
  540. .encoded_packet = mp4_output_packet,
  541. .get_properties = mp4_output_properties,
  542. .get_total_bytes = mp4_output_total_bytes,
  543. };