Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
SeaDve committed Feb 7, 2024
1 parent 04b246b commit 3ff63e8
Show file tree
Hide file tree
Showing 2 changed files with 176 additions and 0 deletions.
93 changes: 93 additions & 0 deletions data/resources/formats.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
formats:
- id: "webm"
name: "WebM"
file_extension: "webm"
video_encoder:
vp8enc:
max-quantizer: 17
cpu-used: 16
cq-level: 13
deadline: 1
static-threshold: 100
keyframe-mode: "disabled"
buffer-size: 20000
threads: ${N_THREADS}
audio_encoder: "opusenc"
container: "webmmux"

- id: "mp4"
name: "MP4"
file_extension: "mp4"
video_encoder:
x264enc:
qp-max: 17
speed-preset: "superfast"
threads: ${N_THREADS}
caps_fields:
profile: "baseline"
audio_encoder: "lamemp3enc"
container: "mp4mux"

- id: "matroska-x264"
name: "Matroska (x264)"
file_extension: "mkv"
video_encoder:
x264enc:
qp-max: 17
speed-preset: "superfast"
threads: ${N_THREADS}
caps_fields:
profile: "baseline"
audio_encoder: "opusenc"
container: "matroskamux"

experimental_formats:
- id: "webm-vp9"
name: "WebM (VP9)"
file_extension: "webm"
video_encoder:
vp9enc:
max-quantizer: 17
cpu-used: 16
cq-level: 13
deadline: 1
static-threshold:
keyframe-mode: "disabled"
buffer-size: 20000
threads: ${N_THREADS}
audio_encoder: "opusenc"
container: "webmmux"

- id: "webm-av1"
name: "WebM (AV1)"
file_extension: "webm"
video_encoder:
av1enc:
max-quantizer: 17
cpu-used: 5
end-usage: "cq"
buf-sz: 20000
threads: ${N_THREADS}
audio_encoder: "opusenc"
container: "webmmux"

- id: "vaapi-vp8"
name: "WebM VAAPI VP8"
file_extension: "mkv"
video_encoder: "vaapivp8enc"
audio_encoder: "opusenc"
container: "webmmux"

- id: "vaapi-vp9"
name: "WebM VAAPI VP9"
file_extension: "mkv"
video_encoder: "vaapivp9enc"
audio_encoder: "opusenc"
container: "webmmux"

- id: "vaapi-h264"
name: "WebM VAAPI H264"
file_extension: "mkv"
video_encoder: "vaapih264enc"
audio_encoder: "lamemp3enc"
container: "mp4mux"
83 changes: 83 additions & 0 deletions src/formats.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
use std::collections::HashMap;

use anyhow::{bail, Context, Result};
use gtk::{gio, glib};
use serde::Deserialize;
use serde_yaml::Value;

#[derive(Debug, Deserialize)]
struct Document {
formats: Vec<Format>,
experimental_formats: Vec<Format>,
}

#[derive(Debug, Deserialize)]
struct Format {
id: String,
name: String,
file_extension: String,
video_encoder: Value,
audio_encoder: Value,
container: Value,
}

struct Element {
name: String,
properties: HashMap<String, glib::SendValue>,
caps_field: HashMap<String, glib::SendValue>,
}

impl Element {
fn from_value(value: Value) -> Result<Self> {
match value {
Value::String(name) => Ok(Self {
name,
properties: HashMap::new(),
caps_field: HashMap::new(),
}),
Value::Mapping(mut mapping) => {
// Remove caps_field first.
let caps_field = match mapping.remove("caps_fields") {
Some(Value::Mapping(caps_field)) => caps_field
.into_iter()
.map(|(k, v)| {
match k {
Value::String(k) => Ok((k, v)),
_ => bail!("Invalid caps_field key"),
}
Ok(())
})
.collect::<Result<HashMap<_, _>>>()?,
None => HashMap::new(),
_ => bail!("Invalid caps_field value"),
};

let (name, properties) = mapping.into_iter().next().context("No name found")?;

let name = match name {
Value::String(name) => name,
_ => bail!("Invalid name value"),
};

let properties = match properties {
Value::Mapping(properties) => properties,
_ => bail!("Invalid properties value"),
};

todo!()
}
_ => bail!("Invalid encoder value"),
}
}
}

pub fn get() -> Result<()> {
let data = gio::resources_lookup_data(
"/io/github/seadve/Kooha/formats.yml",
gio::ResourceLookupFlags::NONE,
)?;

dbg!(serde_yaml::from_slice::<Document>(&data).unwrap());

Ok(())
}

0 comments on commit 3ff63e8

Please sign in to comment.