mp4 example: fix panic on empty video
```
thread 'main' panicked at 'range start index 1 out of range for slice of length 0', examples/client/mp4.rs:171:44
stack backtrace:
0: rust_begin_unwind
at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/std/src/panicking.rs:515:5
1: core::panicking::panic_fmt
at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/panicking.rs:92:14
2: core::slice::index::slice_start_index_len_fail
at /rustc/a178d0322ce20e33eac124758e837cbd80a6f633/library/core/src/slice/index.rs:34:5
3: client::mp4::TrakTracker::write_common_stbl_parts
4: client::mp4::Mp4Writer<W>::write_audio_trak
5: client::mp4::run::{{closure}}
6: <core::future::from_generator::GenFuture<T> as core::future::future::Future>::poll
7: tokio::park:🧵:CachedParkThread::block_on
8: tokio::runtime::thread_pool::ThreadPool::block_on
9: tokio::runtime::Runtime::block_on
10: client::main
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
```
This commit is contained in:
parent
6155d4ebcf
commit
76b3a61eb7
@ -168,14 +168,14 @@ impl TrakTracker {
|
||||
buf.put_u32(u32::try_from(self.chunks.len())?);
|
||||
let mut prev_sample_number = 1;
|
||||
let mut chunk_number = 1;
|
||||
for &(sample_number, _pos) in &self.chunks[1..] {
|
||||
buf.put_u32(chunk_number);
|
||||
buf.put_u32(sample_number - prev_sample_number);
|
||||
buf.put_u32(1); // sample_description_index
|
||||
prev_sample_number = sample_number;
|
||||
chunk_number += 1;
|
||||
}
|
||||
if !self.chunks.is_empty() {
|
||||
for &(sample_number, _pos) in &self.chunks[1..] {
|
||||
buf.put_u32(chunk_number);
|
||||
buf.put_u32(sample_number - prev_sample_number);
|
||||
buf.put_u32(1); // sample_description_index
|
||||
prev_sample_number = sample_number;
|
||||
chunk_number += 1;
|
||||
}
|
||||
buf.put_u32(chunk_number);
|
||||
buf.put_u32(self.samples + 1 - prev_sample_number);
|
||||
buf.put_u32(1); // sample_description_index
|
||||
|
Loading…
Reference in New Issue
Block a user