Skip to content

A fast file manager for Windows and macOS that never freezes: tabs, dual panes, archives as folders, Quick Look-style previews. A File Explorer and Finder alternative written in Rust.

DirectLook says when a file is a raw H.264 or H.265 stream (1044)

gelenmedya44b2e97bb51f
diff --git a/crates/rf-app/src/i18n_en.rs b/crates/rf-app/src/i18n_en.rs
index 9cd059c4..b2ce31dc 100644
--- a/crates/rf-app/src/i18n_en.rs
+++ b/crates/rf-app/src/i18n_en.rs
@@ -2219,6 +2219,7 @@ pub const EN: &[(&str, &str)] = &[
("ÜST ADA", "TOP ISLAND"),
("ALT ADA", "BOTTOM ISLAND"),
("Yazdır", "Print"),
+ ("ham {codec} video akışı: kabı yok, bu yüzden oynatılamıyor", "a raw {codec} video stream: it has no container, so it cannot be played"),
("MASAÜSTÜ VE KABUK", "DESKTOP AND SHELL"),
("DENEYSEL", "EXPERIMENTAL"),
("Dock kapalı: bu ayar yalnızca Dock çalışırken işe yarar. Açmak için sayfanın başındaki Dock anahtarını kullanın.", "The dock is off: this setting only works while the dock runs. Use the dock switch at the top of the page to turn it on."),
diff --git a/crates/rf-app/src/look/viewers/hex.rs b/crates/rf-app/src/look/viewers/hex.rs
index a43b1cae..a49bbce5 100644
--- a/crates/rf-app/src/look/viewers/hex.rs
+++ b/crates/rf-app/src/look/viewers/hex.rs
@@ -95,6 +95,27 @@ impl HexView {
}
}
+/// Whether `bytes` begin as a raw H.264 or H.265 stream (Annex B: a start code, then a parameter set), as a camera or an encoder
+/// writes one with no container around it. Such a file has no box that says it is a video, so it is shown here as bytes. Pure.
+fn raw_video_stream(bytes: &[u8]) -> Option<&'static str> {
+ let nal = match bytes {
+ [0, 0, 0, 1, n, ..] | [0, 0, 1, n, ..] => *n,
+ _ => return None,
+ };
+ if nal & 0x80 != 0 {
+ return None;
+ }
+ // H.265: a video, sequence or picture parameter set (types 32, 33, 34) or an access unit delimiter (35)
+ if matches!((nal >> 1) & 0x3F, 32..=35) && bytes.len() > 5 {
+ return Some("H.265");
+ }
+ // H.264: a sequence or picture parameter set (7, 8) or an access unit delimiter (9)
+ if matches!(nal & 0x1F, 7..=9) {
+ return Some("H.264");
+ }
+ None
+}
+
impl Render for HexView {
fn render(&mut self, window: &mut Window, cx: &mut Context<Self>) -> impl IntoElement {
let p = crate::theme::Palette::for_window(window);
@@ -108,6 +129,11 @@ impl Render for HexView {
} else {
rf_core::format::size(self.total)
};
+ // (a raw video stream says what it is: issue 1044, a camera's .h265 opened as bytes with no word why)
+ let note = match raw_video_stream(&self.bytes) {
+ Some(codec) => format!("{note} · {}", t!("ham {codec} video akışı: kabı yok, bu yüzden oynatılamıyor").replace("{codec}", codec)),
+ None => note,
+ };
let mono = || div().font_family("Cascadia Mono").text_size(px(13.));
let (text_c, dim_c, faint_c) = (p.text, p.text_secondary, p.text_tertiary);
let head = h_flex()
@@ -166,3 +192,19 @@ mod tests {
assert_eq!(ascii, "····Hi!");
}
}
+
+#[cfg(test)]
+mod raw_stream_tests {
+ use super::raw_video_stream;
+
+ /// Issue 1044: the reporter's file began 00 00 00 01 40 01 (an H.265 VPS).
+ #[test]
+ fn a_raw_video_stream_is_told_by_its_first_bytes() {
+ assert_eq!(raw_video_stream(&[0, 0, 0, 1, 0x40, 0x01, 0x0C]), Some("H.265"));
+ assert_eq!(raw_video_stream(&[0, 0, 0, 1, 0x67, 0x64, 0x00]), Some("H.264"));
+ assert_eq!(raw_video_stream(&[0, 0, 1, 0x09, 0xF0]), Some("H.264"));
+ assert_eq!(raw_video_stream(b"PK a zip"), None);
+ assert_eq!(raw_video_stream(&[0, 0, 0, 1, 0x80]), None, "a forbidden bit set is no stream");
+ assert_eq!(raw_video_stream(&[]), None);
+ }
+}