diff --git a/Cargo.lock b/Cargo.lock index b012bda16..bb1d89cf1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1875,9 +1875,6 @@ dependencies = [ "effectcraft-render", "effectcraft-time", "exr", - "filmcraft-av1", - "filmcraft-hevc", - "filmcraft-vp9", "gif", "image", "log", @@ -2050,7 +2047,6 @@ dependencies = [ "filmcraft-color", "filmcraft-frame", "filmcraft-media", - "filmcraft-mpegts", "filmcraft-time", "gif", "image", diff --git a/Cargo.toml b/Cargo.toml index af6b39861..21f47439c 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -103,13 +103,6 @@ filmcraft-media = { git = "https://github.com/storytold/filmcraft", rev = "d5ead filmcraft-frame = { git = "https://github.com/storytold/filmcraft", rev = "d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" } filmcraft-color = { git = "https://github.com/storytold/filmcraft", rev = "d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" } filmcraft-time = { git = "https://github.com/storytold/filmcraft", rev = "d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" } -# MPEG TS / PS headers read for AAC channel layouts (crates/media); craft-media has no MPEG TS reader -filmcraft-mpegts = { git = "https://github.com/storytold/filmcraft", rev = "d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" } -# decoders used as the round-trip oracles of craft-video's VP9, HEVC and AV1 encoders (crates/export -# dev-dependencies only); craft-video has no decoder for them -filmcraft-vp9 = { git = "https://github.com/storytold/filmcraft", rev = "d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" } -filmcraft-hevc = { git = "https://github.com/storytold/filmcraft", rev = "d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" } -filmcraft-av1 = { git = "https://github.com/storytold/filmcraft", rev = "d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" } # timeline interchange (EDL, FCP7 XML, FCPXML, OTIO) for Premiere Pro interop (crates/interchange only) filmcraft-interchange = { git = "https://github.com/storytold/filmcraft", rev = "d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" } filmcraft-project = { git = "https://github.com/storytold/filmcraft", rev = "d5ead4ba1ee2f1cd13cb86a4239aee2730a3d9f5" } @@ -144,7 +137,6 @@ sys-locale = "0.3" # filmcraft-frame = { path = "../filmcraft/crates/frame" } # filmcraft-color = { path = "../filmcraft/crates/color" } # filmcraft-time = { path = "../filmcraft/crates/time" } -# filmcraft-mpegts = { path = "../filmcraft/crates/mpegts" } [workspace.lints.rust] unsafe_code = "forbid" diff --git a/crates/export/Cargo.toml b/crates/export/Cargo.toml index c84efc6ee..1bf883df3 100644 --- a/crates/export/Cargo.toml +++ b/crates/export/Cargo.toml @@ -31,7 +31,6 @@ tempfile = { workspace = true } effectcraft-media = { workspace = true } effectcraft-effects = { workspace = true } effectcraft-color = { workspace = true } -filmcraft-hevc = { workspace = true } -filmcraft-av1 = { workspace = true } -filmcraft-vp9 = { workspace = true } +# The decoders that check the VP9, HEVC and AV1 encoders round-trip (av1 is already on). +craft-video = { workspace = true, features = ["vp9-decode", "hevc-decode"] } effectcraft-keyframe = { workspace = true } diff --git a/crates/export/tests/it/av1_encoder/common.rs b/crates/export/tests/it/av1_encoder/common.rs index 3cd42a584..7e78adda6 100644 --- a/crates/export/tests/it/av1_encoder/common.rs +++ b/crates/export/tests/it/av1_encoder/common.rs @@ -86,13 +86,13 @@ pub struct Run { pub lf_levels: Vec, } -/// Encodes `pics`, checks every packet decodes (filmcraft-av1) to exactly the encoder's +/// Encodes `pics`, checks every packet decodes (craft-video's AV1 decoder) to exactly the encoder's /// reconstruction and returns packets, reconstructions and luma PSNRs. pub fn encode_and_check(cfg: EncoderConfig, pics: &[Pic]) -> Run { let bd = cfg.bit_depth as u32; let mut enc = Encoder::new(cfg).expect("config"); // single-threaded: each packet's picture comes out of its own decode call - let mut dec = filmcraft_av1::Decoder::with_threads(1); + let mut dec = craft_video::av1::decode::Decoder::with_threads(1); let mut run = Run { packets: Vec::new(), recons: Vec::new(), psnr_y: Vec::new(), lf_levels: Vec::new() }; for (i, p) in pics.iter().enumerate() { let pkt = enc.encode(&p.frame()).expect("encode"); diff --git a/crates/export/tests/it/av1_encoder/mod.rs b/crates/export/tests/it/av1_encoder/mod.rs index d33ea0c55..be7476d43 100644 --- a/crates/export/tests/it/av1_encoder/mod.rs +++ b/crates/export/tests/it/av1_encoder/mod.rs @@ -1,4 +1,4 @@ -//! craft-video's AV1 encoder against the filmcraft-av1 decoder and ffmpeg's libdav1d. +//! craft-video's AV1 encoder against craft-video's AV1 decoder and ffmpeg's libdav1d. mod bench; mod common; diff --git a/crates/export/tests/it/hevc_encoder.rs b/crates/export/tests/it/hevc_encoder.rs index c19ff9cbd..383183ec0 100644 --- a/crates/export/tests/it/hevc_encoder.rs +++ b/crates/export/tests/it/hevc_encoder.rs @@ -1,4 +1,4 @@ -//! Round trips through the filmcraft-hevc decoder and (when installed) ffmpeg: decoded pictures must +//! Round trips through the craft-video HEVC decoder and (when installed) ffmpeg: decoded pictures must //! equal the encoder's own reconstruction bit-exactly. use craft_video::hevc::{Encoder, EncoderConfig, Frame, Profile, RateControl}; @@ -84,9 +84,9 @@ fn encode(cfg: EncoderConfig, pics: &[Pic]) -> Run { run } -/// Decode with filmcraft-hevc and compare with the reconstructions. -fn check_filmcraft(run: &Run, w: usize, h: usize) { - let mut dec = filmcraft_hevc::Decoder::from_hvcc(&run.hvcc).unwrap(); +/// Decode with craft-video's HEVC decoder and compare with the reconstructions. +fn check_decoder(run: &Run, w: usize, h: usize) { + let mut dec = craft_video::hevc::decode::Decoder::from_hvcc(&run.hvcc).unwrap(); let mut pics = Vec::new(); for (i, p) in run.packets.iter().enumerate() { pics.extend(dec.decode(p, i as i64).unwrap()); @@ -211,7 +211,7 @@ fn intra_8bit_quality_and_decoders() { let run = encode(cfg(w as u32, h as u32, 22, 1, Profile::Main), &pics); eprintln!("intra QP22: {} bytes, PSNR-Y {:.2}", run.packets[0].len(), run.psnr_y[0]); assert!(run.psnr_y[0] > 35.0, "PSNR {}", run.psnr_y[0]); - check_filmcraft(&run, w, h); + check_decoder(&run, w, h); check_ffmpeg(&run, w, h, 8, "intra8"); } @@ -267,7 +267,7 @@ fn inter_8bit_moving_pattern() { let p_avg = sizes[1..].iter().sum::() as f64 / 5.0; assert!(p_avg < sizes[0] as f64 * 0.6, "P frames {p_avg} vs I {}", sizes[0]); assert!(run.psnr_y.iter().all(|&p| p > 33.0)); - check_filmcraft(&run, w, h); + check_decoder(&run, w, h); check_ffmpeg(&run, w, h, 8, "inter8"); } @@ -276,7 +276,7 @@ fn odd_multiple_sizes_and_cropping() { for (w, h) in [(34usize, 18usize), (66, 38), (8, 8), (130, 72), (2, 2), (2, 70), (264, 6)] { let pics: Vec = (0..3).map(|i| synth(w, h, 8, i, 2 * i)).collect(); let run = encode(cfg(w as u32, h as u32, 30, 2, Profile::Main), &pics); - check_filmcraft(&run, w, h); + check_decoder(&run, w, h); check_ffmpeg(&run, w, h, 8, &format!("size{w}x{h}")); } } @@ -305,7 +305,7 @@ fn noise_low_qp() { .collect(); let run = encode(cfg(w as u32, h as u32, 0, 2, profile), &pics); assert!(run.psnr_y.iter().all(|&p| p > 45.0), "{:?}", run.psnr_y); - check_filmcraft(&run, w, h); + check_decoder(&run, w, h); check_ffmpeg(&run, w, h, bd, &format!("noise{bd}")); } } @@ -317,7 +317,7 @@ fn high_qp_deblocking() { for (qp, profile, bd) in [(38u8, Profile::Main, 8u32), (44, Profile::Main, 8), (37, Profile::Main10, 10)] { let pics: Vec = (0..5).map(|i| synth(w, h, bd, 2 * i, i)).collect(); let run = encode(cfg(w as u32, h as u32, qp, 4, profile), &pics); - check_filmcraft(&run, w, h); + check_decoder(&run, w, h); check_ffmpeg(&run, w, h, bd, &format!("hq{qp}")); } } @@ -329,7 +329,7 @@ fn long_gop_poc_wrap() { let pics: Vec = (0..300).map(|i| synth(w, h, 8, i % 7, i % 5)).collect(); let run = encode(cfg(w as u32, h as u32, 30, 0, Profile::Main), &pics); assert_eq!(run.keys.iter().filter(|&&k| k).count(), 1); - check_filmcraft(&run, w, h); + check_decoder(&run, w, h); check_ffmpeg(&run, w, h, 8, "pocwrap"); let run = encode(cfg(w as u32, h as u32, 30, 260, Profile::Main), &pics); assert_eq!(run.keys.iter().filter(|&&k| k).count(), 2); @@ -348,7 +348,7 @@ fn main10_round_trip() { let run = encode(cfg(w as u32, h as u32, 24, 3, Profile::Main10), &pics); eprintln!("main10 psnr {:?}", run.psnr_y); assert!(run.psnr_y[0] > 35.0); - check_filmcraft(&run, w, h); + check_decoder(&run, w, h); check_ffmpeg(&run, w, h, 10, "main10"); } @@ -358,7 +358,7 @@ fn qp_extremes() { for qp in [0u8, 51] { let pics: Vec = (0..2).map(|i| synth(w, h, 8, i, i)).collect(); let run = encode(cfg(w as u32, h as u32, qp, 30, Profile::Main), &pics); - check_filmcraft(&run, w, h); + check_decoder(&run, w, h); check_ffmpeg(&run, w, h, 8, &format!("qp{qp}")); } } @@ -375,7 +375,7 @@ fn bitrate_mode_hits_target() { let kbps = bits as f64 / (pics.len() as f64 / 30.0) / 1000.0; eprintln!("bitrate mode: {kbps:.1} kbit/s for a 400 kbit/s target"); assert!(kbps > 400.0 / 2.0 && kbps < 400.0 * 2.0, "{kbps}"); - check_filmcraft(&run, w, h); + check_decoder(&run, w, h); } #[test] diff --git a/crates/export/tests/it/vp9_roundtrip.rs b/crates/export/tests/it/vp9_roundtrip.rs index f9d36770d..cb6fbfa0c 100644 --- a/crates/export/tests/it/vp9_roundtrip.rs +++ b/crates/export/tests/it/vp9_roundtrip.rs @@ -1,8 +1,8 @@ -//! The VP9 intra encoder (`craft_video::vp9`) round-trips through FilmCraft's VP9 decoder (and +//! The VP9 intra encoder (`craft_video::vp9`) round-trips through craft-video's VP9 decoder (and //! ffmpeg as an external oracle when installed): sizes, lossless exactness, PSNR. +use craft_video::vp9::decode::{Decoder, Picture, Plane}; use craft_video::vp9::{EncoderConfig, Vp9Encoder}; -use filmcraft_vp9::{Decoder, Plane}; fn plane_u8(p: &Plane) -> Vec { match p { @@ -40,7 +40,7 @@ fn source(w: usize, h: usize, kind: u32) -> (Vec, Vec, Vec) { (y, u, v) } -fn decode(frame: &[u8]) -> filmcraft_vp9::Picture { +fn decode(frame: &[u8]) -> Picture { let mut d = Decoder::with_threads(1); let mut pics = d.decode(frame, 0).expect("decode"); assert_eq!(pics.len(), 1); @@ -179,7 +179,7 @@ fn moving(w: usize, h: usize, t: usize, kind: u32) -> (Vec, Vec, Vec (y, u, v) } -fn planes_of(p: &filmcraft_vp9::Picture, w: usize, h: usize) -> [Vec; 3] { +fn planes_of(p: &Picture, w: usize, h: usize) -> [Vec; 3] { let (cw, ch) = (w.div_ceil(2), h.div_ceil(2)); [crop(&plane_u8(&p.y), p.y_stride, w, h), crop(&plane_u8(&p.u), p.uv_stride, cw, ch), crop(&plane_u8(&p.v), p.uv_stride, cw, ch)] } diff --git a/crates/media/Cargo.toml b/crates/media/Cargo.toml index c236cf294..ff98229cb 100644 --- a/crates/media/Cargo.toml +++ b/crates/media/Cargo.toml @@ -26,9 +26,8 @@ craft-dpx = { workspace = true } craft-exr = { workspace = true, features = ["decode"] } craft-gif = { workspace = true, features = ["frames"] } craft-webp = { workspace = true, features = ["frames"] } -craft-audio = { workspace = true } -craft-media = { workspace = true } -filmcraft-mpegts = { workspace = true } +craft-audio = { workspace = true, features = ["aac-decode"] } +craft-media = { workspace = true, features = ["mpegts"] } filmcraft-frame = { workspace = true } filmcraft-color = { workspace = true } filmcraft-time = { workspace = true } diff --git a/crates/media/src/aac.rs b/crates/media/src/aac.rs index a1793b7af..356a8dff5 100644 --- a/crates/media/src/aac.rs +++ b/crates/media/src/aac.rs @@ -62,15 +62,15 @@ fn matroska(file: &dyn ByteReader) -> Option> { /// first unit it can read. Only AAC is asked about, so the streams before that one were refused /// whatever their codec, and an ADTS stream played has no configuration outside its frames. fn latm(file: &dyn ByteReader) -> Option> { - use filmcraft_mpegts::Codec; + use craft_media::mpegts::{self, Codec}; let head = Head(file, file.len().min(MPEG_HEAD)); - let mpeg = filmcraft_mpegts::open(&head).ok()?; - let audio = mpeg.streams.iter().enumerate().filter(|(_, s)| s.kind() == filmcraft_mpegts::Kind::Audio && !s.units.is_empty()); + let mpeg = mpegts::open(&head).ok()?; + let audio = mpeg.streams.iter().enumerate().filter(|(_, s)| s.kind() == mpegts::Kind::Audio && !s.units.is_empty()); let played = audio.take(filmcraft_media::MAX_AUDIO_STREAMS).find_map(|(i, s)| { let first = mpeg.read_unit(&head, i, 0).ok()?; match s.codec { - Codec::AacAdts => filmcraft_mpegts::frame_info(&s.codec, &first).map(|_| None), - Codec::AacLatm => filmcraft_codecs::audio::latm_config(&first).map(|c| Some(c.asc)), + Codec::AacAdts => mpegts::frame_info(&s.codec, &first).map(|_| None), + Codec::AacLatm => craft_audio::aac::latm_config(&first).map(|c| Some(c.asc)), _ => None, } }); @@ -97,12 +97,3 @@ impl craft_media::ByteSource for Head<'_> { self.read(offset, buf) } } - -impl filmcraft_mpegts::ByteSource for Head<'_> { - fn len(&self) -> u64 { - self.1 - } - fn read_at(&self, offset: u64, buf: &mut [u8]) -> io::Result<()> { - self.read(offset, buf) - } -}