| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 | use crate::export::{ExportSettings, Format, HdrOutput, HdrTransfer, LoudnessTarget, ProResProfile}; |
| 13 | |
| 14 | |
| 15 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
| 16 | pub enum Category { |
| 17 | |
| 18 | Web, |
| 19 | |
| 20 | Social, |
| 21 | |
| 22 | Audio, |
| 23 | |
| 24 | Archive, |
| 25 | } |
| 26 | |
| 27 | |
| 28 | #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] |
| 29 | pub enum Output { |
| 30 | Video, |
| 31 | AudioOnly, |
| 32 | } |
| 33 | |
| 34 | |
| 35 | #[derive(Debug, Clone, Copy, PartialEq, Eq)] |
| 36 | pub struct Target { |
| 37 | pub category: Category, |
| 38 | pub output: Output, |
| 39 | |
| 40 | |
| 41 | pub size: Option<(u32, u32)>, |
| 42 | } |
| 43 | |
| 44 | |
| 45 | |
| 46 | #[derive(Debug, Clone, Copy, PartialEq)] |
| 47 | pub struct Preset { |
| 48 | |
| 49 | pub id: &'static str, |
| 50 | |
| 51 | pub label: &'static str, |
| 52 | |
| 53 | pub description: &'static str, |
| 54 | |
| 55 | pub target: Target, |
| 56 | pub format: Format, |
| 57 | |
| 58 | pub bitrate: Option<u64>, |
| 59 | |
| 60 | pub audio_kbps: u32, |
| 61 | |
| 62 | pub video_bit_depth: Option<u8>, |
| 63 | |
| 64 | pub loudness: Option<LoudnessTarget>, |
| 65 | |
| 66 | pub prores_profile: Option<ProResProfile>, |
| 67 | |
| 68 | |
| 69 | pub hdr: HdrTransfer, |
| 70 | |
| 71 | pub qp: Option<u32>, |
| 72 | |
| 73 | pub keyframe_s: Option<f64>, |
| 74 | |
| 75 | pub faststart: bool, |
| 76 | } |
| 77 | |
| 78 | const PODCAST: Option<LoudnessTarget> = Some(LoudnessTarget { lufs: -16.0, true_peak_dbtp: -1.0 }); |
| 79 | |
| 80 | #[allow(clippy::too_many_arguments)] |
| 81 | const fn video( |
| 82 | id: &'static str, |
| 83 | label: &'static str, |
| 84 | description: &'static str, |
| 85 | category: Category, |
| 86 | format: Format, |
| 87 | mbps: u64, |
| 88 | size: (u32, u32), |
| 89 | audio_kbps: u32, |
| 90 | ) -> Preset { |
| 91 | Preset { |
| 92 | id, |
| 93 | label, |
| 94 | description, |
| 95 | target: Target { category, output: Output::Video, size: Some(size) }, |
| 96 | format, |
| 97 | bitrate: Some(mbps * 1_000_000), |
| 98 | audio_kbps, |
| 99 | video_bit_depth: None, |
| 100 | loudness: None, |
| 101 | prores_profile: None, |
| 102 | hdr: HdrTransfer::Sdr, |
| 103 | qp: None, |
| 104 | keyframe_s: None, |
| 105 | faststart: false, |
| 106 | } |
| 107 | } |
| 108 | |
| 109 | const fn sound( |
| 110 | id: &'static str, |
| 111 | label: &'static str, |
| 112 | description: &'static str, |
| 113 | category: Category, |
| 114 | format: Format, |
| 115 | audio_kbps: u32, |
| 116 | loudness: Option<LoudnessTarget>, |
| 117 | ) -> Preset { |
| 118 | Preset { |
| 119 | id, |
| 120 | label, |
| 121 | description, |
| 122 | target: Target { category, output: Output::AudioOnly, size: None }, |
| 123 | format, |
| 124 | bitrate: None, |
| 125 | audio_kbps, |
| 126 | video_bit_depth: None, |
| 127 | loudness, |
| 128 | prores_profile: None, |
| 129 | hdr: HdrTransfer::Sdr, |
| 130 | qp: None, |
| 131 | keyframe_s: None, |
| 132 | faststart: false, |
| 133 | } |
| 134 | } |
| 135 | |
| 136 | const WEB: Category = Category::Web; |
| 137 | const HD: (u32, u32) = (1920, 1080); |
| 138 | const UHD: (u32, u32) = (3840, 2160); |
| 139 | |
| 140 | static TABLE: [Preset; 16] = [ |
| 141 | video("youtube_1080p", "YouTube 1920×1080", "H.264 1080p30 at 8 Mb/s, AAC 384k: YouTube's recommended SDR upload.", WEB, Format::Mp4, 8, HD, 384), |
| 142 | video("youtube_1080p60", "YouTube 1920×1080 60fps", "H.264 1080p60 at 12 Mb/s, AAC 384k.", WEB, Format::Mp4, 12, HD, 384), |
| 143 | video("youtube_1080p_hevc", "YouTube 1920×1080 HEVC", "HEVC 1080p at 6 Mb/s in an mp4, AAC 384k: a smaller file at the same look.", WEB, Format::HevcMp4, 6, HD, 384), |
| 144 | video("youtube_4k", "YouTube 3840×2160", "H.264 2160p30 at 40 Mb/s, AAC 384k.", WEB, Format::Mp4, 40, UHD, 384), |
| 145 | video("youtube_4k60", "YouTube 3840×2160 60fps", "H.264 2160p60 at 50 Mb/s (the engine's ceiling; YouTube suggests 53-68), AAC 384k.", WEB, Format::Mp4, 50, UHD, 384), |
| 146 | video("youtube_4k_hevc", "YouTube 3840×2160 HEVC", "HEVC 2160p at 28 Mb/s in an mp4, AAC 384k.", WEB, Format::HevcMp4, 28, UHD, 384), |
| 147 | Preset { |
| 148 | id: "youtube_4k_master", |
| 149 | label: "YouTube 3840×2160 master", |
| 150 | description: "HEVC 2160p, constant QP 18 on the GPU, 0.5 s keyframes, AAC 384k, faststart: an upload YouTube re-encodes from.", |
| 151 | target: Target { category: WEB, output: Output::Video, size: Some(UHD) }, |
| 152 | format: Format::HevcMp4, |
| 153 | bitrate: None, |
| 154 | audio_kbps: 384, |
| 155 | video_bit_depth: None, |
| 156 | loudness: None, |
| 157 | prores_profile: None, |
| 158 | hdr: HdrTransfer::Sdr, |
| 159 | qp: Some(18), |
| 160 | keyframe_s: Some(0.5), |
| 161 | faststart: true, |
| 162 | }, |
| 163 | video("shorts_reels", "Shorts / Reels", "Vertical 9:16 1080x1920, H.264 at 8 Mb/s, AAC 192k.", Category::Social, Format::Mp4, 8, (1080, 1920), 192), |
| 164 | sound("podcast", "Podcast m4a", "AAC 128k in an m4a, levelled to -16 LUFS with a -1 dBTP ceiling.", Category::Audio, Format::M4a, 128, PODCAST), |
| 165 | sound("podcast_ogg", "Podcast ogg", "Vorbis in an ogg, -16 LUFS, -1 dBTP.", Category::Audio, Format::Ogg, 128, PODCAST), |
| 166 | sound("podcast_opus", "Podcast opus", "Opus 96k stereo in an Ogg file, levelled to -16 LUFS with a -1 dBTP ceiling.", Category::Audio, Format::Opus, 96, PODCAST), |
| 167 | Preset { |
| 168 | id: "archive", |
| 169 | label: "Archive 10-bit AV1", |
| 170 | description: "10-bit AV1 in an mkv at 30 Mb/s, the project's size, audio at the top AAC rate.", |
| 171 | target: Target { category: Category::Archive, output: Output::Video, size: None }, |
| 172 | format: Format::Av1, |
| 173 | bitrate: Some(30_000_000), |
| 174 | audio_kbps: 320, |
| 175 | video_bit_depth: Some(10), |
| 176 | loudness: None, |
| 177 | prores_profile: None, |
| 178 | hdr: HdrTransfer::Sdr, |
| 179 | qp: None, |
| 180 | keyframe_s: None, |
| 181 | faststart: false, |
| 182 | }, |
| 183 | Preset { |
| 184 | id: "archive_prores", |
| 185 | label: "ProRes 422 HQ master", |
| 186 | description: "ProRes 422 HQ in a QuickTime .mov at the project's size, 24-bit PCM sound: an editing master.", |
| 187 | target: Target { category: Category::Archive, output: Output::Video, size: None }, |
| 188 | format: Format::ProRes, |
| 189 | bitrate: None, |
| 190 | audio_kbps: 320, |
| 191 | video_bit_depth: None, |
| 192 | loudness: None, |
| 193 | prores_profile: Some(ProResProfile::Hq), |
| 194 | hdr: HdrTransfer::Sdr, |
| 195 | qp: None, |
| 196 | keyframe_s: None, |
| 197 | faststart: false, |
| 198 | }, |
| 199 | Preset { |
| 200 | id: "hdr10_hevc", |
| 201 | label: "HDR10 (HEVC 10-bit)", |
| 202 | description: "10-bit HEVC in an mp4 tagged HDR10 (PQ, BT.2020) at 40 Mb/s, the project's size, AAC 384k.", |
| 203 | target: Target { category: Category::Archive, output: Output::Video, size: None }, |
| 204 | format: Format::HevcMp4, |
| 205 | bitrate: Some(40_000_000), |
| 206 | audio_kbps: 384, |
| 207 | video_bit_depth: Some(10), |
| 208 | loudness: None, |
| 209 | prores_profile: None, |
| 210 | hdr: HdrTransfer::Pq, |
| 211 | qp: None, |
| 212 | keyframe_s: None, |
| 213 | faststart: false, |
| 214 | }, |
| 215 | sound("archive_flac", "Archive FLAC", "Lossless FLAC of the mix.", Category::Archive, Format::Flac, 320, None), |
| 216 | sound("archive_wav", "Archive WAV", "16-bit PCM WAV of the mix.", Category::Archive, Format::Wav, 320, None), |
| 217 | ]; |
| 218 | |
| 219 | |
| 220 | pub fn presets() -> &'static [Preset] { |
| 221 | &TABLE |
| 222 | } |
| 223 | |
| 224 | |
| 225 | pub fn by_id(id: &str) -> Option<&'static Preset> { |
| 226 | TABLE.iter().find(|p| p.id == id) |
| 227 | } |
| 228 | |
| 229 | impl Preset { |
| 230 | |
| 231 | pub fn settings(&self) -> ExportSettings { |
| 232 | apply(self, ExportSettings::default()) |
| 233 | } |
| 234 | } |
| 235 | |
| 236 | |
| 237 | |
| 238 | |
| 239 | pub fn apply(preset: &Preset, base: ExportSettings) -> ExportSettings { |
| 240 | ExportSettings { |
| 241 | format: preset.format, |
| 242 | bitrate: preset.bitrate, |
| 243 | audio_kbps: Some(preset.audio_kbps), |
| 244 | size: preset.target.size, |
| 245 | video_bit_depth: preset.video_bit_depth.or(base.video_bit_depth), |
| 246 | loudness: preset.loudness, |
| 247 | prores_profile: preset.prores_profile.unwrap_or(base.prores_profile), |
| 248 | hdr: HdrOutput { transfer: preset.hdr, ..HdrOutput::default() }, |
| 249 | qp: preset.qp.or(base.qp), |
| 250 | keyframe_s: preset.keyframe_s.or(base.keyframe_s), |
| 251 | faststart: preset.faststart || base.faststart, |
| 252 | ..base |
| 253 | } |
| 254 | } |