Skip to content

Commit

Permalink
Use buffered IO
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianEddy committed Aug 27, 2024
1 parent fce38e5 commit 627b2c4
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ jobs:
mv target/${{ matrix.targets.target }}/release/mp4_merge${{ matrix.targets.ext }} dist/mp4_merge-${{ matrix.targets.name }}${{ matrix.targets.ext }}
- name: Save Binaries
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
with:
name: mp4_merge
path: dist/mp4_merge*
Expand All @@ -68,7 +68,7 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Download artifacts
uses: actions/download-artifact@v3
uses: actions/download-artifact@v4
with:
name: mp4_merge

Expand Down
1 change: 1 addition & 0 deletions src/insta360.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ pub const MAGIC: &[u8] = b"8db42d694ccc418790edff439fe026bf";
pub fn get_insta360_offsets<R: Read + Seek>(files: &mut [(R, usize)]) -> Result<Vec<BTreeMap<u64, (u32, u8, u8, i64)>>> {
let mut ret = Vec::new();
for (ref mut stream, size) in files {
let mut stream = std::io::BufReader::with_capacity(16*1024, stream);

let mut buf = vec![0u8; HEADER_SIZE];
stream.seek(SeekFrom::End(-(HEADER_SIZE as i64)))?;
Expand Down
7 changes: 4 additions & 3 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ pub fn join_file_streams<F: Fn(f64), I: Read + Seek, O: Read + Write + Seek>(fil
let mut insta360_max_read = None;
for (i, fs) in files.iter_mut().enumerate() {
let filesize = fs.1;
let mut fs = &mut fs.0;
let mut fs = std::io::BufReader::with_capacity(16*1024, &mut fs.0);
total_size += filesize;

{ // Find mdat first
Expand Down Expand Up @@ -115,12 +115,13 @@ pub fn join_file_streams<F: Fn(f64), I: Read + Seek, O: Read + Write + Seek>(fil

// Write it to the file
let mut debounce = Instant::now();
let mut f_out = ProgressStream::new(output_file, |total| {
if (Instant::now() - debounce).as_millis() > 20 {
let f_out = ProgressStream::new(output_file, |total| {
if (Instant::now() - debounce).as_millis() > 100 {
progress_cb((0.1 + ((total as f64 / total_size as f64) * 0.9)).min(0.9999));
debounce = Instant::now();
}
});
let mut f_out = std::io::BufWriter::with_capacity(64*1024, f_out);

writer::get_first(files).seek(std::io::SeekFrom::Start(0))?;
writer::rewrite_from_desc(files, &mut f_out, &mut desc, 0, insta360_max_read.unwrap_or(u64::MAX))?;
Expand Down

0 comments on commit 627b2c4

Please sign in to comment.