diff options
author | metamuffin <metamuffin@disroot.org> | 2023-01-17 23:08:57 +0100 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2023-01-17 23:08:57 +0100 |
commit | 5aa557e864bd2cf940e7164b7568e7e545817306 (patch) | |
tree | 6eec3a834c4217dbf1208dc9b34bb7debddb1d9c /remuxer/src/lib.rs | |
parent | cda5929b5176947490bcf0f661f61b4b9d5ea7c1 (diff) | |
download | jellything-5aa557e864bd2cf940e7164b7568e7e545817306.tar jellything-5aa557e864bd2cf940e7164b7568e7e545817306.tar.bz2 jellything-5aa557e864bd2cf940e7164b7568e7e545817306.tar.zst |
wokrs
Diffstat (limited to 'remuxer/src/lib.rs')
-rw-r--r-- | remuxer/src/lib.rs | 39 |
1 files changed, 29 insertions, 10 deletions
diff --git a/remuxer/src/lib.rs b/remuxer/src/lib.rs index 523569a..bc0aff7 100644 --- a/remuxer/src/lib.rs +++ b/remuxer/src/lib.rs @@ -34,7 +34,7 @@ impl RemuxerContext { iteminfo: ItemInfo, selection: Vec<u64>, ) -> anyhow::Result<()> { - let source_path = path_base.join(format!("demon-slayer-1.mkv")); + let source_path = path_base.join(&iteminfo.path); info!("remuxing {source_path:?} to have tracks {selection:?}"); let input = File::open(source_path)?; @@ -55,7 +55,8 @@ impl RemuxerContext { MatroskaTag::EbmlReadVersion(1), MatroskaTag::EbmlMaxIdLength(4), MatroskaTag::EbmlMaxSizeLength(8), - MatroskaTag::DocType("matroska".to_string()), + // MatroskaTag::DocType("matroska".to_string()), + MatroskaTag::DocType("webm".to_string()), MatroskaTag::DocTypeVersion(4), MatroskaTag::DocTypeReadVersion(2), ])))?; @@ -63,11 +64,14 @@ impl RemuxerContext { output.write_tag(&MatroskaTag::Segment(Master::Start))?; 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::Duration(1000.0), MatroskaTag::MuxingApp("jellyremux".to_string()), MatroskaTag::WritingApp("jellything".to_string()), ])))?; + output.write_tag(&MatroskaTag::Tags(Master::Collected(vec![])))?; + // output.write_tag(&MatroskaTag::Cues(Master::Collected(vec![])))?; let tracks_header = MatroskaTag::Tracks(Master::Collected( mapping @@ -87,6 +91,9 @@ impl RemuxerContext { } }; match item { + MatroskaTag::Ebml(_) => { + Unflatten::new_with_end(&mut input, item); + } MatroskaTag::Segment(_) => { info!("segment start"); let mut children = Unflatten::new_with_end(&mut input, item); @@ -115,10 +122,14 @@ fn filter_segment( MatroskaTag::Info(_) => {} MatroskaTag::Cluster(_) => { let mut cluster = vec![]; - info!("start of cluster found"); let mut children = children.unwrap(); while let Some(Ok(Unflat { children, item })) = children.next() { match item { + MatroskaTag::Crc32(_) => (), + MatroskaTag::Timestamp(ts) => { + info!("ts={ts}"); + cluster.push(MatroskaTag::Timestamp(ts)); + } MatroskaTag::BlockGroup(_) => { debug!("group"); let mut children = children.unwrap(); @@ -129,14 +140,18 @@ fn filter_segment( let mut block = Block::parse(&buf)?; if let Some(outnum) = mapping.get(&block.track) { block.track = *outnum; - debug!( + trace!( "block: track={} tso={}", - block.track, block.timestamp_off + block.track, + block.timestamp_off ); group.push(MatroskaTag::Block(block.dump())); } } - _ => trace!("{item:?}"), + MatroskaTag::BlockDuration(v) => { + group.push(MatroskaTag::BlockDuration(v)); + } + _ => debug!("ignored {item:?}"), } } cluster.push(MatroskaTag::BlockGroup(Master::Collected(group))); @@ -145,11 +160,11 @@ fn filter_segment( let mut block = Block::parse(&buf)?; if let Some(outnum) = mapping.get(&block.track) { block.track = *outnum; - debug!("block: track={} tso={}", block.track, block.timestamp_off); + trace!("block: track={} tso={}", block.track, block.timestamp_off); cluster.push(MatroskaTag::SimpleBlock(block.dump())); } } - _ => debug!("(rsc) tag ignored: {item:?}"), + _ => warn!("(rsc) tag ignored: {item:?}"), } } writer.write_tag(&MatroskaTag::Cluster(Master::Collected(cluster)))?; @@ -171,6 +186,9 @@ pub fn track_to_ebml(number: u64, track: &SourceTrack) -> MatroskaTag { els.push(MatroskaTag::FlagLacing(0)); els.push(MatroskaTag::Language(track.language.clone())); els.push(MatroskaTag::CodecID(track.codec.clone())); + if let Some(d) = &track.default_duration { + els.push(MatroskaTag::DefaultDuration(*d)); + } match track.kind { SourceTrackKind::Video { width, height, fps } => { els.push(MatroskaTag::TrackType(1)); @@ -189,7 +207,8 @@ pub fn track_to_ebml(number: u64, track: &SourceTrack) -> MatroskaTag { els.push(MatroskaTag::Audio(Master::Collected(vec![ MatroskaTag::SamplingFrequency(sample_rate), MatroskaTag::Channels(channels.try_into().unwrap()), - ]))) + ]))); + els.push(MatroskaTag::BitDepth(bit_depth.try_into().unwrap())); } SourceTrackKind::Subtitles => { els.push(MatroskaTag::TrackType(19)); |