}
}
+fn parse_bitrate(strval: &str) -> Result<u32, ()> {
+ let mut val = 0;
+ let mut has_suffix = false;
+ for ch in strval.chars() {
+ match ch {
+ _ if has_suffix => return Err(()),
+ '0'..='9' => {
+ if val >= std::u32::MAX / 100 {
+ return Err(());
+ }
+ val = val * 10 + ch.to_digit(10).unwrap_or(0);
+ },
+ 'k' | 'K' => {
+ if val >= std::u32::MAX / 1000 {
+ return Err(());
+ }
+ val *= 1000;
+ has_suffix = true;
+ },
+ 'm' | 'M' => {
+ if val >= std::u32::MAX / 1000000 {
+ return Err(());
+ }
+ val *= 1000000;
+ has_suffix = true;
+ },
+ _ => return Err(()),
+ };
+ }
+ Ok(val)
+}
+
struct OptionArgs {
name: String,
value: Option<String>,
}
},*/
"bitrate" => {
- let ret = oval[1].parse::<u32>();
+ let ret = parse_bitrate(oval[1]);
if let Ok(val) = ret {
ostr.enc_params.bitrate = val;
} else {