aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--matroska/src/write.rs2
-rw-r--r--remuxer/src/lib.rs42
2 files changed, 41 insertions, 3 deletions
diff --git a/matroska/src/write.rs b/matroska/src/write.rs
index 63cec2b..0b3b167 100644
--- a/matroska/src/write.rs
+++ b/matroska/src/write.rs
@@ -5,6 +5,7 @@
*/
use crate::{matroska::MatroskaTag, size::EbmlSize, Master};
use anyhow::{bail, Result};
+use log::debug;
use std::io::{Seek, Write};
pub struct EbmlWriter<W> {
@@ -28,6 +29,7 @@ impl<W: Write> EbmlWriter<W> {
}
pub fn write_padding(&mut self, position: usize) -> Result<()> {
+ debug!("padding up to {position}");
let mut size = position - self.position;
match size {
0 => return Ok(()),
diff --git a/remuxer/src/lib.rs b/remuxer/src/lib.rs
index 34991e2..c68c9b0 100644
--- a/remuxer/src/lib.rs
+++ b/remuxer/src/lib.rs
@@ -138,7 +138,7 @@ impl RemuxerContext {
blocks: Vec<(usize, BlockIndex)>,
}
- let segment_layout = {
+ let mut segment_layout: Vec<ClusterLayout> = {
let mut cluster_pts = 0;
let mut clusters = vec![];
let mut cluster = vec![];
@@ -173,7 +173,7 @@ impl RemuxerContext {
+ vint_length(cluster_content_size as u64) // size varint
+ cluster_content_size;
clusters.push(ClusterLayout {
- position: gp + 7860, // TODO this needs calculation
+ position: gp, // relative to the first cluster
timestamp: cluster_pts,
source_offsets,
blocks: std::mem::take(&mut cluster),
@@ -206,6 +206,38 @@ impl RemuxerContext {
);
let timing_cp = Instant::now();
+ let max_cue_size = 4 // cues id
+ + 8 // cues len
+ + ( // cues content
+ 1 // cp id
+ + 1 // cp len
+ + ( // cp content
+ 1 // ctime id,
+ + 1 // ctime len
+ + 8 // ctime content uint
+ + ( // ctps
+ 1 // ctp id
+ + 8 // ctp len
+ + (// ctp content
+ 1 // ctrack id
+ + 1 // ctrack size
+ + 1 // ctrack content int
+ // TODO break if inputs.len() >= 127
+ + 1 // ccp id
+ + 1 // ccp len
+ + 8 // ccp content offset
+ )
+ )
+ ) * inputs.len()
+ ) * segment_layout.len()
+ + 1 // void id
+ + 8; // void len
+
+ let first_cluster_offset_predict = max_cue_size + output.position();
+
+ // make the cluster position relative to the segment start as they should
+ segment_layout.iter_mut().for_each(|e| e.position += first_cluster_offset_predict - segment_offset);
+
output.write_tag(&MatroskaTag::Cues(Master::Collected(
segment_layout
.iter()
@@ -225,8 +257,12 @@ impl RemuxerContext {
})
.collect(),
)))?;
-
+ eprintln!("posbefore={}", output.position());
+ output.write_padding(first_cluster_offset_predict)?;
+ eprintln!("posafter={}", output.position());
let first_cluster_offset = output.position();
+ assert_eq!(first_cluster_offset, first_cluster_offset_predict);
+
eprintln!("{}", first_cluster_offset - segment_offset);
let mut skip = 0;
for (i, cluster) in segment_layout.iter().enumerate() {