Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
master-of-zen committed Dec 1, 2024
1 parent 696fea7 commit 28135e0
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 44 deletions.
4 changes: 2 additions & 2 deletions av1an-core/src/broker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ impl Display for EncoderCrash {

impl<'a> Broker<'a> {
/// Main encoding loop. set_thread_affinity may be ignored if the value is invalid.
#[tracing::instrument]
#[tracing::instrument(skip(self))]
pub fn encoding_loop(self, tx: Sender<()>, set_thread_affinity: Option<usize>) {
if !self.chunk_queue.is_empty() {
let (sender, receiver) = crossbeam_channel::bounded(self.chunk_queue.len());
Expand Down Expand Up @@ -165,7 +165,7 @@ impl<'a> Broker<'a> {
}
}

#[tracing::instrument]
#[tracing::instrument(skip(self))]
fn encode_chunk(&self, chunk: &mut Chunk, worker_id: usize) -> Result<(), Box<EncoderCrash>> {
let st_time = Instant::now();

Expand Down
6 changes: 6 additions & 0 deletions av1an-core/src/concat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ impl Display for ConcatMethod {
}
}

#[tracing::instrument]
pub fn sort_files_by_filename(files: &mut [PathBuf]) {
files.sort_unstable_by_key(|x| {
// If the temp directory follows the expected format of 00000.ivf, 00001.ivf, etc.,
Expand All @@ -49,6 +50,7 @@ pub fn sort_files_by_filename(files: &mut [PathBuf]) {
});
}

#[tracing::instrument]
pub fn ivf(input: &Path, out: &Path) -> anyhow::Result<()> {
let mut files: Vec<PathBuf> = read_in_dir(input)?.collect();

Expand Down Expand Up @@ -137,6 +139,7 @@ pub fn ivf(input: &Path, out: &Path) -> anyhow::Result<()> {
Ok(())
}

#[tracing::instrument]
fn read_encoded_chunks(encode_dir: &Path) -> anyhow::Result<Vec<DirEntry>> {
Ok(
fs::read_dir(encode_dir)
Expand All @@ -145,6 +148,7 @@ fn read_encoded_chunks(encode_dir: &Path) -> anyhow::Result<Vec<DirEntry>> {
)
}

#[tracing::instrument]
pub fn mkvmerge(
temp_dir: &Path,
output: &Path,
Expand Down Expand Up @@ -222,6 +226,7 @@ pub fn mkvmerge(
}

/// Create mkvmerge options.json
#[tracing::instrument]
pub fn mkvmerge_options_json(
num: usize,
encoder: Encoder,
Expand All @@ -243,6 +248,7 @@ pub fn mkvmerge_options_json(
}

/// Concatenates using ffmpeg (does not work with x265)
#[tracing::instrument]
pub fn ffmpeg(temp: &Path, output: &Path) -> anyhow::Result<()> {
fn write_concat_file(temp_folder: &Path) -> anyhow::Result<()> {
let concat_file = temp_folder.join("concat");
Expand Down
4 changes: 3 additions & 1 deletion av1an-core/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ pub struct Av1anContext {
}

impl Av1anContext {

#[tracing::instrument]
pub fn new(mut args: EncodeArgs) -> anyhow::Result<Self> {
args.validate()?;
let mut this = Self {
Expand Down Expand Up @@ -1168,7 +1170,7 @@ impl Av1anContext {
output_ext: output_ext.to_owned(),
index,
start_frame: 0,
end_frame: num_frames,
end_frame: num_frames,
frame_rate,
video_params: overrides.as_ref().map_or_else(
|| self.args.video_params.clone(),
Expand Down
1 change: 1 addition & 0 deletions av1an-core/src/encoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pub enum Encoder {
x265,
}

#[tracing::instrument]
pub(crate) fn parse_svt_av1_version(version: &[u8]) -> Option<(u32, u32, u32)> {
let v_idx = memchr::memchr(b'v', version)?;
let s = version.get(v_idx + 1..)?;
Expand Down
4 changes: 2 additions & 2 deletions av1an-core/src/logging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ use tracing_subscriber::{fmt, prelude::*, EnvFilter};
///
/// This function will panic if it fails to initialize the global logger.
pub fn init_logging() {
let rust_log = env::var("RUST_LOG").unwrap_or_else(|_| "INFO".to_string());
let rust_log = env::var("RUST_LOG").unwrap_or_else(|_| "ERROR".to_string());

// Set up daily rotating file appender
let file_appender = RollingFileAppender::new(Rotation::DAILY, "logs", "application.log");
let file_appender = RollingFileAppender::new(Rotation::DAILY, "logs", "av1an.log");

let (non_blocking, _guard) = tracing_appender::non_blocking(file_appender);

Expand Down
43 changes: 4 additions & 39 deletions av1an/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,8 @@ pub struct CliOpts {
}

impl CliOpts {

#[tracing::instrument]
pub fn target_quality_params(
&self,
temp_dir: String,
Expand Down Expand Up @@ -624,6 +626,7 @@ pub(crate) fn resolve_file_paths(path: &Path) -> anyhow::Result<Box<dyn Iterator
}

/// Returns vector of Encode args ready to be fed to encoder
#[tracing::instrument]
pub fn parse_cli(args: CliOpts) -> anyhow::Result<Vec<EncodeArgs>> {
let input_paths = &*args.input;

Expand Down Expand Up @@ -879,49 +882,11 @@ pub fn run() -> anyhow::Result<()> {

let cli_args = CliOpts::parse();

let log_level = cli_args.log_level;
//let log_level = cli_args.log_level;
let args = parse_cli(cli_args)?;

let log = LogSpecBuilder::new()
.default(LevelFilter::Error)
.module("av1an", log_level)
.module("av1an_cli", log_level)
.module("av1an_core", log_level)
.module(
"rav1e::scenechange",
match log_level {
LevelFilter::Trace => LevelFilter::Debug,
LevelFilter::Debug => LevelFilter::Info,
other => other,
},
)
.build();

// Note that with all write modes except WriteMode::Direct (which is the default)
// you should keep the LoggerHandle alive up to the very end of your program,
// because it will, in its Drop implementation, flush all writers to ensure that
// all buffered log lines are flushed before the program terminates,
// and then it calls their shutdown method.
let logger = Logger::with(log)
.log_to_file_and_writer(
// UGLY: take first or the files for log path
FileSpec::try_from(PathAbs::new(&args[0].log_file)?)?,
Box::new(StderrLogger {
// UGLY: take first or the files for verbosity
level: match args[0].verbosity {
Verbosity::Quiet => Level::Warn,
Verbosity::Normal | Verbosity::Verbose => Level::Info,
},
}),
)
.start()?;

for arg in args {
// Change log file
let new_log_file = FileSpec::try_from(PathAbs::new(&arg.log_file)?)?;
let _ =
&logger.reset_flw(&flexi_logger::writers::FileLogWriter::builder(new_log_file).append())?;

Av1anContext::new(arg)?.encode_file()?;
}

Expand Down

0 comments on commit 28135e0

Please sign in to comment.