Teach filter subcommand to recognize --skip and --take options
This commit is contained in:
parent
bfe7d4b1d7
commit
2b88d09d0f
2 changed files with 17 additions and 4 deletions
|
@ -1,4 +1,5 @@
|
|||
## v0.3.1-dev
|
||||
- Teach filter subcommand to recognize --skip and --take options
|
||||
- MSRV now rustc 1.61
|
||||
- forget a channel's initialization segment when no transmitter is active. This improves behavior when a channel is occasionally used for streams with different codecs.
|
||||
- Add INFO logging for channel creation/garbage-collection
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
use std::{io, io::prelude::*, pin::Pin};
|
||||
use std::{io, io::prelude::*, pin::Pin, time::Duration};
|
||||
|
||||
use clap::Args;
|
||||
use futures::prelude::*;
|
||||
|
||||
use super::stdin_stream;
|
||||
use super::{parse_time, stdin_stream};
|
||||
use webmetro::{
|
||||
chunk::{Chunk, WebmStream},
|
||||
error::WebmetroError,
|
||||
|
@ -15,19 +15,31 @@ use webmetro::{
|
|||
#[derive(Args, Debug)]
|
||||
pub struct FilterArgs {
|
||||
/// Slow down output to "real time" speed as determined by the timestamps (useful for streaming static files)
|
||||
#[clap(long, short)]
|
||||
#[clap(long)]
|
||||
throttle: bool,
|
||||
/// Skip approximately n seconds of content before uploading or throttling
|
||||
#[clap(long, short, parse(try_from_str = parse_time))]
|
||||
skip: Option<Duration>,
|
||||
/// Stop uploading after approximately n seconds of content
|
||||
#[clap(long, short, parse(try_from_str = parse_time))]
|
||||
take: Option<Duration>,
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
pub async fn run(args: FilterArgs) -> Result<(), WebmetroError> {
|
||||
let start_time = args.skip.map_or(0, |s| s.as_millis());
|
||||
let stop_time = args
|
||||
.take
|
||||
.map_or(std::u128::MAX, |t| t.as_millis() + start_time);
|
||||
|
||||
let mut timecode_fixer = ChunkTimecodeFixer::new();
|
||||
let mut chunk_stream: Pin<Box<dyn Stream<Item = Result<Chunk, WebmetroError>> + Send>> =
|
||||
Box::pin(
|
||||
stdin_stream()
|
||||
.parse_ebml()
|
||||
.chunk_webm()
|
||||
.map_ok(move |chunk| timecode_fixer.process(chunk)),
|
||||
.map_ok(move |chunk| timecode_fixer.process(chunk))
|
||||
.try_filter(move |chunk| future::ready(chunk.overlaps(start_time, stop_time))),
|
||||
);
|
||||
|
||||
if args.throttle {
|
||||
|
|
Loading…
Reference in a new issue