Skip to content

Commit dea7648

Browse files
committed
Add progress bar to render process
1 parent fa5144b commit dea7648

File tree

5 files changed

+192
-58
lines changed

5 files changed

+192
-58
lines changed

Cargo.lock

Lines changed: 140 additions & 14 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,3 +17,4 @@ ffmpeg-next = "6.0.0"
1717
ndarray = "0.15.6"
1818
fast_image_resize = "2.7.3"
1919
clap = { version = "4.3.5", features = [ "derive" ] }
20+
indicatif = "0.17.5"

src/data/song.rs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ pub struct Channel {
3737

3838
#[serde(skip)]
3939
pub play_time_samples: u64,
40+
41+
#[serde(skip)]
42+
pub play_time_samples_total: u64,
4043
}
4144

4245
#[derive(Debug)]
@@ -69,7 +72,7 @@ impl Channel {
6972
Ok(packet) => packet,
7073
Err(Error::IoError(_err)) => {
7174
if self.play_time_samples
72-
>= track.codec_params.n_frames.unwrap() - min_samples_required as u64
75+
>= self.play_time_samples_total - min_samples_required as u64
7376
{
7477
return Err(SongError::End);
7578
}
@@ -166,9 +169,6 @@ impl Window {
166169
pub struct Song {
167170
pub channels: Vec<Channel>,
168171
pub video_file_out: String,
169-
170-
#[serde(skip)]
171-
pub frame: usize,
172172
}
173173

174174
impl Song {
@@ -182,6 +182,11 @@ impl Song {
182182
let rdr = BufReader::new(file);
183183
let song: Song = serde_json::from_reader(rdr).unwrap();
184184

185+
assert!(
186+
song.channels.len() > 0,
187+
"Please provide at least one channel"
188+
);
189+
185190
println!("Loaded song with {} channels", song.channels.len());
186191
for channel in &song.channels {
187192
println!("- {} ({})", channel.name, channel.file);
@@ -193,6 +198,7 @@ impl Song {
193198
pub fn load_tracks_into_memory(&mut self) {
194199
for channel in &mut self.channels {
195200
let (format, track, decoder) = load_track_into_memory(&channel.file);
201+
channel.play_time_samples_total = track.codec_params.n_frames.unwrap();
196202
channel.format = Some(format);
197203
channel.track = Some(track);
198204
channel.decoder = Some(decoder);
@@ -314,11 +320,6 @@ impl Song {
314320
// Render frame to video
315321
encoding.render_frame(frame);
316322

317-
self.frame += 1;
318-
if self.frame % 100 == 0 {
319-
println!("Rendered {} frames", self.frame);
320-
}
321-
322323
Ok(())
323324
}
324325
}

0 commit comments

Comments
 (0)