diff --git a/av1an-cli/src/lib.rs b/av1an-cli/src/lib.rs index 78c0d32..0069c5c 100644 --- a/av1an-cli/src/lib.rs +++ b/av1an-cli/src/lib.rs @@ -1,31 +1,24 @@ -use ::ffmpeg::format::Pixel; -use ansi_term::{Color, Style}; -use anyhow::{anyhow, Context}; -use anyhow::{bail, ensure}; -use av1an_core::progress_bar::{get_first_multi_progress_bar, get_progress_bar}; -use av1an_core::settings::{InputPixelFormat, PixelFormat}; -use av1an_core::util::read_in_dir; -use av1an_core::ScenecutMethod; -use av1an_core::{ffmpeg, into_vec}; -use av1an_core::{ChunkOrdering, Input}; -use flexi_logger::writers::LogWriter; -use flexi_logger::{FileSpec, Level, LevelFilter, LogSpecBuilder, Logger}; -use path_abs::{PathAbs, PathInfo}; use std::io::{self, Write}; use std::path::{Path, PathBuf}; use std::process::exit; -use clap::{AppSettings, Parser}; - +use ::ffmpeg::format::Pixel; +use ansi_term::{Color, Style}; +use anyhow::{anyhow, bail, ensure, Context}; +use av1an_core::concat::ConcatMethod; +use av1an_core::encoder::Encoder; +use av1an_core::progress_bar::{get_first_multi_progress_bar, get_progress_bar}; +use av1an_core::settings::{EncodeArgs, InputPixelFormat, PixelFormat}; +use av1an_core::util::read_in_dir; use av1an_core::{ - encoder::Encoder, - hash_path, - settings::EncodeArgs, - vapoursynth, Verbosity, - {concat::ConcatMethod, ChunkMethod, SplitMethod}, + ffmpeg, hash_path, into_vec, vapoursynth, ChunkMethod, ChunkOrdering, Input, ScenecutMethod, + SplitMethod, Verbosity, }; - +use clap::{AppSettings, Parser}; +use flexi_logger::writers::LogWriter; +use flexi_logger::{FileSpec, Level, LevelFilter, LogSpecBuilder, Logger}; use once_cell::sync::OnceCell; +use path_abs::{PathAbs, PathInfo}; // needs to be static, runtime allocated string to avoid evil hacks to // concatenate non-trivial strings at compile-time diff --git a/av1an-core/src/broker.rs b/av1an-core/src/broker.rs index c30d79a..9f16816 100644 --- a/av1an-core/src/broker.rs +++ b/av1an-core/src/broker.rs @@ -1,28 +1,25 @@ -use crate::progress_bar::update_progress_bar_estimates; -use crate::util::printable_base10_digits; -use crate::DoneChunk; -use crate::{ - finish_multi_progress_bar, finish_progress_bar, get_done, - progress_bar::{dec_bar, dec_mp_bar}, - settings::EncodeArgs, - Chunk, Encoder, Instant, TargetQuality, Verbosity, -}; +use std::fmt::{Debug, Display}; +use std::fs::File; +use std::io::Write; +use std::path::Path; +use std::process::ExitStatus; use std::sync::atomic::{self, AtomicU64}; +use std::sync::mpsc::Sender; use std::sync::Arc; -use std::{ - fmt::{Debug, Display}, - fs::File, - io::Write, - path::Path, - process::ExitStatus, - sync::mpsc::Sender, -}; use cfg_if::cfg_if; use memchr::memmem; use smallvec::SmallVec; use thiserror::Error; +use crate::progress_bar::{dec_bar, dec_mp_bar, update_progress_bar_estimates}; +use crate::settings::EncodeArgs; +use crate::util::printable_base10_digits; +use crate::{ + finish_multi_progress_bar, finish_progress_bar, get_done, Chunk, DoneChunk, Encoder, Instant, + TargetQuality, Verbosity, +}; + pub struct Broker<'a> { pub max_tries: usize, pub chunk_queue: Vec, diff --git a/av1an-core/src/chunk.rs b/av1an-core/src/chunk.rs index b7002a5..5eea3cc 100644 --- a/av1an-core/src/chunk.rs +++ b/av1an-core/src/chunk.rs @@ -1,6 +1,9 @@ -use crate::scenes::ZoneOptions; +use std::ffi::OsString; +use std::path::Path; + use serde::{Deserialize, Serialize}; -use std::{ffi::OsString, path::Path}; + +use crate::scenes::ZoneOptions; #[derive(Debug, Clone, Default, Serialize, Deserialize)] pub struct Chunk { diff --git a/av1an-core/src/concat.rs b/av1an-core/src/concat.rs index bf09acf..0401120 100644 --- a/av1an-core/src/concat.rs +++ b/av1an-core/src/concat.rs @@ -1,25 +1,21 @@ +use std::fmt::{Display, Write as FmtWrite}; +use std::fs::{self, DirEntry, File}; +use std::io::Write; +use std::path::{Path, PathBuf}; +use std::process::{Command, Stdio}; +use std::sync::Arc; + use anyhow::{anyhow, Context}; -use av_format::{ - buffer::AccReader, - demuxer::{Context as DemuxerContext, Event}, - muxer::Context as MuxerContext, -}; -use av_ivf::{demuxer::IvfDemuxer, muxer::IvfMuxer}; -use path_abs::PathAbs; +use av_format::buffer::AccReader; +use av_format::demuxer::{Context as DemuxerContext, Event}; +use av_format::muxer::Context as MuxerContext; +use av_ivf::demuxer::IvfDemuxer; +use av_ivf::muxer::IvfMuxer; +use path_abs::{PathAbs, PathInfo}; use serde::{Deserialize, Serialize}; -use std::{ - fmt::Display, - fmt::Write as FmtWrite, - fs::{self, DirEntry, File}, - io::Write, - path::{Path, PathBuf}, - process::{Command, Stdio}, - sync::Arc, -}; -use path_abs::PathInfo; - -use crate::{encoder::Encoder, util::read_in_dir}; +use crate::encoder::Encoder; +use crate::util::read_in_dir; #[derive( PartialEq, Eq, Copy, Clone, Serialize, Deserialize, Debug, strum::EnumString, strum::IntoStaticStr, diff --git a/av1an-core/src/encoder.rs b/av1an-core/src/encoder.rs index ffb6b78..3b84617 100644 --- a/av1an-core/src/encoder.rs +++ b/av1an-core/src/encoder.rs @@ -1,14 +1,20 @@ -use crate::{ffmpeg::compose_ffmpeg_pipe, inplace_vec, into_array, into_vec, list_index}; +use std::borrow::Cow; +use std::cmp; +use std::fmt::Display; +use std::iter::Iterator; +use std::path::PathBuf; +use std::process::Command; + use arrayvec::ArrayVec; use cfg_if::cfg_if; use ffmpeg::format::Pixel; use itertools::chain; use once_cell::sync::Lazy; use serde::{Deserialize, Serialize}; -use std::{borrow::Cow, cmp, fmt::Display, path::PathBuf, process::Command}; use thiserror::Error; -use std::iter::Iterator; +use crate::ffmpeg::compose_ffmpeg_pipe; +use crate::{inplace_vec, into_array, into_vec, list_index}; const NULL: &str = if cfg!(windows) { "nul" } else { "/dev/null" }; diff --git a/av1an-core/src/ffmpeg.rs b/av1an-core/src/ffmpeg.rs index 2e75473..dc02fa5 100644 --- a/av1an-core/src/ffmpeg.rs +++ b/av1an-core/src/ffmpeg.rs @@ -1,15 +1,14 @@ -use crate::{into_array, into_vec}; +use std::ffi::OsStr; +use std::path::{Path, PathBuf}; +use std::process::{Command, Stdio}; + use ffmpeg::color::TransferCharacteristic; use ffmpeg::format::{input, Pixel}; use ffmpeg::media::Type as MediaType; use ffmpeg::Error::StreamNotFound; use path_abs::{PathAbs, PathInfo}; -use std::path::PathBuf; -use std::{ - ffi::OsStr, - path::Path, - process::{Command, Stdio}, -}; + +use crate::{into_array, into_vec}; pub fn compose_ffmpeg_pipe>( params: impl IntoIterator, diff --git a/av1an-core/src/grain.rs b/av1an-core/src/grain.rs index b54285d..d0c18d2 100644 --- a/av1an-core/src/grain.rs +++ b/av1an-core/src/grain.rs @@ -1,8 +1,6 @@ -use std::{ - fs::File, - io::{BufWriter, Write}, - path::Path, -}; +use std::fs::File; +use std::io::{BufWriter, Write}; +use std::path::Path; #[derive(Debug, Clone, Copy)] pub struct NoiseGenArgs { diff --git a/av1an-core/src/lib.rs b/av1an-core/src/lib.rs index e5c0ab0..53057ef 100644 --- a/av1an-core/src/lib.rs +++ b/av1an-core/src/lib.rs @@ -20,11 +20,17 @@ #[macro_use] extern crate log; -use crate::{ - encoder::Encoder, - progress_bar::{finish_multi_progress_bar, finish_progress_bar}, - target_quality::TargetQuality, -}; +use std::cmp::max; +use std::collections::hash_map::DefaultHasher; +use std::fs; +use std::fs::File; +use std::hash::{Hash, Hasher}; +use std::io::Write; +use std::path::{Path, PathBuf}; +use std::string::ToString; +use std::sync::atomic::{AtomicBool, AtomicUsize}; +use std::time::Instant; + use ::ffmpeg::color::TransferCharacteristic; use anyhow::Context; use chunk::Chunk; @@ -32,21 +38,12 @@ use dashmap::DashMap; use grain::TransferFunction; use once_cell::sync::OnceCell; use serde::{Deserialize, Serialize}; -use std::{ - cmp::max, - collections::hash_map::DefaultHasher, - fs, - fs::File, - hash::{Hash, Hasher}, - io::Write, - path::{Path, PathBuf}, - string::ToString, - sync::atomic::{AtomicBool, AtomicUsize}, - time::Instant, -}; +use strum::{Display, EnumString, IntoStaticStr}; use sysinfo::SystemExt; -use strum::{Display, EnumString, IntoStaticStr}; +use crate::encoder::Encoder; +use crate::progress_bar::{finish_multi_progress_bar, finish_progress_bar}; +use crate::target_quality::TargetQuality; pub mod broker; pub mod chunk; diff --git a/av1an-core/src/parse.rs b/av1an-core/src/parse.rs index 010ae29..6d50100 100644 --- a/av1an-core/src/parse.rs +++ b/av1an-core/src/parse.rs @@ -4,7 +4,8 @@ //! runtime detection that the corresponding feature //! set is available before calling them. -use std::{borrow::Cow, collections::HashSet}; +use std::borrow::Cow; +use std::collections::HashSet; use crate::encoder::Encoder; @@ -78,7 +79,6 @@ pub unsafe fn parse_aom_vpx_frames_sse41(s: &[u8]) -> Option { use std::arch::x86::*; #[cfg(target_arch = "x86_64")] use std::arch::x86_64::*; - use std::mem::transmute; // This implementation matches the *second* number in the output. Ex: diff --git a/av1an-core/src/progress_bar.rs b/av1an-core/src/progress_bar.rs index adaca71..0a0d408 100644 --- a/av1an-core/src/progress_bar.rs +++ b/av1an-core/src/progress_bar.rs @@ -1,10 +1,8 @@ -use crate::get_done; -use crate::Verbosity; -use indicatif::HumanBytes; -use indicatif::{MultiProgress, ProgressBar, ProgressDrawTarget, ProgressStyle}; +use indicatif::{HumanBytes, MultiProgress, ProgressBar, ProgressDrawTarget, ProgressStyle}; use once_cell::sync::OnceCell; use crate::util::printable_base10_digits; +use crate::{get_done, Verbosity}; const INDICATIF_PROGRESS_TEMPLATE: &str = if cfg!(windows) { // Do not use a spinner on Windows since the default console cannot display diff --git a/av1an-core/src/scene_detect.rs b/av1an-core/src/scene_detect.rs index ab44ca1..f8c7810 100644 --- a/av1an-core/src/scene_detect.rs +++ b/av1an-core/src/scene_detect.rs @@ -1,15 +1,16 @@ -use crate::scenes::Scene; -use crate::Encoder; -use crate::{into_smallvec, progress_bar, Input, ScenecutMethod, Verbosity}; +use std::io::Read; +use std::process::{Command, Stdio}; +use std::thread; + use ansi_term::Style; use anyhow::bail; use av_scenechange::{detect_scene_changes, DetectionOptions, SceneDetectionSpeed}; use ffmpeg::format::Pixel; use itertools::Itertools; use smallvec::{smallvec, SmallVec}; -use std::io::Read; -use std::process::{Command, Stdio}; -use std::thread; + +use crate::scenes::Scene; +use crate::{into_smallvec, progress_bar, Encoder, Input, ScenecutMethod, Verbosity}; pub fn av_scenechange_detect( input: &Input, diff --git a/av1an-core/src/scenes.rs b/av1an-core/src/scenes.rs index 5925caa..9a78f21 100644 --- a/av1an-core/src/scenes.rs +++ b/av1an-core/src/scenes.rs @@ -1,8 +1,8 @@ -use crate::parse::valid_params; -use crate::settings::{invalid_params, suggest_fix, EncodeArgs}; -use crate::Encoder; -use anyhow::Result; -use anyhow::{anyhow, bail}; +use std::collections::HashMap; +use std::process::{exit, Command}; +use std::str::FromStr; + +use anyhow::{anyhow, bail, Result}; use itertools::Itertools; use nom::branch::alt; use nom::bytes::complete::{tag, take_till, take_while}; @@ -11,9 +11,10 @@ use nom::combinator::{map, map_res, opt, recognize, rest}; use nom::multi::{many1, separated_list0}; use nom::sequence::{preceded, tuple}; use serde::{Deserialize, Serialize}; -use std::collections::HashMap; -use std::process::{exit, Command}; -use std::str::FromStr; + +use crate::parse::valid_params; +use crate::settings::{invalid_params, suggest_fix, EncodeArgs}; +use crate::Encoder; #[derive(Deserialize, Serialize, Debug, Clone)] pub struct Scene { @@ -248,11 +249,10 @@ fn get_test_args() -> EncodeArgs { use ffmpeg::format::Pixel; + use crate::concat::ConcatMethod; + use crate::settings::{InputPixelFormat, PixelFormat}; use crate::{ - concat::ConcatMethod, - into_vec, - settings::{InputPixelFormat, PixelFormat}, - ChunkMethod, ChunkOrdering, Input, ScenecutMethod, SplitMethod, Verbosity, + into_vec, ChunkMethod, ChunkOrdering, Input, ScenecutMethod, SplitMethod, Verbosity, }; EncodeArgs { diff --git a/av1an-core/src/settings.rs b/av1an-core/src/settings.rs index 727331c..38a6c39 100644 --- a/av1an-core/src/settings.rs +++ b/av1an-core/src/settings.rs @@ -1,63 +1,47 @@ -use crate::ffmpeg::num_frames; -use crate::grain::create_film_grain_file; -use crate::parse::valid_params; -use crate::progress_bar::{reset_bar_at, reset_mp_bar_at}; -use crate::progress_bar::{update_mp_chunk, update_progress_bar_estimates}; -use crate::vapoursynth::{is_ffms2_installed, is_lsmash_installed}; -use crate::ChunkOrdering; -use crate::{ - broker::{Broker, EncoderCrash}, - chunk::Chunk, - concat::{self, ConcatMethod}, - create_dir, determine_workers, - ffmpeg::compose_ffmpeg_pipe, - finish_multi_progress_bar, get_done, init_done, into_vec, - progress_bar::{ - finish_progress_bar, inc_bar, inc_mp_bar, init_multi_progress_bar, init_progress_bar, - update_mp_msg, - }, - read_chunk_queue, save_chunk_queue, - scene_detect::av_scenechange_detect, - split::{extra_splits, segment, write_scenes_to_file}, - vapoursynth::create_vs_file, - vmaf::{self, validate_libvmaf}, - ChunkMethod, DashMap, DoneJson, Encoder, Input, ScenecutMethod, SplitMethod, TargetQuality, - Verbosity, -}; +use std::borrow::{Borrow, Cow}; +use std::cmp::{Ordering, Reverse}; +use std::collections::{BTreeSet, HashSet}; +use std::convert::TryInto; +use std::ffi::OsString; +use std::fs::File; +use std::io::Write; +use std::path::{Path, PathBuf}; +use std::process::{exit, Command, Stdio}; +use std::sync::atomic::{self, AtomicBool, AtomicU64, AtomicUsize}; +use std::sync::{mpsc, Arc}; +use std::{cmp, fs, iter, thread}; + +use ansi_term::{Color, Style}; use anyhow::{bail, ensure, Context}; use crossbeam_utils; use ffmpeg::format::Pixel; use itertools::Itertools; use rand::prelude::SliceRandom; use rand::thread_rng; -use std::borrow::Borrow; -use std::cmp::Ordering; -use std::collections::BTreeSet; -use std::sync::atomic::AtomicUsize; -use std::thread; -use std::{ - borrow::Cow, - cmp, - cmp::Reverse, - collections::HashSet, - convert::TryInto, - ffi::OsString, - fs, - fs::File, - io::Write, - iter, - path::{Path, PathBuf}, - process::{exit, Command, Stdio}, - sync::atomic::{self, AtomicBool, AtomicU64}, - sync::{mpsc, Arc}, -}; - -use ansi_term::{Color, Style}; - -use crate::scenes::{Scene, ZoneOptions}; use tokio::io::{AsyncBufReadExt, BufReader}; use tokio::process::ChildStderr; +use crate::broker::{Broker, EncoderCrash}; +use crate::chunk::Chunk; +use crate::concat::{self, ConcatMethod}; +use crate::ffmpeg::{compose_ffmpeg_pipe, num_frames}; +use crate::grain::create_film_grain_file; +use crate::parse::valid_params; +use crate::progress_bar::{ + finish_progress_bar, inc_bar, inc_mp_bar, init_multi_progress_bar, init_progress_bar, + reset_bar_at, reset_mp_bar_at, update_mp_chunk, update_mp_msg, update_progress_bar_estimates, +}; +use crate::scene_detect::av_scenechange_detect; +use crate::scenes::{Scene, ZoneOptions}; +use crate::split::{extra_splits, segment, write_scenes_to_file}; +use crate::vapoursynth::{create_vs_file, is_ffms2_installed, is_lsmash_installed}; +use crate::vmaf::{self, validate_libvmaf}; +use crate::{ + create_dir, determine_workers, finish_multi_progress_bar, get_done, init_done, into_vec, + read_chunk_queue, save_chunk_queue, ChunkMethod, ChunkOrdering, DashMap, DoneJson, Encoder, + Input, ScenecutMethod, SplitMethod, TargetQuality, Verbosity, +}; + pub struct PixelFormat { pub format: Pixel, pub bit_depth: usize, diff --git a/av1an-core/src/split.rs b/av1an-core/src/split.rs index b98f92f..1fe8cae 100644 --- a/av1an-core/src/split.rs +++ b/av1an-core/src/split.rs @@ -1,14 +1,14 @@ -use crate::scenes::Scene; +use std::fs::File; +use std::io::prelude::*; +use std::io::BufReader; +use std::path::Path; +use std::process::{Command, Stdio}; +use std::string::ToString; + use anyhow::Context; use serde::{Deserialize, Serialize}; -use std::{ - fs::File, - io::prelude::*, - io::BufReader, - path::Path, - process::{Command, Stdio}, - string::ToString, -}; + +use crate::scenes::Scene; pub fn segment(input: impl AsRef, temp: impl AsRef, segments: &[usize]) { let input = input.as_ref(); @@ -139,9 +139,10 @@ pub fn read_scenes_from_file(scene_path: &Path) -> anyhow::Result<(Vec, u #[cfg(test)] mod tests { - use crate::{encoder::Encoder, into_vec, scenes::ZoneOptions}; - use super::*; + use crate::encoder::Encoder; + use crate::into_vec; + use crate::scenes::ZoneOptions; #[test] fn test_extra_split_no_segments() { diff --git a/av1an-core/src/target_quality.rs b/av1an-core/src/target_quality.rs index bc5694b..7e1aa15 100644 --- a/av1an-core/src/target_quality.rs +++ b/av1an-core/src/target_quality.rs @@ -1,20 +1,18 @@ -use crate::{ - broker::EncoderCrash, - chunk::Chunk, - settings::EncodeArgs, - vmaf::{self, read_weighted_vmaf}, - Encoder, -}; +use std::cmp; +use std::cmp::Ordering; +use std::convert::TryInto; +use std::fmt::Error; +use std::path::{Path, PathBuf}; +use std::process::Stdio; + use ffmpeg::format::Pixel; use splines::{Interpolation, Key, Spline}; -use std::{ - cmp, - cmp::Ordering, - convert::TryInto, - fmt::Error, - path::{Path, PathBuf}, - process::Stdio, -}; + +use crate::broker::EncoderCrash; +use crate::chunk::Chunk; +use crate::settings::EncodeArgs; +use crate::vmaf::{self, read_weighted_vmaf}; +use crate::Encoder; const VMAF_PERCENTILE: f64 = 0.25; diff --git a/av1an-core/src/vapoursynth.rs b/av1an-core/src/vapoursynth.rs index 4d40635..26a6544 100644 --- a/av1an-core/src/vapoursynth.rs +++ b/av1an-core/src/vapoursynth.rs @@ -1,18 +1,15 @@ -use std::{ - collections::HashSet, - fs::File, - io::Write, - path::{Path, PathBuf}, -}; -use vapoursynth::video_info::VideoInfo; - -use once_cell::sync::Lazy; - -use super::ChunkMethod; -use path_abs::PathAbs; -use vapoursynth::prelude::*; +use std::collections::HashSet; +use std::fs::File; +use std::io::Write; +use std::path::{Path, PathBuf}; use anyhow::{anyhow, bail}; +use once_cell::sync::Lazy; +use path_abs::PathAbs; +use vapoursynth::prelude::*; +use vapoursynth::video_info::VideoInfo; + +use super::ChunkMethod; static VAPOURSYNTH_PLUGINS: Lazy> = Lazy::new(|| { let environment = Environment::new().expect("Failed to initialize VapourSynth environment"); diff --git a/av1an-core/src/vmaf.rs b/av1an-core/src/vmaf.rs index 8e96619..649d6f0 100644 --- a/av1an-core/src/vmaf.rs +++ b/av1an-core/src/vmaf.rs @@ -1,18 +1,17 @@ -use crate::broker::EncoderCrash; -use crate::util::printable_base10_digits; -use crate::{ffmpeg, ref_smallvec, Input}; -use anyhow::anyhow; -use anyhow::Context; +use std::cmp::Ordering; +use std::ffi::OsStr; +use std::path::Path; +use std::process::{Command, Stdio}; +use std::usize; + +use anyhow::{anyhow, Context}; use plotters::prelude::*; use serde::Deserialize; use smallvec::SmallVec; -use std::{ - cmp::Ordering, - ffi::OsStr, - path::Path, - process::{Command, Stdio}, - usize, -}; + +use crate::broker::EncoderCrash; +use crate::util::printable_base10_digits; +use crate::{ffmpeg, ref_smallvec, Input}; #[derive(Deserialize, Debug)] struct VmafScore { diff --git a/rustfmt.toml b/rustfmt.toml index 2bc17ab..a5fa827 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,2 +1,5 @@ edition = "2021" tab_spaces = 2 +reorder_imports = true +group_imports = "StdExternalCrate" +imports_granularity = "Module"