aboutsummaryrefslogtreecommitdiff
path: root/remuxer/src/extract.rs
diff options
context:
space:
mode:
authormetamuffin <metamuffin@disroot.org>2025-09-13 16:08:42 +0200
committermetamuffin <metamuffin@disroot.org>2025-09-13 16:08:42 +0200
commit044c7e1c75145f1ec9d002b4f6fc4433ff7f9540 (patch)
treedb326c8f2327396ed443a1822936927e7c847494 /remuxer/src/extract.rs
parente99bde7a00a161ff5dd91eaf1ce546a9d98cef05 (diff)
downloadjellything-044c7e1c75145f1ec9d002b4f6fc4433ff7f9540.tar
jellything-044c7e1c75145f1ec9d002b4f6fc4433ff7f9540.tar.bz2
jellything-044c7e1c75145f1ec9d002b4f6fc4433ff7f9540.tar.zst
start remuxer crate rewrite; added matroska demuxer and format detection
Diffstat (limited to 'remuxer/src/extract.rs')
-rw-r--r--remuxer/src/extract.rs51
1 files changed, 0 insertions, 51 deletions
diff --git a/remuxer/src/extract.rs b/remuxer/src/extract.rs
deleted file mode 100644
index 15c1e9d..0000000
--- a/remuxer/src/extract.rs
+++ /dev/null
@@ -1,51 +0,0 @@
-/*
- This file is part of jellything (https://codeberg.org/metamuffin/jellything)
- which is licensed under the GNU Affero General Public License (version 3); see /COPYING.
- Copyright (C) 2025 metamuffin <metamuffin.org>
-*/
-use crate::seek_index::get_seek_index;
-use anyhow::{anyhow, bail};
-use jellymatroska::{block::Block, read::EbmlReader, Master, MatroskaTag};
-use log::debug;
-use std::{fs::File, io::BufReader, path::PathBuf};
-
-pub type TrackExtract = Vec<(u64, Option<u64>, Vec<u8>)>;
-pub fn extract_track(path: PathBuf, track: u64) -> anyhow::Result<TrackExtract> {
- let file = File::open(&path)?;
- let mut reader = EbmlReader::new(BufReader::new(file));
- let index = get_seek_index(&path)?;
- let index = index.get(&track).ok_or(anyhow!("track missing"))?;
-
- let mut out = Vec::new();
- for b in &index.blocks {
- reader.seek(b.source_off, MatroskaTag::BlockGroup(Master::Start))?;
- let (duration, block) = read_group(&mut reader)?;
- assert_eq!(track, block.track, "seek index is wrong");
- out.push((b.pts, duration, block.data))
- }
- Ok(out)
-}
-
-pub fn read_group(segment: &mut EbmlReader) -> anyhow::Result<(Option<u64>, Block)> {
- let (mut dur, mut block) = (None, None);
- for _ in 0..10 {
- let (_, item) = segment.next().ok_or(anyhow!("eof"))??;
- match item {
- MatroskaTag::Void(_) => (),
- MatroskaTag::Crc32(_) => (),
- MatroskaTag::Cluster(_) => bail!("unexpected cluster"),
- MatroskaTag::Timestamp(_) => (),
- MatroskaTag::SimpleBlock(block) => {
- return Ok((None, block)); // HDMV/PGS does not use duration?!
- }
- MatroskaTag::BlockGroup(Master::Start) => (),
- MatroskaTag::BlockGroup(Master::End) => return Ok((dur, block.unwrap())),
- MatroskaTag::BlockDuration(duration) => dur = Some(duration),
- MatroskaTag::Block(blk) => block = Some(blk),
- MatroskaTag::Cues(_) => bail!("reached cues, this is the end"),
- MatroskaTag::Segment(Master::End) => bail!("extractor reached segment end"),
- _ => debug!("(rs) tag ignored: {item:?}"),
- }
- }
- bail!(".")
-}