mirror of
https://github.com/storytold/lightcraft.git
synced 2026-11-20 09:22:36 +01:00
fix(codecs): retain large AV1 frame support
This commit is contained in:
1 parent
e4411b2ea1
commit
2d13d97c6b
3 files changed
+29
-6
No files matched your search
Generated
+2
-1
@@ -1438,9 +1438,10 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "craft-video"
|
||||
version = "0.1.0"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=d6cd7836d364177661b0ae17f48a0805e83a5f32#d6cd7836d364177661b0ae17f48a0805e83a5f32"
|
||||
source = "git+https://github.com/storytold/craft-libs?rev=045d3865126d3408503c54fea71b08f33262fddf#045d3865126d3408503c54fea71b08f33262fddf"
|
||||
dependencies = [
|
||||
"craft-media",
|
||||
"rav1e",
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
|
||||
|
||||
+1
-1
@@ -21,7 +21,7 @@ jixel = "=0.3.4"
|
||||
# Photo metadata: EXIF, IPTC-IIM, XMP packets and GPX track logs (craft-libs#949)
|
||||
craft-metadata = { git = "https://github.com/storytold/craft-libs", rev = "f0f4758c01581d79577b9bf5046c06f4e77b1f18" }
|
||||
craft-image-codecs = { git = "https://github.com/storytold/craft-libs", rev = "d6cd7836d364177661b0ae17f48a0805e83a5f32" }
|
||||
craft-video = { git = "https://github.com/storytold/craft-libs", rev = "d6cd7836d364177661b0ae17f48a0805e83a5f32", features = ["av1"] }
|
||||
craft-video = { git = "https://github.com/storytold/craft-libs", rev = "045d3865126d3408503c54fea71b08f33262fddf", features = ["av1", "av1-large-encode"] }
|
||||
craft-xml = { git = "https://github.com/storytold/craft-libs", rev = "f0f4758c01581d79577b9bf5046c06f4e77b1f18" }
|
||||
# craft-update: app-specific pretend versions apply to startup and manual checks.
|
||||
craft-update = { git = "https://github.com/storytold/craft-libs", version = "=0.1.0", rev = "6e03f65bf45181db77ba6229716e6624db9eb25b", features = ["egui"] }
|
||||
|
||||
@@ -831,12 +831,18 @@ pub fn quantizer(quality: u8) -> usize {
|
||||
/// the samples as they come out (in order: no frame reordering).
|
||||
pub struct Av1Encoder {
|
||||
#[cfg(all(feature = "avif", not(target_arch = "wasm32")))]
|
||||
enc: craft_video::av1::Encoder,
|
||||
enc: Av1Backend,
|
||||
width: usize,
|
||||
height: usize,
|
||||
has_sample: bool,
|
||||
}
|
||||
|
||||
#[cfg(all(feature = "avif", not(target_arch = "wasm32")))]
|
||||
enum Av1Backend {
|
||||
Single(craft_video::av1::Encoder),
|
||||
Tiled(craft_video::av1::LargeEncoder),
|
||||
}
|
||||
|
||||
impl Av1Encoder {
|
||||
pub fn new(c: &VideoConfig) -> Result<Self> {
|
||||
let (w, h) = ((c.width & !1) as usize, (c.height & !1) as usize);
|
||||
@@ -850,7 +856,13 @@ impl Av1Encoder {
|
||||
let mut ec = EncoderConfig::new(w as u32, h as u32, c.fps, 1);
|
||||
ec.rate = RateControl::ConstantQ(quantizer(c.quality).clamp(1, 255) as u8);
|
||||
ec.keyint = 120;
|
||||
let enc = Encoder::new(ec).map_err(|e| bad(format!("AV1: {e}")))?;
|
||||
let sb_cols = w.div_ceil(64);
|
||||
let sb_rows = h.div_ceil(64);
|
||||
let enc = if w > 4096 || h > 4096 || sb_cols * sb_rows > 2304 {
|
||||
Av1Backend::Tiled(craft_video::av1::LargeEncoder::new(&ec).map_err(|e| bad(format!("AV1: {e}")))?)
|
||||
} else {
|
||||
Av1Backend::Single(Encoder::new(ec).map_err(|e| bad(format!("AV1: {e}")))?)
|
||||
};
|
||||
Ok(Av1Encoder { enc, width: w, height: h, has_sample: false })
|
||||
}
|
||||
#[cfg(not(all(feature = "avif", not(target_arch = "wasm32"))))]
|
||||
@@ -869,7 +881,13 @@ impl Av1Encoder {
|
||||
pub fn config_record(&self) -> Option<Vec<u8>> {
|
||||
#[cfg(all(feature = "avif", not(target_arch = "wasm32")))]
|
||||
{
|
||||
self.has_sample.then(|| self.enc.av1c())
|
||||
if !self.has_sample {
|
||||
return None;
|
||||
}
|
||||
match &self.enc {
|
||||
Av1Backend::Single(enc) => Some(enc.av1c()),
|
||||
Av1Backend::Tiled(enc) => enc.av1c(),
|
||||
}
|
||||
}
|
||||
#[cfg(not(all(feature = "avif", not(target_arch = "wasm32"))))]
|
||||
{
|
||||
@@ -889,7 +907,11 @@ impl Av1Encoder {
|
||||
let u16_: Vec<u16> = u.into_iter().map(u16::from).collect();
|
||||
let v16: Vec<u16> = v.into_iter().map(u16::from).collect();
|
||||
let frame = craft_video::av1::Frame { y: &y16, u: &u16_, v: &v16, y_stride: self.width, uv_stride: self.width / 2 };
|
||||
let pkt = self.enc.encode_with_key(&frame, key).map_err(|e| bad(format!("AV1: {e}")))?;
|
||||
let pkt = match &mut self.enc {
|
||||
Av1Backend::Single(enc) => enc.encode_with_key(&frame, key),
|
||||
Av1Backend::Tiled(enc) => enc.encode_with_key(&frame, key),
|
||||
}
|
||||
.map_err(|e| bad(format!("AV1: {e}")))?;
|
||||
self.has_sample = true;
|
||||
Ok(vec![Sample { data: pkt.data, key: pkt.keyframe, duration: periods.max(1) }])
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user