Skip to content

Commit

Permalink
Use stdin(Stdio::null()) for all Commands when not use stdin (#53)
Browse files Browse the repository at this point in the history
* Null all stdin when not using them

Fixes the terminal getting trashed sometimes no ctrl_c

* Cargo update

Keep console back to 0.15.1 to avoid lazy_static

* Remove with_finish calls & update changelog
  • Loading branch information
alexheretic authored Sep 30, 2022
1 parent 0727373 commit b3acdaa
Show file tree
Hide file tree
Showing 11 changed files with 34 additions and 31 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Unreleased
* Leave incomplete progress bars when exitting early with _ctrl c_ instead of clearing them.
# Unreleased (v0.4.3)
* Fix terminal breaking sometimes after exitting early.

# v0.4.2
* Update _indicatif_ dependency to `0.17`.
Expand Down
17 changes: 8 additions & 9 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 7 additions & 9 deletions src/command/auto_encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
};
use clap::Parser;
use console::style;
use indicatif::{ProgressBar, ProgressFinish, ProgressStyle};
use indicatif::{ProgressBar, ProgressStyle};
use std::time::Duration;

/// Automatically determine the best crf to deliver the min-vmaf and use it to encode a video.
Expand Down Expand Up @@ -39,13 +39,11 @@ pub async fn auto_encode(Args { mut search, encode }: Args) -> anyhow::Result<()
.output
.unwrap_or_else(|| default_output_from(&search.args));

let bar = ProgressBar::new(12)
.with_style(
ProgressStyle::default_bar()
.template(SPINNER_RUNNING)?
.progress_chars(PROGRESS_CHARS),
)
.with_finish(ProgressFinish::Abandon);
let bar = ProgressBar::new(12).with_style(
ProgressStyle::default_bar()
.template(SPINNER_RUNNING)?
.progress_chars(PROGRESS_CHARS),
);

bar.set_prefix("Searching");
if defaulting_output {
Expand Down Expand Up @@ -97,7 +95,7 @@ pub async fn auto_encode(Args { mut search, encode }: Args) -> anyhow::Result<()
ProgressStyle::default_bar()
.template("{spinner:.cyan.bold} {prefix} {elapsed_precise:.bold} {wide_bar:.cyan/blue} ({msg}eta {eta})")?
.progress_chars(PROGRESS_CHARS)
).with_finish(ProgressFinish::Abandon);
);
bar.set_prefix("Encoding ");
bar.enable_steady_tick(Duration::from_millis(100));

Expand Down
4 changes: 2 additions & 2 deletions src/command/crf_search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
use clap::Parser;
use console::style;
use err::ensure_other;
use indicatif::{HumanBytes, HumanDuration, ProgressBar, ProgressFinish, ProgressStyle};
use indicatif::{HumanBytes, HumanDuration, ProgressBar, ProgressStyle};
use std::time::Duration;

const BAR_LEN: u64 = 1000;
Expand Down Expand Up @@ -59,7 +59,7 @@ pub async fn crf_search(args: Args) -> anyhow::Result<()> {
ProgressStyle::default_bar()
.template("{spinner:.cyan.bold} {elapsed_precise:.bold} {wide_bar:.cyan/blue} ({msg}eta {eta})")?
.progress_chars(PROGRESS_CHARS)
).with_finish(ProgressFinish::Abandon);
);

let best = run(&args, bar.clone()).await;
bar.finish();
Expand Down
4 changes: 2 additions & 2 deletions src/command/encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ use crate::{
};
use clap::Parser;
use console::style;
use indicatif::{HumanBytes, ProgressBar, ProgressFinish, ProgressStyle};
use indicatif::{HumanBytes, ProgressBar, ProgressStyle};
use std::{path::PathBuf, time::Duration};
use tokio::fs;
use tokio_stream::StreamExt;
Expand All @@ -35,7 +35,7 @@ pub async fn encode(args: Args) -> anyhow::Result<()> {
ProgressStyle::default_bar()
.template("{spinner:.cyan.bold} {elapsed_precise:.bold} {wide_bar:.cyan/blue} ({msg}eta {eta})")?
.progress_chars(PROGRESS_CHARS)
).with_finish(ProgressFinish::Abandon);
);
bar.enable_steady_tick(Duration::from_millis(100));

