Skip to content

Commit 2ec2f5a

Browse files
committed
Man command to quantizer_replace
1 parent 2337195 commit 2ec2f5a

File tree

3 files changed

+12
-268
lines changed

3 files changed

+12
-268
lines changed

av1an-core/src/broker.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use std::fmt::{Debug, Display};
22
use std::fs::File;
33
use std::io::Write;
4-
use std::path::Path;
4+
use std::path::{Path, PathBuf};
55
use std::process::ExitStatus;
66
use std::sync::mpsc::Sender;
77
use std::thread::available_parallelism;
@@ -18,6 +18,11 @@ use crate::{finish_progress_bar, get_done, Chunk, DoneChunk, Instant};
1818
pub struct Broker<'a> {
1919
pub chunk_queue: Vec<Chunk>,
2020
pub project: &'a Av1anContext,
21+
22+
// Future
23+
pub broker_port: Option<u32>,
24+
pub http_port: Option<u32>,
25+
pub cache_root: Option<PathBuf>,
2126
}
2227

2328
#[derive(Clone)]
@@ -97,7 +102,7 @@ impl Display for EncoderCrash {
97102
impl<'a> Broker<'a> {
98103
/// Main encoding loop. set_thread_affinity may be ignored if the value is invalid.
99104
pub fn encoding_loop(self, tx: Sender<()>, mut set_thread_affinity: Option<usize>) {
100-
assert!(!self.chunk_queue.is_empty());
105+
//if self.chunk_queue.is_empty() ?? {};
101106

102107
if !self.chunk_queue.is_empty() {
103108
let (sender, receiver) = crossbeam_channel::bounded(self.chunk_queue.len());

av1an-core/src/context.rs

+4-265
Original file line numberDiff line numberDiff line change
@@ -303,6 +303,9 @@ impl Av1anContext {
303303
let broker = Broker {
304304
chunk_queue,
305305
project: self,
306+
broker_port: None,
307+
http_port: None,
308+
cache_root: None,
306309
};
307310

308311
let (tx, rx) = mpsc::channel();
@@ -442,7 +445,7 @@ impl Av1anContext {
442445
if let Some(per_shot_target_quality_cq) = chunk.tq_cq {
443446
enc_cmd = chunk
444447
.encoder
445-
.man_command(enc_cmd, per_shot_target_quality_cq as usize);
448+
.quantizer_replace(enc_cmd, per_shot_target_quality_cq as usize);
446449
}
447450

448451
let rt = tokio::runtime::Builder::new_current_thread()
@@ -828,270 +831,6 @@ impl Av1anContext {
828831
Ok(scenes)
829832
}
830833

831-
fn create_select_chunk(
832-
&self,
833-
index: usize,
834-
src_path: &Path,
835-
start_frame: usize,
836-
end_frame: usize,
837-
frame_rate: f64,
838-
overrides: Option<ZoneOptions>,
839-
) -> anyhow::Result<Chunk> {
840-
assert!(
841-
start_frame < end_frame,
842-
"Can't make a chunk with <= 0 frames!"
843-
);
844-
845-
let ffmpeg_gen_cmd: Vec<OsString> = into_vec![
846-
"ffmpeg",
847-
"-y",
848-
"-hide_banner",
849-
"-loglevel",
850-
"error",
851-
"-i",
852-
src_path,
853-
"-vf",
854-
format!(
855-
"select=between(n\\,{}\\,{}),setpts=PTS-STARTPTS",
856-
start_frame,
857-
end_frame - 1
858-
),
859-
"-pix_fmt",
860-
self
861-
.args
862-
.output_pix_format
863-
.format
864-
.descriptor()
865-
.unwrap()
866-
.name(),
867-
"-strict",
868-
"-1",
869-
"-f",
870-
"yuv4mpegpipe",
871-
"-",
872-
];
873-
874-
let output_ext = self.args.encoder.output_extension();
875-
876-
let mut chunk = Chunk {
877-
cache: self.args.cache.clone(),
878-
index,
879-
input: Input::Video(src_path.to_path_buf()),
880-
source_cmd: ffmpeg_gen_cmd,
881-
output_ext: output_ext.to_owned(),
882-
start_frame,
883-
end_frame,
884-
frame_rate,
885-
video_params: overrides.as_ref().map_or_else(
886-
|| self.args.video_params.clone(),
887-
|ovr| ovr.video_params.clone(),
888-
),
889-
passes: self.args.passes,
890-
encoder: self.args.encoder,
891-
noise_size: self.args.photon_noise_size,
892-
tq_cq: None,
893-
ignore_frame_mismatch: self.args.ignore_frame_mismatch,
894-
};
895-
chunk.apply_photon_noise_args(
896-
overrides.map_or(self.args.photon_noise, |ovr| ovr.photon_noise),
897-
self.args.chroma_noise,
898-
)?;
899-
if let Some(ref tq) = self.args.target_quality {
900-
tq.per_shot_target_quality_routine(&mut chunk)?;
901-
}
902-
Ok(chunk)
903-
}
904-
905-
fn create_vs_chunk(
906-
&self,
907-
index: usize,
908-
vs_script: &Path,
909-
scene: &Scene,
910-
frame_rate: f64,
911-
) -> anyhow::Result<Chunk> {
912-
// the frame end boundary is actually a frame that should be included in the next chunk
913-
let frame_end = scene.end_frame - 1;
914-
915-
let vspipe_cmd_gen: Vec<OsString> = into_vec![
916-
"vspipe",
917-
vs_script,
918-
"-c",
919-
"y4m",
920-
"-",
921-
"-s",
922-
scene.start_frame.to_string(),
923-
"-e",
924-
frame_end.to_string(),
925-
];
926-
927-
let output_ext = self.args.encoder.output_extension();
928-
929-
let mut chunk = Chunk {
930-
cache: self.args.cache.clone(),
931-
index,
932-
input: Input::VapourSynth(vs_script.to_path_buf()),
933-
source_cmd: vspipe_cmd_gen,
934-
output_ext: output_ext.to_owned(),
935-
start_frame: scene.start_frame,
936-
end_frame: scene.end_frame,
937-
frame_rate,
938-
video_params: scene.zone_overrides.as_ref().map_or_else(
939-
|| self.args.video_params.clone(),
940-
|ovr| ovr.video_params.clone(),
941-
),
942-
passes: self.args.passes,
943-
encoder: self.args.encoder,
944-
noise_size: self.args.photon_noise_size,
945-
tq_cq: None,
946-
ignore_frame_mismatch: self.args.ignore_frame_mismatch,
947-
};
948-
chunk.apply_photon_noise_args(
949-
scene
950-
.zone_overrides
951-
.as_ref()
952-
.map_or(self.args.photon_noise, |ovr| ovr.photon_noise),
953-
self.args.chroma_noise,
954-
)?;
955-
Ok(chunk)
956-
}
957-
958-
fn create_video_queue_vs(&self, scenes: &[Scene], vs_script: &Path) -> Vec<Chunk> {
959-
let frame_rate = self.args.input.frame_rate().unwrap();
960-
let chunk_queue: Vec<Chunk> = scenes
961-
.iter()
962-
.enumerate()
963-
.map(|(index, scene)| {
964-
self
965-
.create_vs_chunk(index, vs_script, scene, frame_rate)
966-
.unwrap()
967-
})
968-
.collect();
969-
970-
chunk_queue
971-
}
972-
973-
fn create_video_queue_select(&self, scenes: &[Scene]) -> Vec<Chunk> {
974-
let input = self.args.input.as_video_path();
975-
let frame_rate = self.args.input.frame_rate().unwrap();
976-
977-
let chunk_queue: Vec<Chunk> = scenes
978-
.iter()
979-
.enumerate()
980-
.map(|(index, scene)| {
981-
self
982-
.create_select_chunk(
983-
index,
984-
input,
985-
scene.start_frame,
986-
scene.end_frame,
987-
frame_rate,
988-
scene.zone_overrides.clone(),
989-
)
990-
.unwrap()
991-
})
992-
.collect();
993-
994-
chunk_queue
995-
}
996-
997-
fn create_video_queue_segment(&self, scenes: &[Scene]) -> anyhow::Result<Vec<Chunk>> {
998-
let input = self.args.input.as_video_path();
999-
let frame_rate = self.args.input.frame_rate().unwrap();
1000-
1001-
debug!("Splitting video");
1002-
segment(
1003-
input,
1004-
&self.args.cache,
1005-
&scenes
1006-
.iter()
1007-
.skip(1)
1008-
.map(|scene| scene.start_frame)
1009-
.collect::<Vec<usize>>(),
1010-
);
1011-
debug!("Splitting done");
1012-
1013-
let source_path = Path::new(&self.args.cache).join("split");
1014-
let queue_files = Self::read_queue_files(&source_path)?;
1015-
1016-
assert!(
1017-
!queue_files.is_empty(),
1018-
"Error: No files found in cache/split, probably splitting not working"
1019-
);
1020-
1021-
let chunk_queue: Vec<Chunk> = queue_files
1022-
.iter()
1023-
.enumerate()
1024-
.map(|(index, file)| {
1025-
self
1026-
.create_chunk_from_segment(
1027-
index,
1028-
file.as_path().to_str().unwrap(),
1029-
frame_rate,
1030-
scenes[index].zone_overrides.clone(),
1031-
)
1032-
.unwrap()
1033-
})
1034-
.collect();
1035-
1036-
Ok(chunk_queue)
1037-
}
1038-
1039-
fn create_video_queue_hybrid(&self, scenes: &[Scene]) -> anyhow::Result<Vec<Chunk>> {
1040-
let input = self.args.input.as_video_path();
1041-
let frame_rate = self.args.input.frame_rate().unwrap();
1042-
1043-
let keyframes = crate::ffmpeg::get_keyframes(input).unwrap();
1044-
1045-
let to_split: Vec<usize> = keyframes
1046-
.iter()
1047-
.filter(|kf| scenes.iter().any(|scene| scene.start_frame == **kf))
1048-
.copied()
1049-
.collect();
1050-
1051-
debug!("Segmenting video");
1052-
segment(input, &self.args.cache, &to_split[1..]);
1053-
debug!("Segment done");
1054-
1055-
let source_path = Path::new(&self.args.cache).join("split");
1056-
let queue_files = Self::read_queue_files(&source_path)?;
1057-
1058-
let kf_list = to_split
1059-
.iter()
1060-
.copied()
1061-
.chain(iter::once(self.frames))
1062-
.tuple_windows();
1063-
1064-
let mut segments = Vec::with_capacity(scenes.len());
1065-
for (file, (x, y)) in queue_files.iter().zip(kf_list) {
1066-
for s in scenes {
1067-
let s0 = s.start_frame;
1068-
let s1 = s.end_frame;
1069-
if s0 >= x && s1 <= y && s0 < s1 {
1070-
segments.push((file.as_path(), (s0 - x, s1 - x, s)));
1071-
}
1072-
}
1073-
}
1074-
1075-
let chunk_queue: Vec<Chunk> = segments
1076-
.iter()
1077-
.enumerate()
1078-
.map(|(index, &(file, (start, end, scene)))| {
1079-
self
1080-
.create_select_chunk(
1081-
index,
1082-
file,
1083-
start,
1084-
end,
1085-
frame_rate,
1086-
scene.zone_overrides.clone(),
1087-
)
1088-
.unwrap()
1089-
})
1090-
.collect();
1091-
1092-
Ok(chunk_queue)
1093-
}
1094-
1095834
fn create_chunk_from_segment(
1096835
&self,
1097836
index: usize,

av1an-core/src/encoder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ impl Encoder {
546546
}
547547

548548
/// Returns changed q/crf in command line arguments
549-
pub fn man_command(self, mut params: Vec<String>, q: usize) -> Vec<String> {
549+
pub fn quantizer_replace(self, mut params: Vec<String>, q: usize) -> Vec<String> {
550550
let index = list_index(&params, self.q_match_fn());
551551
if let Some(index) = index {
552552
let (replace_index, replace_q) = self.replace_q(index, q);

0 commit comments

Comments
 (0)