Skip to main content

viser_contextaware/
profile.rs

1use serde::{Deserialize, Serialize};
2use viser_ffmpeg::{
3    Codec, RES_360P, RES_480P, RES_720P, RES_1080P, RES_1440P, RES_2160P, Resolution,
4};
5use viser_ladder::Opts as LadderOpts;
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
8#[serde(rename_all = "snake_case")]
9pub enum DeviceClass {
10    Mobile,
11    Desktop,
12    Tv,
13    Tv4k,
14}
15
16/// Encoding constraints and quality targets for a device class.
17#[derive(Debug, Clone, Serialize, Deserialize)]
18pub struct Profile {
19    pub name: String,
20    pub device: DeviceClass,
21    pub description: String,
22    pub vmaf_model: String,
23    pub max_res: Resolution,
24    pub resolutions: Vec<Resolution>,
25    pub codecs: Vec<Codec>,
26    pub ladder_opts: LadderOpts,
27}
28
29pub fn mobile_profile() -> Profile {
30    Profile {
31        name: "Mobile".into(),
32        device: DeviceClass::Mobile,
33        description: "Smartphones and small tablets. Screen <7 inches.".into(),
34        vmaf_model: "vmaf_v0.6.1".into(),
35        max_res: RES_720P,
36        resolutions: vec![RES_360P, RES_480P, RES_720P],
37        codecs: vec![Codec::SvtAv1, Codec::X264],
38        ladder_opts: LadderOpts {
39            num_rungs: 4,
40            min_bitrate: 150.0,
41            max_bitrate: 3000.0,
42            min_vmaf: 50.0,
43            max_vmaf: 95.0,
44            audio_bitrate_kbps: 0.0,
45        },
46    }
47}
48
49pub fn desktop_profile() -> Profile {
50    Profile {
51        name: "Desktop".into(),
52        device: DeviceClass::Desktop,
53        description: "Laptops and desktop monitors. 13-27 inch screens.".into(),
54        vmaf_model: "vmaf_v0.6.1".into(),
55        max_res: RES_1080P,
56        resolutions: vec![RES_480P, RES_720P, RES_1080P],
57        codecs: vec![Codec::SvtAv1, Codec::X265, Codec::X264],
58        ladder_opts: LadderOpts::default(),
59    }
60}
61
62pub fn tv_profile() -> Profile {
63    Profile {
64        name: "TV (1080p)".into(),
65        device: DeviceClass::Tv,
66        description: "TVs and large displays. 40-65 inch screens.".into(),
67        vmaf_model: "vmaf_v0.6.1".into(),
68        max_res: RES_1080P,
69        resolutions: vec![RES_480P, RES_720P, RES_1080P],
70        codecs: vec![Codec::SvtAv1, Codec::X265, Codec::X264],
71        ladder_opts: LadderOpts {
72            num_rungs: 8,
73            min_bitrate: 200.0,
74            max_bitrate: 12000.0,
75            min_vmaf: 40.0,
76            max_vmaf: 0.0,
77            audio_bitrate_kbps: 0.0,
78        },
79    }
80}
81
82pub fn tv_4k_profile() -> Profile {
83    Profile {
84        name: "TV (4K)".into(),
85        device: DeviceClass::Tv4k,
86        description: "4K TVs. 55-85 inch screens.".into(),
87        vmaf_model: "vmaf_4k_v0.6.1".into(),
88        max_res: RES_2160P,
89        resolutions: vec![RES_720P, RES_1080P, RES_1440P, RES_2160P],
90        codecs: vec![Codec::SvtAv1, Codec::X265],
91        ladder_opts: LadderOpts {
92            num_rungs: 8,
93            min_bitrate: 1000.0,
94            max_bitrate: 25000.0,
95            min_vmaf: 40.0,
96            max_vmaf: 97.0,
97            audio_bitrate_kbps: 0.0,
98        },
99    }
100}
101
102pub fn all_profiles() -> Vec<Profile> {
103    vec![mobile_profile(), desktop_profile(), tv_profile(), tv_4k_profile()]
104}