run(args, &bar).await
Expand Down
4 changes: 2 additions & 2 deletions src/command/sample_encode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use crate::{
use anyhow::ensure;
use clap::Parser;
use console::style;
use indicatif::{HumanBytes, HumanDuration, ProgressBar, ProgressFinish, ProgressStyle};
use indicatif::{HumanBytes, HumanDuration, ProgressBar, ProgressStyle};
use std::{
path::PathBuf,
sync::Arc,
Expand Down Expand Up @@ -62,7 +62,7 @@ pub async fn sample_encode(args: Args) -> anyhow::Result<()> {
ProgressStyle::default_bar()
.template("{spinner:.cyan.bold} {elapsed_precise:.bold} {prefix} {wide_bar:.cyan/blue} ({msg:13} eta {eta})")?
.progress_chars(PROGRESS_CHARS)
).with_finish(ProgressFinish::Abandon);
);
bar.enable_steady_tick(Duration::from_millis(100));

run(args, bar).await?;
Expand Down
4 changes: 2 additions & 2 deletions src/command/vmaf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use crate::{
vmaf::VmafOut,
};
use clap::Parser;
use indicatif::{ProgressBar, ProgressFinish, ProgressStyle};
use indicatif::{ProgressBar, ProgressStyle};
use std::{path::PathBuf, time::Duration};
use tokio_stream::StreamExt;

Expand Down Expand Up @@ -45,7 +45,7 @@ pub async fn vmaf(
ProgressStyle::default_bar()
.template("{spinner:.cyan.bold} {elapsed_precise:.bold} {wide_bar:.cyan/blue} ({msg}eta {eta})")?
.progress_chars(PROGRESS_CHARS)
).with_finish(ProgressFinish::Abandon);
);
bar.enable_steady_tick(Duration::from_millis(100));
bar.set_message("vmaf running, ");

Expand Down
2 changes: 2 additions & 0 deletions src/ffmpeg.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ pub fn encode_sample(
.arg2_opt("-vf", vfilter)
.arg("-an")
.arg(&dest)
.stdin(Stdio::null())
.stdout(Stdio::null())
.stderr(Stdio::piped())
.spawn()
Expand Down Expand Up @@ -125,6 +126,7 @@ pub fn encode(
.arg2_if(set_ba_128k, "-b:a", "128k")
.arg2_if(add_faststart, "-movflags", "+faststart")
.arg(output)
.stdin(Stdio::null())
.stdout(Stdio::null())
.stderr(Stdio::piped())
.spawn()
Expand Down
2 changes: 2 additions & 0 deletions src/sample.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ use crate::{
use anyhow::Context;
use std::{
path::{Path, PathBuf},
process::Stdio,
time::Duration,
};
use tokio::process::Command;
Expand Down Expand Up @@ -44,6 +45,7 @@ pub async fn copy(
.arg2("-c:v", "copy")
.arg("-an")
.arg(&dest)
.stdin(Stdio::null())
.output()
.await
.context("ffmpeg copy")?;
Expand Down
6 changes: 3 additions & 3 deletions src/svtav1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,6 @@ pub fn encode(

let to_output = Command::new("ffmpeg")
.kill_on_drop(true)
.stdin(svt_out)
.stdout(Stdio::null())
.stderr(Stdio::piped())
.arg("-y")
.arg2("-i", "-")
.arg2("-i", input)
Expand All @@ -141,6 +138,9 @@ pub fn encode(
.arg2_if(audio_codec == "libopus", "-b:a", "128k")
.arg2_if(add_faststart, "-movflags", "+faststart")
.arg(output)
.stdin(svt_out)
.stdout(Stdio::null())
.stderr(Stdio::piped())
.spawn()
.context("ffmpeg to-output")?;

Expand Down
2 changes: 2 additions & 0 deletions src/yuv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ pub fn pipe(
.arg2("-strict", "-1")
.arg2("-f", "yuv4mpegpipe")
.arg("-")
.stdin(Stdio::null())
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.spawn()
Expand Down Expand Up @@ -60,6 +61,7 @@ pub mod unix {
.arg2("-f", "yuv4mpegpipe")
.arg("-y")
.arg(&fifo)
.stdin(Stdio::null())
.stdout(Stdio::null())
.stderr(Stdio::piped())
.spawn()
Expand Down

0 comments on commit b3acdaa

Please sign in to comment.