hang/catalog/video/
codec.rs1use super::*;
2
3use std::str::FromStr;
4
5use derive_more::{Display, From};
6
7use crate::Error;
8
9#[derive(Debug, Clone, PartialEq, Eq, Display, From)]
12#[non_exhaustive]
13pub enum VideoCodec {
14 H264(H264),
16 H265(H265),
18 VP9(VP9),
20 AV1(AV1),
22
23 #[display("vp8")]
25 VP8,
26
27 #[display("{_0}")]
29 Unknown(String),
30}
31
32#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
34#[non_exhaustive]
35pub enum VideoCodecKind {
36 H264,
38 H265,
40 VP8,
42 VP9,
44 AV1,
46 Unknown,
48}
49
50impl VideoCodec {
51 pub fn kind(&self) -> VideoCodecKind {
53 match self {
54 Self::H264(_) => VideoCodecKind::H264,
55 Self::H265(_) => VideoCodecKind::H265,
56 Self::VP9(_) => VideoCodecKind::VP9,
57 Self::AV1(_) => VideoCodecKind::AV1,
58 Self::VP8 => VideoCodecKind::VP8,
59 Self::Unknown(_) => VideoCodecKind::Unknown,
60 }
61 }
62}
63
64impl FromStr for VideoCodec {
65 type Err = Error;
66
67 fn from_str(s: &str) -> Result<Self, Self::Err> {
68 if s.starts_with("avc1.") || s.starts_with("avc3.") {
69 return H264::from_str(s).map(Into::into);
70 } else if s.starts_with("hvc1.") || s.starts_with("hev1.") {
71 return H265::from_str(s).map(Into::into);
72 } else if s == "vp8" {
73 return Ok(Self::VP8);
74 } else if s.starts_with("vp09.") {
75 return VP9::from_str(s).map(Into::into);
76 } else if s.starts_with("av01.") {
77 return AV1::from_str(s).map(Into::into);
78 }
79
80 Ok(Self::Unknown(s.to_string()))
81 }
82}