ChapterForge
Loading...
Searching...
No Matches
mp4_muxer.hpp
Go to the documentation of this file.
1//
2// mp4_muxer.hpp
3// ChapterForge
4//
5// Created by Till Toenshoff on 12/9/25.
6// Copyright © 2025 Till Toenshoff. All rights reserved.
7//
8
9#pragma once
10
11#include <cstdint>
12#include <memory>
13#include <string>
14#include <vector>
15#include <utility>
16
17#include "aac_extractor.hpp"
18#include "metadata_set.hpp"
19#include "mp4_atoms.hpp"
20#include "mp4a_builder.hpp"
22#include "stbl_text_builder.hpp"
23
24// Complete MP4 writer: takes raw AAC (ADTS) bytes, chapter text/image samples,
25// audio config, and metadata.
26// Exposed for embedding; prefer the higher-level helper in chapterforge.hpp when linking externally.
27bool write_mp4(const std::string &path, const AacExtractResult &aac,
28 const std::vector<ChapterTextSample> &text_chapters,
29 const std::vector<ChapterImageSample> &image_chapters, Mp4aConfig audio_cfg,
30 const MetadataSet &meta, bool fast_start = true,
31 const std::vector<std::pair<std::string, std::vector<ChapterTextSample>>>
32 &extra_text_tracks = {},
33 const std::vector<uint8_t> *ilst_payload = nullptr,
34 const std::vector<uint8_t> *meta_payload = nullptr);
35
36#ifdef CHAPTERFORGE_TESTING
37namespace chapterforge::testing {
38struct TestDurationInfo {
39 uint32_t audio_timescale = 0;
40 uint64_t audio_duration_ts = 0;
41 uint32_t audio_duration_ms = 0;
42 std::vector<uint32_t> text_ms;
43 std::vector<uint32_t> image_ms;
44};
45
46std::vector<uint32_t> build_audio_chunk_plan_for_test(uint32_t sample_count);
47std::vector<uint32_t> derive_chunk_plan_for_test(const std::vector<uint8_t> &stsc_payload,
48 uint32_t sample_count);
49std::vector<uint8_t> encode_tx3g_sample_for_test(const ChapterTextSample &sample);
50std::vector<std::vector<uint8_t>> encode_tx3g_track_for_test(
51 const std::vector<ChapterTextSample> &chapters);
52TestDurationInfo compute_durations_for_test(
53 const AacExtractResult &aac, Mp4aConfig audio_cfg,
54 const std::vector<ChapterTextSample> &text_chapters,
55 const std::vector<ChapterImageSample> &image_chapters);
56} // namespace chapterforge::testing
57#endif
Definition aac_extractor.hpp:15
Definition chapter_text_sample.hpp:16
Definition metadata_set.hpp:16
bool write_mp4(const std::string &path, const AacExtractResult &aac, const std::vector< ChapterTextSample > &text_chapters, const std::vector< ChapterImageSample > &image_chapters, Mp4aConfig audio_cfg, const MetadataSet &meta, bool fast_start=true, const std::vector< std::pair< std::string, std::vector< ChapterTextSample > > > &extra_text_tracks={}, const std::vector< uint8_t > *ilst_payload=nullptr, const std::vector< uint8_t > *meta_payload=nullptr)
Definition mp4a_builder.hpp:17