Skip to content

Commit

Permalink
Merge pull request #489 from shiguredo/feature/mp4-media-stream-vite
Browse files Browse the repository at this point in the history
MP4 から MediaStream を作成するためのパッケージを追加する
  • Loading branch information
sile authored Oct 16, 2024
2 parents 95386d6 + f09464a commit a37d597
Show file tree
Hide file tree
Showing 22 changed files with 1,829 additions and 3 deletions.
1 change: 1 addition & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
with:
version: 0.12.0
- run: zig version
- run: rustup update stable && rustup target add wasm32-unknown-unknown
- uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,6 @@ yarn.lock

# Ignore typedoc output
apidoc/

# Rust
/target/
230 changes: 230 additions & 0 deletions Cargo.lock

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

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[workspace]
members = ["packages/mp4-media-stream/wasm/"]
resolver = "2"
3 changes: 2 additions & 1 deletion examples/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@
<li><a href="./light-adjustment/">ライト調整サンプル</a></li>
<li><a href="./light-adjustment-gpu/">ライト調整GPUサンプル</a></li>
<li><a href="./noise-suppression/">ノイズ抑制サンプル</a></li>
<li><a href="./mp4-media-stream/">MP4 メディアストリームサンプル</a></li>
</ul>
</div>
</body>

</html>
</html>
26 changes: 26 additions & 0 deletions examples/mp4-media-stream/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<html>
<head>
<meta charset="utf-8">
<title>Media Processors: MP4 メディアストリームサンプル</title>
</head>
<body>
<h1>Media Processors: MP4 メディアストリームサンプル</h1>

<h3>入力 MP4 ファイル</h3>
ファイル選択後に「再生開始」ボタンを押してください。
<br /><br />
<input id="input" type="file" accept="video/mp4" />
<br /><br />
<input id="play" type="button" value="再生開始" />
<input id="stop" type="button" value="再生停止" />

<br /><br />
<input id="repeat" type="checkbox"> リピート再生を有効にする
<br />

<h3>出力映像</h3>
<video id="output" autoplay playsinline></video>

<script type="module" src="./main.mts"></script>
</body>
</html>
57 changes: 57 additions & 0 deletions examples/mp4-media-stream/main.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { Mp4MediaStream } from '@shiguredo/mp4-media-stream'

document.addEventListener('DOMContentLoaded', async () => {
let mp4MediaStream

if (!Mp4MediaStream.isSupported()) {
alert('Unsupported platform')
throw Error('Unsupported platform')
}

async function load() {
const input = document.getElementById('input')
const files = input.files
if (files === null || files.length === 0) {
return
}
const file = files[0]

if (mp4MediaStream !== undefined) {
await mp4MediaStream.stop()
}

try {
mp4MediaStream = await Mp4MediaStream.load(file)
} catch (e) {
alert(e.message)
throw e
}
}

function play() {
if (mp4MediaStream === undefined) {
alert('MP4 ファイルが未選択です')
return
}

const options = {
repeat: document.getElementById('repeat').checked,
}
const stream = mp4MediaStream.play(options)

const output = document.getElementById('output')
output.srcObject = stream
}

async function stop() {
if (mp4MediaStream === undefined) {
return
}

await mp4MediaStream.stop()
}

document.getElementById('input').addEventListener('change', load)
document.getElementById('play').addEventListener('click', play)
document.getElementById('stop').addEventListener('click', stop)
})
5 changes: 3 additions & 2 deletions examples/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
"@shiguredo/light-adjustment": "workspace:*",
"@shiguredo/light-adjustment-gpu": "workspace:*",
"@shiguredo/noise-suppression": "workspace:*",
"@shiguredo/virtual-background": "workspace:*"
"@shiguredo/virtual-background": "workspace:*",
"@shiguredo/mp4-media-stream": "workspace:*"
},
"devDependencies": {
"vite-plugin-static-copy": "1.0.6"
}
}
}
6 changes: 6 additions & 0 deletions examples/vite.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ export default defineConfig({
__dirname,
'../packages/light-adjustment-gpu/dist/light_adjustment_gpu.mjs',
),
'@shiguredo/mp4-media-stream': resolve(
__dirname,
'../packages/mp4-media-stream/dist/mp4_media_stream.mjs',
),
},
},
optimizeDeps: {
Expand All @@ -32,6 +36,7 @@ export default defineConfig({
'@shiguredo/noise-suppression',
'@shiguredo/light-adjustment',
'@shiguredo/light-adjustment-gpu',
'@shiguredo/mp4-media-stream',
],
},
build: {
Expand All @@ -44,6 +49,7 @@ export default defineConfig({
noiseSuppression: resolve(__dirname, 'noise-suppression/index.html'),
videoMultiProcessors: resolve(__dirname, 'video-multi-processors/index.html'),
videoMultiProcessorsGpu: resolve(__dirname, 'video-multi-processors-gpu/index.html'),
mp4MediaStream: resolve(__dirname, 'mp4-media-stream/index.html'),
},
},
},
Expand Down
Loading

0 comments on commit a37d597

Please sign in to comment.