Skip to content

Commit

Permalink
Merge branch 'release/mp4-media-stream-2024.3.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
sile committed Dec 6, 2024
2 parents ffe95e0 + 9bd1f81 commit fdb7cbc
Show file tree
Hide file tree
Showing 9 changed files with 253 additions and 51 deletions.
15 changes: 15 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,21 @@

## develop

### misc

## mp4-media-stream-2024.3.0

- [ADD] `Mp4MediaStream` の対応コーデックに H.265 を追加する
- @sile
- [ADD] `Mp4MediaStream` の対応コーデックに AV1 を追加する
- @sile
- [ADD] `Mp4MediaStream` の対応コーデックに VP9 を追加する
- @sile
- [ADD] `Mp4MediaStream` の対応コーデックに VP8 を追加する
- @sile
- [ADD] `Mp4MediaStream` の対応コーデックに AAC を追加する
- @sile

## mp4-media-stream-2024.2.0

- [CHANGE] `Mp4MediaStream.play()` を非同期にする
Expand Down
38 changes: 19 additions & 19 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Please read <https://github.com/shiguredo/oss/blob/master/README.en.md> before u
- [@shiguredo/noise\-suppression \- npm](https://www.npmjs.com/package/@shiguredo/noise-suppression)
- [@shiguredo/light\-adjustment \- npm](https://www.npmjs.com/package/@shiguredo/light-adjustment)
- [@shiguredo/light\-adjustment\-gpu \- npm](https://www.npmjs.com/package/@shiguredo/light-adjustment-gpu)
- [@shiguredo/mp4\-media\-stream \- npm](https://www.npmjs.com/package/@shiguredo/mp4-media-stream)

## サンプル

Expand Down
13 changes: 12 additions & 1 deletion packages/mp4-media-stream/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,21 @@ video.srcObject = stream

本ライブラリは Chrome や Edge 等の Chromium ベースのブラウザで動作します。

## 対応コーデック

- 映像:
- H.264
- H.265
- VP8
- VP9
- AV1
- 音声:
- AAC
- Opus

## 未対応機能

以下の機能には現時点では対応していません:
- H.264 / Opus 以外のコーデックを含んだ MP4 の再生
- 再生開始位置の指定(シーク)
- 再生の一時停止・再開
- 数 GB を超える MP4 ファイルの再生
Expand Down
2 changes: 1 addition & 1 deletion packages/mp4-media-stream/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@shiguredo/mp4-media-stream",
"version": "2024.2.0",
"version": "2024.3.0",
"description": "Library to generate MediaStream from MP4 file",
"author": "Shiguredo Inc.",
"license": "Apache-2.0",
Expand Down
64 changes: 36 additions & 28 deletions packages/mp4-media-stream/src/mp4_media_stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,10 @@ class Mp4MediaStream {
// JSON.parse() の結果では config.description の型は number[] となって期待とは異なるので
// ここで適切な型に変換している
config.description = new Uint8Array(config.description as object as number[])
if (config.description.byteLength === 0) {
// コーデックによっては description が存在しないので空なら削除する
config.description = undefined
}

if (!(await VideoDecoder.isConfigSupported(config)).supported) {
throw new Error(`Unsupported video decoder configuration: ${JSON.stringify(config)}`)
Expand Down Expand Up @@ -238,22 +242,29 @@ class Mp4MediaStream {
// JSON.parse() の結果では config.description の型は number[] となって期待とは異なるので
// ここで適切な型に変換している
config.description = new Uint8Array(config.description as object as number[])
if (config.description.byteLength === 0) {
// コーデックによっては description が存在しないので空なら削除する
config.description = undefined
}

const init = {
output: async (frame: VideoFrame) => {
if (player.canvas === undefined || player.canvasCtx === undefined) {
return
}

try {
player.canvas.width = frame.displayWidth
player.canvas.height = frame.displayHeight
player.canvasCtx.drawImage(frame, 0, 0)
if (player.canvas === undefined || player.canvasCtx === undefined) {
return
}

try {
player.canvas.width = frame.displayWidth
player.canvas.height = frame.displayHeight
player.canvasCtx.drawImage(frame, 0, 0)
} catch (error) {
// エラーが発生した場合には再生を停止する
await this.stopPlayer(playerId)
throw error
}
} finally {
frame.close()
} catch (error) {
// エラーが発生した場合には再生を停止する
await this.stopPlayer(playerId)
throw error
}
},
error: async (error: DOMException) => {
Expand Down Expand Up @@ -286,27 +297,24 @@ class Mp4MediaStream {
const config = this.wasmJsonToValue(configWasmJson) as AudioDecoderConfig
const init = {
output: async (data: AudioData) => {
if (player.audioInputNode === undefined) {
return
}

try {
if (data.format !== 'f32') {
// フォーマットは f32 だけが来る想定。
// もし他のフォーマットが来ることがあれば、その都度対応すること。
throw Error(`Unsupported audio data format: ${data.format}"`)
if (player.audioInputNode === undefined) {
return
}

const samples = new Float32Array(data.numberOfFrames * data.numberOfChannels)
data.copyTo(samples, { planeIndex: 0 })
data.close()
try {
const samples = new Float32Array(data.numberOfFrames * data.numberOfChannels)
data.copyTo(samples, { planeIndex: 0, format: 'f32' })

const timestamp = data.timestamp
player.audioInputNode.port.postMessage({ timestamp, samples }, [samples.buffer])
} catch (e) {
// エラーが発生した場合には再生を停止する
await this.stopPlayer(playerId)
throw e
const timestamp = data.timestamp
player.audioInputNode.port.postMessage({ timestamp, samples }, [samples.buffer])
} catch (e) {
// エラーが発生した場合には再生を停止する
await this.stopPlayer(playerId)
throw e
}
} finally {
data.close()
}
},
error: async (error: DOMException) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/mp4-media-stream/wasm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ futures = "0.3.31"
orfail = { version = "1.1.0", features = ["serde"] }
serde = { version = "1.0.210", features = ["derive"] }
serde_json = "1.0.128"
shiguredo_mp4 = "2024.3.0"
shiguredo_mp4 = "2024.4.0"
Loading

0 comments on commit fdb7cbc

Please sign in to comment.