-
-
Notifications
You must be signed in to change notification settings - Fork 847
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
133 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
*.tgz | ||
assets | ||
public/assets |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,38 @@ | ||
const tar = require('tar'); | ||
const fs = require('fs'); | ||
const tar = require("tar"); | ||
const fs = require("fs"); | ||
|
||
const NPM_URL = 'https://registry.npmjs.org'; | ||
const NPM_URL = "https://registry.npmjs.org"; | ||
const ROOT = "public/assets"; | ||
|
||
const FFMPEG_VERSION = '0.12.2'; | ||
const UTIL_VERSION = '0.12.0'; | ||
const CORE_VERSION = '0.12.1'; | ||
const FFMPEG_VERSION = "0.12.2"; | ||
const UTIL_VERSION = "0.12.0"; | ||
const CORE_VERSION = "0.12.1"; | ||
|
||
const FFMPEG_TGZ = `ffmpeg-${FFMPEG_VERSION}.tgz`; | ||
const UTIL_TGZ = `util-${UTIL_VERSION}.tgz`; | ||
const CORE_TGZ = `core-${CORE_VERSION}.tgz`; | ||
const CORE_MT_TGZ = `core-mt-${CORE_VERSION}.tgz`; | ||
|
||
const FFMPEG_TGZ_URL = `${NPM_URL}/@ffmpeg/ffmpeg/-/${FFMPEG_TGZ}`; | ||
const UTIL_TGZ_URL = `${NPM_URL}/@ffmpeg/util/-/${UTIL_TGZ}`; | ||
const CORE_TGZ_URL = `${NPM_URL}/@ffmpeg/core/-/${CORE_TGZ}`; | ||
const CORE_MT_TGZ_URL = `${NPM_URL}/@ffmpeg/core-mt/-/${CORE_MT_TGZ}`; | ||
|
||
const mkdir = (dir) => { | ||
!fs.existsSync(dir) && fs.mkdirSync(dir); | ||
}; | ||
|
||
const downloadAndUntar = async (url, tgzName, dst) => { | ||
console.log(`download and untar ${url}`); | ||
fs.mkdirSync(dst); | ||
mkdir(`${ROOT}/${dst}`); | ||
const data = Buffer.from(await (await fetch(url)).arrayBuffer()); | ||
fs.writeFileSync(tgzName, data); | ||
|
||
await tar.x({ file: tgzName, C: dst }); | ||
await tar.x({ file: tgzName, C: `${ROOT}/${dst}` }); | ||
}; | ||
|
||
fs.mkdirSync('assets'); | ||
downloadAndUntar(FFMPEG_TGZ_URL, FFMPEG_TGZ, 'assets/ffmpeg'); | ||
downloadAndUntar(UTIL_TGZ_URL, UTIL_TGZ, 'assets/util'); | ||
downloadAndUntar(CORE_TGZ_URL, CORE_TGZ, 'assets/core'); | ||
mkdir(ROOT); | ||
downloadAndUntar(FFMPEG_TGZ_URL, FFMPEG_TGZ, "ffmpeg"); | ||
downloadAndUntar(UTIL_TGZ_URL, UTIL_TGZ, "util"); | ||
downloadAndUntar(CORE_TGZ_URL, CORE_TGZ, "core"); | ||
downloadAndUntar(CORE_MT_TGZ_URL, CORE_MT_TGZ, "core-mt"); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,11 +5,13 @@ | |
"private": true, | ||
"scripts": { | ||
"download": "node download-assets.js", | ||
"start": "npx http-server -c-1" | ||
"start": "node server.js" | ||
}, | ||
"author": "Jerome Wu <[email protected]>", | ||
"license": "MIT", | ||
"dependencies": { | ||
"express": "^4.18.2", | ||
"serve-index": "^1.9.1", | ||
"tar": "^6.1.15" | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<html> | ||
<head> | ||
<link rel="stylesheet" href="style.css"> | ||
<script src="/assets/ffmpeg/package/dist/umd/ffmpeg.js"></script> | ||
<script src="/assets/util/package/dist/umd/index.js"></script> | ||
</head> | ||
<body> | ||
<h3>Upload a video to transcode to mp4 (x264) and play!</h3> | ||
<video id="output-video" controls></video><br/> | ||
<input type="file" id="uploader"> | ||
<p id="message"></p> | ||
<script> | ||
const { fetchFile } = FFmpegUtil; | ||
const { FFmpeg } = FFmpegWASM; | ||
let ffmpeg = null; | ||
|
||
const transcode = async ({ target: { files } }) => { | ||
const message = document.getElementById('message'); | ||
if (ffmpeg === null) { | ||
ffmpeg = new FFmpeg(); | ||
ffmpeg.on("log", ({ message }) => { | ||
console.log(message); | ||
}) | ||
ffmpeg.on("progress", ({ progress, time }) => { | ||
message.innerHTML = `${progress * 100} %, time: ${time / 1000000} s`; | ||
}); | ||
await ffmpeg.load({ | ||
coreURL: "/assets/core-mt/package/dist/umd/ffmpeg-core.js", | ||
}); | ||
} | ||
const { name } = files[0]; | ||
await ffmpeg.writeFile(name, await fetchFile(files[0])); | ||
message.innerHTML = 'Start transcoding'; | ||
await ffmpeg.exec(['-i', name, 'output.mp4']); | ||
message.innerHTML = 'Complete transcoding'; | ||
const data = await ffmpeg.readFile('output.mp4'); | ||
|
||
const video = document.getElementById('output-video'); | ||
video.src = URL.createObjectURL(new Blob([data.buffer], { type: 'video/mp4' })); | ||
} | ||
const elm = document.getElementById('uploader'); | ||
elm.addEventListener('change', transcode); | ||
</script> | ||
</body> | ||
</html> |
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
const path = require("path"); | ||
const express = require("express"); | ||
const serveIndex = require("serve-index"); | ||
const app = express(); | ||
const PORT = 8080; | ||
const ROOT = path.join(__dirname, "public"); | ||
|
||
app.use((_, res, next) => { | ||
res.append("Cross-Origin-Opener-Policy", "same-origin"); | ||
res.append("Cross-Origin-Embedder-Policy", "require-corp"); | ||
next(); | ||
}); | ||
|
||
app.use(express.static(ROOT)); | ||
app.use("/", serveIndex(ROOT)); | ||
|
||
app.listen(PORT, () => { | ||
console.log(`Listening on port ${PORT}`); | ||
}); |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.