Skip to content

Commit 2337195

Browse files
committed
renamed temp to cache
1 parent ff3009f commit 2337195

14 files changed

+91
-92
lines changed

av1an-core/src/broker.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ impl<'a> Broker<'a> {
215215
let enc_time = st_time.elapsed();
216216
let fps = chunk.frames() as f64 / enc_time.as_secs_f64();
217217

218-
let progress_file = Path::new(&self.project.args.temp).join("done.json");
218+
let progress_file = Path::new(&self.project.args.cache).join("done.json");
219219
get_done().done.insert(
220220
chunk.name(),
221221
DoneChunk {

av1an-core/src/chunk.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ use crate::Input;
1010

1111
#[derive(Debug, Clone, Serialize, Deserialize)]
1212
pub struct Chunk {
13-
pub temp: String,
13+
pub cache: String,
1414
pub index: usize,
1515
pub input: Input,
1616
pub source_cmd: Vec<OsString>,
@@ -37,7 +37,7 @@ impl Chunk {
3737
}
3838

3939
pub fn output(&self) -> String {
40-
Path::new(&self.temp)
40+
Path::new(&self.cache)
4141
.join("encode")
4242
.join(format!("{}.{}", self.name(), self.output_ext))
4343
.to_str()
@@ -56,7 +56,7 @@ impl Chunk {
5656
) -> anyhow::Result<()> {
5757
if let Some(strength) = photon_noise {
5858
let iso_setting = u32::from(strength) * 100;
59-
let grain_table = Path::new(&self.temp).join(format!("iso{iso_setting}-grain.tbl"));
59+
let grain_table = Path::new(&self.cache).join(format!("iso{iso_setting}-grain.tbl"));
6060
if !grain_table.exists() {
6161
debug!("Generating grain table at ISO {}", iso_setting);
6262
let (mut width, mut height) = self.input.resolution()?;
@@ -98,7 +98,7 @@ mod tests {
9898
#[test]
9999
fn test_chunk_name_1() {
100100
let ch = Chunk {
101-
temp: "none".to_owned(),
101+
cache: "none".to_owned(),
102102
index: 1,
103103
input: Input::Video("test.mkv".into()),
104104
source_cmd: vec!["".into()],
@@ -118,7 +118,7 @@ mod tests {
118118
#[test]
119119
fn test_chunk_name_10000() {
120120
let ch = Chunk {
121-
temp: "none".to_owned(),
121+
cache: "none".to_owned(),
122122
index: 10000,
123123
input: Input::Video("test.mkv".into()),
124124
source_cmd: vec!["".into()],
@@ -139,7 +139,7 @@ mod tests {
139139
#[test]
140140
fn test_chunk_output() {
141141
let ch = Chunk {
142-
temp: "d".to_owned(),
142+
cache: "d".to_owned(),
143143
index: 1,
144144
input: Input::Video("test.mkv".into()),
145145
source_cmd: vec!["".into()],

av1an-core/src/concat.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl Display for ConcatMethod {
3737

3838
pub fn sort_files_by_filename(files: &mut [PathBuf]) {
3939
files.sort_unstable_by_key(|x| {
40-
// If the temp directory follows the expected format of 00000.ivf, 00001.ivf, etc.,
40+
// If the cache directory follows the expected format of 00000.ivf, 00001.ivf, etc.,
4141
// then these unwraps will not fail
4242
x.file_stem()
4343
.unwrap()
@@ -242,10 +242,10 @@ pub fn mkvmerge_options_json(
242242
}
243243

244244
/// Concatenates using ffmpeg (does not work with x265)
245-
pub fn ffmpeg(temp: &Path, output: &Path) -> anyhow::Result<()> {
246-
fn write_concat_file(temp_folder: &Path) -> anyhow::Result<()> {
247-
let concat_file = temp_folder.join("concat");
248-
let encode_folder = temp_folder.join("encode");
245+
pub fn ffmpeg(cache: &Path, output: &Path) -> anyhow::Result<()> {
246+
fn write_concat_file(cache_folder: &Path) -> anyhow::Result<()> {
247+
let concat_file = cache_folder.join("concat");
248+
let encode_folder = cache_folder.join("encode");
249249

250250
let mut files = read_encoded_chunks(&encode_folder)?;
251251

@@ -270,16 +270,16 @@ pub fn ffmpeg(temp: &Path, output: &Path) -> anyhow::Result<()> {
270270
Ok(())
271271
}
272272

273-
let temp = PathAbs::new(temp)?;
274-
let temp = temp.as_path();
273+
let cache = PathAbs::new(cache)?;
274+
let cache = cache.as_path();
275275

276-
let concat = temp.join("concat");
276+
let concat = cache.join("concat");
277277
let concat_file = concat.to_str().unwrap();
278278

279-
write_concat_file(temp)?;
279+
write_concat_file(cache)?;
280280

281281
let audio_file = {
282-
let file = temp.join("audio.mkv");
282+
let file = cache.join("audio.mkv");
283283
if file.exists() && file.metadata().unwrap().len() > 1000 {
284284
Some(file)
285285
} else {

av1an-core/src/context.rs

+38-38
Original file line numberDiff line numberDiff line change
@@ -58,25 +58,25 @@ impl Av1anContext {
5858
Ok(this)
5959
}
6060

61-
/// Initialize logging routines and create temporary directories
61+
/// Initialize logging routines and create cache directories
6262
fn initialize(&mut self) -> anyhow::Result<()> {
6363
ffmpeg::init()?;
6464
ffmpeg::util::log::set_level(ffmpeg::util::log::level::Level::Fatal);
6565

66-
if !self.args.resume && Path::new(&self.args.temp).is_dir() {
67-
fs::remove_dir_all(&self.args.temp)
68-
.with_context(|| format!("Failed to remove temporary directory {:?}", &self.args.temp))?;
66+
if !self.args.resume && Path::new(&self.args.cache).is_dir() {
67+
fs::remove_dir_all(&self.args.cache)
68+
.with_context(|| format!("Failed to remove cache directory {:?}", &self.args.cache))?;
6969
}
7070

71-
create_dir!(Path::new(&self.args.temp))?;
72-
create_dir!(Path::new(&self.args.temp).join("split"))?;
73-
create_dir!(Path::new(&self.args.temp).join("encode"))?;
71+
create_dir!(Path::new(&self.args.cache))?;
72+
create_dir!(Path::new(&self.args.cache).join("split"))?;
73+
create_dir!(Path::new(&self.args.cache).join("encode"))?;
7474

75-
debug!("temporary directory: {}", &self.args.temp);
75+
debug!("cache directory: {}", &self.args.cache);
7676

77-
let done_path = Path::new(&self.args.temp).join("done.json");
77+
let done_path = Path::new(&self.args.cache).join("done.json");
7878
let done_json_exists = done_path.exists();
79-
let chunks_json_exists = Path::new(&self.args.temp).join("chunks.json").exists();
79+
let chunks_json_exists = Path::new(&self.args.cache).join("chunks.json").exists();
8080

8181
if self.args.resume {
8282
match (done_json_exists, chunks_json_exists) {
@@ -85,21 +85,21 @@ impl Av1anContext {
8585
(false, true) => {
8686
info!(
8787
"resume was set but done.json does not exist in temporary directory {:?}",
88-
&self.args.temp
88+
&self.args.cache
8989
);
9090
self.args.resume = false;
9191
}
9292
(true, false) => {
9393
info!(
9494
"resume was set but chunks.json does not exist in temporary directory {:?}",
95-
&self.args.temp
95+
&self.args.cache
9696
);
9797
self.args.resume = false;
9898
}
9999
(false, false) => {
100100
info!(
101101
"resume was set but neither chunks.json nor done.json exist in temporary directory {:?}",
102-
&self.args.temp
102+
&self.args.cache
103103
);
104104
self.args.resume = false;
105105
}
@@ -152,7 +152,7 @@ impl Av1anContext {
152152
{
153153
self.vs_script = Some(match &self.args.input {
154154
Input::VapourSynth(path) => path.clone(),
155-
Input::Video(path) => create_vs_file(&self.args.temp, path, self.args.chunk_method)?,
155+
Input::Video(path) => create_vs_file(&self.args.cache, path, self.args.chunk_method)?,
156156
});
157157

158158
let vs_script = self.vs_script.clone().unwrap();
@@ -198,8 +198,8 @@ impl Av1anContext {
198198
if self.args.sc_only {
199199
debug!("scene detection only");
200200

201-
if let Err(e) = fs::remove_dir_all(&self.args.temp) {
202-
warn!("Failed to delete temp directory: {}", e);
201+
if let Err(e) = fs::remove_dir_all(&self.args.cache) {
202+
warn!("Failed to delete cache directory: {}", e);
203203
}
204204

205205
exit(0);
@@ -227,13 +227,13 @@ impl Av1anContext {
227227
&& (!self.args.resume || !get_done().audio_done.load(atomic::Ordering::SeqCst))
228228
{
229229
let input = self.args.input.as_video_path();
230-
let temp = self.args.temp.as_str();
230+
let cache = self.args.cache.as_str();
231231
let audio_params = self.args.audio_params.as_slice();
232232
Some(s.spawn(move |_| {
233-
let audio_output = crate::ffmpeg::encode_audio(input, temp, audio_params);
233+
let audio_output = crate::ffmpeg::encode_audio(input, cache, audio_params);
234234
get_done().audio_done.store(true, atomic::Ordering::SeqCst);
235235

236-
let progress_file = Path::new(temp).join("done.json");
236+
let progress_file = Path::new(cache).join("done.json");
237237
let mut progress_file = File::create(progress_file).unwrap();
238238
progress_file
239239
.write_all(serde_json::to_string(get_done()).unwrap().as_bytes())
@@ -329,20 +329,20 @@ impl Av1anContext {
329329
match self.args.concat {
330330
ConcatMethod::Ivf => {
331331
concat::ivf(
332-
&Path::new(&self.args.temp).join("encode"),
332+
&Path::new(&self.args.cache).join("encode"),
333333
self.args.output_file.as_ref(),
334334
)?;
335335
}
336336
ConcatMethod::MKVMerge => {
337337
concat::mkvmerge(
338-
self.args.temp.as_ref(),
338+
self.args.cache.as_ref(),
339339
self.args.output_file.as_ref(),
340340
self.args.encoder,
341341
total_chunks,
342342
)?;
343343
}
344344
ConcatMethod::FFmpeg => {
345-
concat::ffmpeg(self.args.temp.as_ref(), self.args.output_file.as_ref())?;
345+
concat::ffmpeg(self.args.cache.as_ref(), self.args.output_file.as_ref())?;
346346
}
347347
}
348348

@@ -376,12 +376,12 @@ impl Av1anContext {
376376

377377
if !Path::new(&self.args.output_file).exists() {
378378
warn!(
379-
"Concatenation failed for unknown reasons! Temp folder will not be deleted: {}",
380-
&self.args.temp
379+
"Concatenation failed for unknown reasons! cache folder will not be deleted: {}",
380+
&self.args.cache
381381
);
382382
} else if !self.args.keep {
383-
if let Err(e) = fs::remove_dir_all(&self.args.temp) {
384-
warn!("Failed to delete temp directory: {}", e);
383+
if let Err(e) = fs::remove_dir_all(&self.args.cache) {
384+
warn!("Failed to delete cache directory: {}", e);
385385
}
386386
}
387387

@@ -416,7 +416,7 @@ impl Av1anContext {
416416
) -> Result<(), (Box<EncoderCrash>, u64)> {
417417
update_mp_chunk(worker_id, chunk.index, padding);
418418

419-
let fpf_file = Path::new(&chunk.temp)
419+
let fpf_file = Path::new(&chunk.cache)
420420
.join("split")
421421
.join(format!("{}_fpf", chunk.name()));
422422

@@ -767,7 +767,7 @@ impl Av1anContext {
767767
// scenes.json and return that.
768768
fn split_routine(&mut self) -> anyhow::Result<Vec<Scene>> {
769769
let scene_file = self.args.scenes.as_ref().map_or_else(
770-
|| Cow::Owned(Path::new(&self.args.temp).join("scenes.json")),
770+
|| Cow::Owned(Path::new(&self.args.cache).join("scenes.json")),
771771
|path| Cow::Borrowed(path.as_path()),
772772
);
773773

@@ -874,7 +874,7 @@ impl Av1anContext {
874874
let output_ext = self.args.encoder.output_extension();
875875

876876
let mut chunk = Chunk {
877-
temp: self.args.temp.clone(),
877+
cache: self.args.cache.clone(),
878878
index,
879879
input: Input::Video(src_path.to_path_buf()),
880880
source_cmd: ffmpeg_gen_cmd,
@@ -927,7 +927,7 @@ impl Av1anContext {
927927
let output_ext = self.args.encoder.output_extension();
928928

929929
let mut chunk = Chunk {
930-
temp: self.args.temp.clone(),
930+
cache: self.args.cache.clone(),
931931
index,
932932
input: Input::VapourSynth(vs_script.to_path_buf()),
933933
source_cmd: vspipe_cmd_gen,
@@ -1001,7 +1001,7 @@ impl Av1anContext {
10011001
debug!("Splitting video");
10021002
segment(
10031003
input,
1004-
&self.args.temp,
1004+
&self.args.cache,
10051005
&scenes
10061006
.iter()
10071007
.skip(1)
@@ -1010,12 +1010,12 @@ impl Av1anContext {
10101010
);
10111011
debug!("Splitting done");
10121012

1013-
let source_path = Path::new(&self.args.temp).join("split");
1013+
let source_path = Path::new(&self.args.cache).join("split");
10141014
let queue_files = Self::read_queue_files(&source_path)?;
10151015

10161016
assert!(
10171017
!queue_files.is_empty(),
1018-
"Error: No files found in temp/split, probably splitting not working"
1018+
"Error: No files found in cache/split, probably splitting not working"
10191019
);
10201020

10211021
let chunk_queue: Vec<Chunk> = queue_files
@@ -1049,10 +1049,10 @@ impl Av1anContext {
10491049
.collect();
10501050

10511051
debug!("Segmenting video");
1052-
segment(input, &self.args.temp, &to_split[1..]);
1052+
segment(input, &self.args.cache, &to_split[1..]);
10531053
debug!("Segment done");
10541054

1055-
let source_path = Path::new(&self.args.temp).join("split");
1055+
let source_path = Path::new(&self.args.cache).join("split");
10561056
let queue_files = Self::read_queue_files(&source_path)?;
10571057

10581058
let kf_list = to_split
@@ -1127,7 +1127,7 @@ impl Av1anContext {
11271127
let num_frames = num_frames(Path::new(file))?;
11281128

11291129
let mut chunk = Chunk {
1130-
temp: self.args.temp.clone(),
1130+
cache: self.args.cache.clone(),
11311131
input: Input::Video(PathBuf::from(file)),
11321132
source_cmd: ffmpeg_gen_cmd,
11331133
output_ext: output_ext.to_owned(),
@@ -1155,7 +1155,7 @@ impl Av1anContext {
11551155
/// Returns unfinished chunks and number of total chunks
11561156
fn load_or_gen_chunk_queue(&mut self, splits: &[Scene]) -> anyhow::Result<(Vec<Chunk>, usize)> {
11571157
if self.args.resume {
1158-
let mut chunks = read_chunk_queue(self.args.temp.as_ref())?;
1158+
let mut chunks = read_chunk_queue(self.args.cache.as_ref())?;
11591159
let num_chunks = chunks.len();
11601160

11611161
let done = get_done();
@@ -1167,7 +1167,7 @@ impl Av1anContext {
11671167
} else {
11681168
let chunks = self.create_encoding_queue(splits)?;
11691169
let num_chunks = chunks.len();
1170-
save_chunk_queue(&self.args.temp, &chunks)?;
1170+
save_chunk_queue(&self.args.cache, &chunks)?;
11711171
Ok((chunks, num_chunks))
11721172
}
11731173
}

av1an-core/src/encoder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -816,7 +816,7 @@ impl Encoder {
816816
/// Constructs tuple of commands for target quality probing
817817
pub fn probe_cmd(
818818
self,
819-
temp: String,
819+
cache: String,
820820
chunk_index: usize,
821821
q: usize,
822822
pix_fmt: Pixel,
@@ -836,7 +836,7 @@ impl Encoder {
836836
);
837837

838838
let probe_name = format!("v_{q}_{chunk_index}.ivf");
839-
let mut probe = PathBuf::from(temp);
839+
let mut probe = PathBuf::from(cache);
840840
probe.push("split");
841841
probe.push(&probe_name);
842842
let probe_path = probe.to_str().unwrap().to_owned();

av1an-core/src/ffmpeg.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -149,14 +149,14 @@ pub fn has_audio(file: &Path) -> bool {
149149
#[must_use]
150150
pub fn encode_audio<S: AsRef<OsStr>>(
151151
input: impl AsRef<Path>,
152-
temp: impl AsRef<Path>,
152+
cache: impl AsRef<Path>,
153153
audio_params: &[S],
154154
) -> Option<PathBuf> {
155155
let input = input.as_ref();
156-
let temp = temp.as_ref();
156+
let cache = cache.as_ref();
157157

158158
if has_audio(input) {
159-
let audio_file = Path::new(temp).join("audio.mkv");
159+
let audio_file = Path::new(cache).join("audio.mkv");
160160
let mut encode_audio = Command::new("ffmpeg");
161161

162162
encode_audio.stdout(Stdio::piped());

0 commit comments

Comments
 (0)