mirror of
https://github.com/storytold/filmcraft.git
synced 2026-11-02 18:09:21 +00:00
Parse AVI stream numbers as decimal (#3603)
* Parse AVI stream numbers as decimal Found while testing crates/avi/src/lib.rs:158 Co-Authored-By: GPT-6-Luna <noreply@openai.com> * fix: support decimal and hexadecimal AVI stream IDs Co-Authored-By: GPT-6-Luna <noreply@openai.com> * avi: two decimal digits or a hex letter, never a sign, in a stream id Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: GPT-6-Luna <noreply@openai.com> Co-authored-by: Brandon Thomas <echelon@gmail.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -156,8 +156,12 @@ pub struct Stream {
|
||||
impl Stream {
|
||||
/// Stream index of a `movi` chunk id (`00dc`, `01wb`…): its first two characters.
|
||||
fn number(id: &[u8; 4]) -> Option<usize> {
|
||||
let d = |b: u8| (b as char).to_digit(16).map(|v| v as usize);
|
||||
Some(d(id[0])? * 16 + d(id[1])?)
|
||||
// ffmpeg-style writers number streams in decimal ("10dc" = 10), Video for Windows in hex
|
||||
// ("0adc" = 10): a hex letter means hex, two decimal digits mean decimal
|
||||
let [a, b, ..] = *id;
|
||||
let radix = if [a, b].iter().any(|c| matches!(c, b'a'..=b'f' | b'A'..=b'F')) { 16 } else { 10 };
|
||||
let d = |c: u8| (c as char).to_digit(radix).map(|v| v as usize);
|
||||
Some(d(a)? * radix as usize + d(b)?)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,17 @@
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn stream_number_supports_decimal_and_hex_ids() {
|
||||
assert_eq!(Stream::number(b"10dc"), Some(10));
|
||||
assert_eq!(Stream::number(b"0adc"), Some(10));
|
||||
assert_eq!(Stream::number(b"00dc"), Some(0));
|
||||
assert_eq!(Stream::number(b"09wb"), Some(9));
|
||||
assert_eq!(Stream::number(b"0Fdc"), Some(15));
|
||||
// `from_str_radix` would take a sign; a chunk id never has one
|
||||
assert_eq!(Stream::number(b"+1dc"), None);
|
||||
assert_eq!(Stream::number(b"ixdc"), None);
|
||||
}
|
||||
|
||||
fn chunk(id: &[u8; 4], data: &[u8]) -> Vec<u8> {
|
||||
let mut v = id.to_vec();
|
||||
v.extend_from_slice(&(data.len() as u32).to_le_bytes());
|
||||
|
||||
Reference in New Issue
Block a user