aboutsummaryrefslogtreecommitdiff
path: root/remuxer/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'remuxer/src/lib.rs')
-rw-r--r--remuxer/src/lib.rs67
1 files changed, 48 insertions, 19 deletions
diff --git a/remuxer/src/lib.rs b/remuxer/src/lib.rs
index 1dfbacd..3ce6b78 100644
--- a/remuxer/src/lib.rs
+++ b/remuxer/src/lib.rs
@@ -21,6 +21,7 @@ use std::{collections::VecDeque, fs::File, io::Write, path::PathBuf};
pub struct RemuxerContext {}
impl RemuxerContext {
+ #[allow(clippy::new_without_default)]
pub fn new() -> Self {
Self {}
}
@@ -63,7 +64,7 @@ impl RemuxerContext {
info!("\t {}", info);
let file = File::open(&source_path).context("opening source file")?;
let mut index =
- File::open(source_path.with_extension(&format!("si.{}", info.track_number)))
+ File::open(source_path.with_extension(format!("si.{}", info.track_number)))
.context("opening seek index file")?;
let index = bincode::decode_from_std_read::<SeekIndex, _, _>(
&mut index,
@@ -79,7 +80,6 @@ impl RemuxerContext {
temp_index: 0,
})
})
- .into_iter()
.collect::<anyhow::Result<Vec<_>>>()?;
output.write_tag(&MatroskaTag::Ebml(Master::Collected(vec![
@@ -101,7 +101,7 @@ impl RemuxerContext {
output.write_tag(&MatroskaTag::Info(Master::Collected(vec![
MatroskaTag::TimestampScale(1_000_000),
MatroskaTag::Duration(iteminfo.duration * 1000.0),
- MatroskaTag::Title(iteminfo.title.clone()),
+ MatroskaTag::Title(iteminfo.title),
MatroskaTag::MuxingApp("jellyremux".to_string()),
MatroskaTag::WritingApp("jellything".to_string()),
])))?;
@@ -145,7 +145,7 @@ impl RemuxerContext {
if best_block.pts > cluster_pts + 2_000 {
let cluster_content_size = 1 // timestamp tag
+ 1 // timestamp tag size
- + EbmlWriter::vint_length(cluster_pts as u64) // timestamp tag value
+ + EbmlWriter::vint_length(cluster_pts) // timestamp tag value
+ p;
let cluster_header_size = 4 // tag length
+ EbmlWriter::vint_length(cluster_content_size as u64)// size varint
@@ -153,7 +153,7 @@ impl RemuxerContext {
clusters.push(ClusterLayout {
position: gp,
timestamp: cluster_pts,
- blocks: std::mem::replace(&mut cluster, vec![]),
+ blocks: std::mem::take(&mut cluster),
});
cluster_pts = best_block.pts;
@@ -174,6 +174,34 @@ impl RemuxerContext {
clusters
};
+ output.write_tag(&MatroskaTag::Cues(Master::Collected(
+ segment_layout
+ .iter()
+ .map(|cluster| {
+ MatroskaTag::CuePoint(Master::Collected(
+ [
+ MatroskaTag::CueTime(cluster.timestamp),
+ MatroskaTag::CueTrackPositions(Master::Collected(
+ [
+ MatroskaTag::CueTrack(0),
+ MatroskaTag::CueClusterPosition(cluster.position as u64),
+ ]
+ .to_vec(),
+ )),
+ MatroskaTag::CueTrackPositions(Master::Collected(
+ [
+ MatroskaTag::CueTrack(1),
+ MatroskaTag::CueClusterPosition(cluster.position as u64),
+ ]
+ .to_vec(),
+ )),
+ ]
+ .to_vec(),
+ ))
+ })
+ .collect(),
+ )))?;
+
struct ReaderD<'a> {
_info: SourceTrack,
peek: Option<AbsoluteBlock>,
@@ -206,6 +234,7 @@ impl RemuxerContext {
});
}
+ let segment_start_position = output.position();
for (cluster_index, cluster) in segment_layout.into_iter().enumerate() {
info!(
"writing cluster {cluster_index} (pts_base={}) with {} blocks",
@@ -214,9 +243,9 @@ impl RemuxerContext {
);
debug!(
"calculation was {} bytes off",
- cluster.position as i64 - output.position() as i64
+ cluster.position as i64 - (output.position() - segment_start_position) as i64
);
- let mut cluster_blocks = vec![MatroskaTag::Timestamp(cluster.timestamp as u64)];
+ let mut cluster_blocks = vec![MatroskaTag::Timestamp(cluster.timestamp)];
for (block_index, iblock) in cluster.blocks {
let kn = &mut ks[block_index];
let mut block = kn
@@ -268,14 +297,14 @@ impl SegmentExtractIter<'_> {
}
pub fn read(&mut self) -> Result<()> {
- let Unflat { children, item } = self.segment.next().ok_or(anyhow!("eof"))??;
+ let Unflat { children, item } = self.segment.n().ok_or(anyhow!("eof"))??;
let mut pts_base = 0;
match item {
MatroskaTag::SeekHead(_) => {}
MatroskaTag::Info(_) => {}
MatroskaTag::Cluster(_) => {
let mut children = children.unwrap();
- while let Some(Ok(Unflat { children, item })) = children.next() {
+ while let Some(Ok(Unflat { children, item })) = children.n() {
match item {
MatroskaTag::Crc32(_) => (),
MatroskaTag::Timestamp(ts) => {
@@ -286,18 +315,17 @@ impl SegmentExtractIter<'_> {
trace!("group");
let mut children = children.unwrap();
- let mut duration = None;
+ // let mut duration = None;
let mut block = None;
- while let Some(Ok(Unflat { children: _, item })) = children.next() {
+ while let Some(Ok(Unflat { children: _, item })) = children.n() {
match item {
MatroskaTag::Block(buf) => block = Some(buf),
- MatroskaTag::BlockDuration(v) => duration = Some(v),
+ // MatroskaTag::BlockDuration(v) => duration = Some(v),
_ => debug!("ignored {item:?}"),
}
}
// TODO duration
- drop(duration);
let block = Block::parse(&block.unwrap())?;
if block.track == self.extract {
trace!("block: track={} tso={}", block.track, block.timestamp_off);
@@ -333,12 +361,13 @@ impl SegmentExtractIter<'_> {
}
pub fn track_to_ebml(number: u64, track: &SourceTrack) -> MatroskaTag {
- let mut els = Vec::new();
- els.push(MatroskaTag::TrackNumber(number));
- els.push(MatroskaTag::TrackUID(number));
- els.push(MatroskaTag::FlagLacing(0));
- els.push(MatroskaTag::Language(track.language.clone()));
- els.push(MatroskaTag::CodecID(track.codec.clone()));
+ let mut els = vec![
+ MatroskaTag::TrackNumber(number),
+ MatroskaTag::TrackUID(number),
+ MatroskaTag::FlagLacing(0),
+ MatroskaTag::Language(track.language.clone()),
+ MatroskaTag::CodecID(track.codec.clone()),
+ ];
if let Some(d) = &track.default_duration {
els.push(MatroskaTag::DefaultDuration(*d));
}