Skip to content

Commit

Permalink
Merge pull request #510 from shiguredo/feature/mp4-media-stream-av1
Browse files Browse the repository at this point in the history
`Mp4MediaStream` の対応コーデックに AV1 を追加する
  • Loading branch information
sile authored Dec 6, 2024
2 parents b749217 + e54e3fe commit 471a422
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

## develop

- [ADD] `Mp4MediaStream` の対応コーデックに AV1 を追加する
- @sile
- [ADD] `Mp4MediaStream` の対応コーデックに VP9 を追加する
- @sile
- [ADD] `Mp4MediaStream` の対応コーデックに VP8 を追加する
Expand Down
1 change: 1 addition & 0 deletions packages/mp4-media-stream/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ video.srcObject = stream
- H.264
- VP8
- VP9
- AV1
- 音声:
- AAC
- Opus
Expand Down
37 changes: 35 additions & 2 deletions packages/mp4-media-stream/wasm/src/mp4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -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)]
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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));
}
Expand Down
4 changes: 4 additions & 0 deletions packages/mp4-media-stream/wasm/src/player.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 471a422

Please sign in to comment.