From 839c1e1490e7cd856e6ada1dcfd82f3d4505c89c Mon Sep 17 00:00:00 2001 From: metamuffin Date: Mon, 2 Oct 2023 19:46:08 +0200 Subject: transcoding profiles --- common/src/config.rs | 66 ++++++++++++++++++++++++++++++++++++++++++++-------- common/src/lib.rs | 19 +++++++++++++++ common/src/stream.rs | 13 ++++------- 3 files changed, 79 insertions(+), 19 deletions(-) (limited to 'common') diff --git a/common/src/config.rs b/common/src/config.rs index aded4ff..e30e70b 100644 --- a/common/src/config.rs +++ b/common/src/config.rs @@ -4,7 +4,7 @@ Copyright (C) 2023 metamuffin */ -use crate::user::PermissionSet; +use crate::{user::PermissionSet, EncodingProfile}; use serde::{Deserialize, Serialize}; use std::{collections::HashMap, path::PathBuf}; @@ -19,6 +19,7 @@ pub struct GlobalConfig { #[serde(default = "default::temp_path")] pub temp_path: PathBuf, #[serde(default = "default::cache_path")] pub cache_path: PathBuf, #[serde(default = "default::admin_username")] pub admin_username: String, + #[serde(default = "default::transcoding_profiles")] pub transcoding_profiles: Vec, #[serde(default = "default::max_in_memory_cache_size")] pub max_in_memory_cache_size: usize, pub admin_password: String, #[serde(default)] pub cookie_key: Option, @@ -28,16 +29,61 @@ pub struct GlobalConfig { #[serde(default)] pub default_permission_set: PermissionSet, } -#[rustfmt::skip] mod default { + use crate::EncodingProfile; use std::path::PathBuf; - pub fn admin_username() -> String { "admin".into() } - pub fn login_expire() -> i64 { 60*60*24 } - pub fn asset_path() -> PathBuf { "data/assets".into() } - pub fn database_path() -> PathBuf { "data/database".into() } - pub fn library_path() -> PathBuf { "data/library".into() } - pub fn cache_path() -> PathBuf { "data/cache".into() } - pub fn temp_path() -> PathBuf { "/tmp".into() } - pub fn max_in_memory_cache_size() -> usize { 50_000_000 } + pub fn admin_username() -> String { + "admin".into() + } + pub fn login_expire() -> i64 { + 60 * 60 * 24 + } + pub fn asset_path() -> PathBuf { + "data/assets".into() + } + pub fn database_path() -> PathBuf { + "data/database".into() + } + pub fn library_path() -> PathBuf { + "data/library".into() + } + pub fn cache_path() -> PathBuf { + "data/cache".into() + } + pub fn temp_path() -> PathBuf { + "/tmp".into() + } + pub fn max_in_memory_cache_size() -> usize { + 50_000_000 + } + pub fn transcoding_profiles() -> Vec { + vec![ + EncodingProfile::Video { + codec: "libsvtav1".to_string(), + preset: 8, + bitrate: 2_000_000, + width: 1920, + }, + EncodingProfile::Video { + codec: "libsvtav1".to_string(), + preset: 8, + bitrate: 1_500_000, + width: 1280, + }, + EncodingProfile::Audio { + codec: "libopus".to_string(), + bitrate: 128_000, + sample_rate: None, + }, + EncodingProfile::Audio { + codec: "libopus".to_string(), + bitrate: 64_000, + sample_rate: None, + }, + EncodingProfile::Subtitles { + codec: "webvtt".to_string(), + }, + ] + } } diff --git a/common/src/lib.rs b/common/src/lib.rs index c425c21..6d1a78c 100644 --- a/common/src/lib.rs +++ b/common/src/lib.rs @@ -142,3 +142,22 @@ pub enum SourceTrackKind { }, Subtitles, } + +#[derive(Debug, Clone, Deserialize, Serialize)] +#[serde(rename_all = "snake_case")] +pub enum EncodingProfile { + Video { + codec: String, + preset: u8, + bitrate: usize, + width: usize, + }, + Audio { + codec: String, + bitrate: usize, + sample_rate: Option, + }, + Subtitles { + codec: String, + }, +} diff --git a/common/src/stream.rs b/common/src/stream.rs index 1fb3761..8a7ff36 100644 --- a/common/src/stream.rs +++ b/common/src/stream.rs @@ -13,8 +13,7 @@ pub struct StreamSpec { pub tracks: Vec, pub format: StreamFormat, pub webm: Option, - pub bitrate: Option, - pub width: Option, + pub profile: Option, pub index: Option, } @@ -37,8 +36,7 @@ impl Default for StreamSpec { tracks: Vec::new(), format: StreamFormat::Matroska, webm: Some(true), - width: None, - bitrate: None, + profile: None, index: None, } } @@ -62,8 +60,8 @@ impl StreamSpec { ) .unwrap(); } - if let Some(bitrate) = self.bitrate { - write!(u, "&bitrate={bitrate}").unwrap(); + if let Some(profile) = self.profile { + write!(u, "&profile={profile}").unwrap(); } if let Some(index) = self.index { write!(u, "&index={index}").unwrap(); @@ -71,9 +69,6 @@ impl StreamSpec { if let Some(webm) = self.webm { write!(u, "&webm={webm}").unwrap(); } - if let Some(width) = self.width { - write!(u, "&width={width}").unwrap(); - } u } } -- cgit v1.2.3-70-g09d2