• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2024 The ChromiumOS Authors
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 use std::path::PathBuf;
6 use std::str::FromStr;
7 
8 use argh::FromArgs;
9 
10 use cros_codecs::DecodedFormat;
11 
12 #[derive(Debug, PartialEq, Eq, Copy, Clone, Default)]
13 pub enum Codec {
14     #[default]
15     H264,
16     H265,
17     VP8,
18     VP9,
19     AV1,
20 }
21 
22 impl FromStr for Codec {
23     type Err = &'static str;
24 
from_str(s: &str) -> Result<Self, Self::Err>25     fn from_str(s: &str) -> Result<Self, Self::Err> {
26         match s {
27             "h264" | "H264" => Ok(Self::H264),
28             "h265" | "H265" => Ok(Self::H265),
29             "vp8" | "VP8" => Ok(Self::VP8),
30             "vp9" | "VP9" => Ok(Self::VP9),
31             "av1" | "AV1" => Ok(Self::AV1),
32             _ => Err("unrecognized codec. Valid values: h264, h265, vp8, vp9, av1"),
33         }
34     }
35 }
36 
37 /// Simple encoder
38 #[derive(Debug, FromArgs)]
39 pub struct Args {
40     /// input file
41     #[argh(positional)]
42     pub input: PathBuf,
43 
44     /// input frames width
45     #[argh(option)]
46     pub width: u32,
47 
48     /// input frames height
49     #[argh(option)]
50     pub height: u32,
51 
52     /// input frame coded width
53     #[argh(option)]
54     pub coded_width: Option<u32>,
55 
56     /// input frame coded height
57     #[argh(option)]
58     pub coded_height: Option<u32>,
59 
60     /// input frames count
61     #[argh(option)]
62     pub count: usize,
63 
64     /// input fourcc
65     #[argh(option)]
66     pub fourcc: DecodedFormat,
67 
68     /// codec
69     #[argh(option)]
70     pub codec: Option<Codec>,
71 
72     /// framerate
73     #[argh(option, default = "30")]
74     pub framerate: u32,
75 
76     /// bitrate
77     #[argh(option, default = "200000")]
78     pub bitrate: u64,
79 
80     /// output file to write the decoded frames to
81     #[argh(option)]
82     pub output: Option<PathBuf>,
83 
84     /// set to true if low power version of the API shall be used
85     #[allow(dead_code)]
86     #[argh(switch)]
87     pub low_power: bool,
88 }
89