diff --git a/CHANGES.md b/CHANGES.md index cb62c440..28b00780 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -11,6 +11,8 @@ ## develop +- [ADD] `Mp4MediaStream` の対応コーデックに AV1 を追加する + - @sile - [ADD] `Mp4MediaStream` の対応コーデックに VP9 を追加する - @sile - [ADD] `Mp4MediaStream` の対応コーデックに VP8 を追加する diff --git a/packages/mp4-media-stream/README.md b/packages/mp4-media-stream/README.md index ed8c009b..681b567e 100644 --- a/packages/mp4-media-stream/README.md +++ b/packages/mp4-media-stream/README.md @@ -34,6 +34,7 @@ video.srcObject = stream - H.264 - VP8 - VP9 + - AV1 - 音声: - AAC - Opus diff --git a/packages/mp4-media-stream/wasm/src/mp4.rs b/packages/mp4-media-stream/wasm/src/mp4.rs index 4ca941e8..9867d3dd 100644 --- a/packages/mp4-media-stream/wasm/src/mp4.rs +++ b/packages/mp4-media-stream/wasm/src/mp4.rs @@ -5,8 +5,8 @@ use serde::Serialize; use shiguredo_mp4::{ aux::SampleTableAccessor, boxes::{ - Avc1Box, FtypBox, HdlrBox, IgnoredBox, MoovBox, Mp4aBox, OpusBox, SampleEntry, StblBox, - TrakBox, Vp08Box, Vp09Box, + Av01Box, Avc1Box, FtypBox, HdlrBox, IgnoredBox, MoovBox, Mp4aBox, OpusBox, SampleEntry, + StblBox, TrakBox, Vp08Box, Vp09Box, }, BaseBox, Decode, Either, Encode, }; @@ -61,6 +61,35 @@ impl VideoDecoderConfig { coded_height: b.visual.height, } } + + pub fn from_av01_box(b: &Av01Box) -> Self { + Self { + // https://aomediacodec.github.io/av1-isobmff/#codecsparam + codec: format!( + "av01.{}.{:02}{}.{:02}", + b.av1c_box.seq_profile.get(), + b.av1c_box.seq_level_idx_0.get(), + if b.av1c_box.seq_tier_0.get() == 0 { + 'M' + } else { + 'H' + }, + match ( + b.av1c_box.seq_profile.get(), + b.av1c_box.high_bitdepth.get(), + b.av1c_box.twelve_bit.get() + ) { + (2, 1, 1) => 12, + (2, 1, 0) => 10, + (_, 1, _) => 10, + (_, _, _) => 8, + } + ), + description: Vec::new(), + coded_width: b.visual.width, + coded_height: b.visual.height, + } + } } #[derive(Debug, Serialize)] @@ -136,6 +165,7 @@ impl Track { Some(SampleEntry::Avc1(_)) => (), Some(SampleEntry::Vp08(_)) => (), Some(SampleEntry::Vp09(_)) => (), + Some(SampleEntry::Av01(_)) => (), Some(SampleEntry::Opus(_)) => (), Some(SampleEntry::Mp4a(_)) => (), Some(b) => { @@ -232,6 +262,9 @@ impl Mp4 { SampleEntry::Vp09(b) => { video_configs.push(VideoDecoderConfig::from_vp09_box(b)); } + SampleEntry::Av01(b) => { + video_configs.push(VideoDecoderConfig::from_av01_box(b)); + } SampleEntry::Opus(b) => { audio_configs.push(AudioDecoderConfig::from_opus_box(b)); } diff --git a/packages/mp4-media-stream/wasm/src/player.rs b/packages/mp4-media-stream/wasm/src/player.rs index 3e103076..10728463 100644 --- a/packages/mp4-media-stream/wasm/src/player.rs +++ b/packages/mp4-media-stream/wasm/src/player.rs @@ -188,6 +188,10 @@ impl TrackPlayer { let config = VideoDecoderConfig::from_vp09_box(b); WasmApi::create_video_decoder(self.player_id, config).await } + SampleEntry::Av01(b) => { + let config = VideoDecoderConfig::from_av01_box(b); + WasmApi::create_video_decoder(self.player_id, config).await + } SampleEntry::Opus(b) => { let config = AudioDecoderConfig::from_opus_box(b); WasmApi::create_audio_decoder(self.player_id, config).await