-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from TUS-OSK/hls
HLS
- Loading branch information
Showing
11 changed files
with
226 additions
and
276 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 |
---|---|---|
|
@@ -43,8 +43,10 @@ ngrok で得られる URL はは変動するので,[API Gateway](https://aws.a | |
│ └─ GET | ||
├─ /oauth-redirect | ||
│ └─ GET | ||
├─ /photo | ||
│ └─ GET | ||
├─ /stream | ||
│ ├─ GET | ||
│ └ /{file+} | ||
│ └─ GET | ||
└─ /viewer | ||
└─ GET | ||
``` | ||
|
@@ -135,24 +137,31 @@ ffmpeg \ | |
-i /dev/video0 \ | ||
-vcodec libx264 \ | ||
-preset veryfast \ | ||
-tune zerolatency \ | ||
-b 8M \ | ||
-vf "drawtext=fontfile=/usr/share/fonts/dejavu/DejaVuSans-Bold.ttf: \ | ||
text='%{localtime\:%T}': [email protected]: x=7: y=700" \ | ||
-f flv rtmp://localhost/live/stream; | ||
-hls_flags delete_segments \ | ||
-g 20 \ | ||
-f hls [Directory of ramdisk]/output.m3u8 | ||
``` | ||
|
||
**Use USB Camera on macOS** | ||
|
||
```bash= | ||
ffmpeg \ | ||
-f avfoundation \ | ||
-framerate 5 \ | ||
-i 0 \ | ||
-framerate 30 \ | ||
-re -i 0 \ | ||
-r 5 \ | ||
-vcodec libx264 \ | ||
-preset veryfast \ | ||
-tune zerolatency \ | ||
-vf "drawtext=fontfile=/usr/share/fonts/dejavu/DejaVuSans-Bold.ttf: \ | ||
text='%{localtime\:%T}': [email protected]: x=7: y=700" \ | ||
-f flv rtmp://localhost/live/stream | ||
-hls_flags delete_segments \ | ||
-g 20 \ | ||
-f hls [Directory of ramdisk]/output.m3u8 | ||
``` | ||
|
||
## Usage | ||
|
@@ -171,8 +180,6 @@ Remote URL: https://[AWS_REST_API_ID].execute-api.[REGION].amazonaws.com/prod | |
|
||
とあります。それに`/viewer`を付け加えた`https://[AWS_REST_API_ID].execute-api.[REGION].amazonaws.com/prod/viewer`を開いてください。 | ||
|
||
対応していないブラウザ,または`https://[AWS_REST_API_ID].execute-api.[REGION].amazonaws.com/prod/viewer?photo=force`へのアクセスでは,動画ではなく画像が表示されます。 | ||
|
||
> この AWS の URL は半永久的に変わりません | ||
すると,初回実行時(過去に Slack で認証をしていなければ) Slack の認証ページへリダイレクトされます。 | ||
|
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,60 +1,31 @@ | ||
const childProcess = require('child_process'); | ||
const util = require('util'); | ||
const ngrok = require('./ngrok'); | ||
const Server = require('./server'); | ||
const MediaServer = require('./mediaServer'); | ||
const aws = require('./aws'); | ||
|
||
const exec = util.promisify(childProcess.exec); | ||
const Stream = require('./stream'); | ||
|
||
const config = { | ||
restApiId: process.env.AWS_REST_API_ID, | ||
viewerResourceId: process.env.VIEWER_RESOURCE_ID, | ||
oauthResourceId: process.env.OAUTH_RESOURCE_ID, | ||
httpMethod: 'GET', | ||
slackClientId: process.env.SLACK_CLIENT_ID, | ||
slackClientSecret: process.env.SLACK_CLIENT_SECRET, | ||
wsId: process.env.WORKSTATION_ID, | ||
privateKey: process.env.LIVE_PRIVATE_KEY, | ||
}; | ||
|
||
new MediaServer(process.env.LIVE_PRIVATE_KEY).run(); | ||
|
||
const deamon = async (command) => { | ||
// eslint-disable-next-line no-constant-condition | ||
while (true) { | ||
try { | ||
// eslint-disable-next-line no-await-in-loop | ||
await exec(command); | ||
} catch (e) { | ||
console.error(e); | ||
} | ||
} | ||
}; | ||
|
||
deamon( | ||
// eslint-disable-next-line no-useless-escape | ||
'ffmpeg -framerate 5 -video_size 960x720 -i /dev/video0 -vcodec libx264 -preset veryfast -b 8M -vf "drawtext=fontfile=/usr/share/fonts/dejavu/DejaVuSans-Bold.ttf: text="%{localtime:%T}": [email protected]: x=7: y=700" -f flv rtmp://localhost/live/stream', | ||
); | ||
deamon('ffmpeg -y -i rtmp://localhost/live/stream -r 0.1 -f image2 -updatefirst 1 capture.jpg'); | ||
|
||
ngrok | ||
.run(process.env.NGROK_TOKEN) | ||
.then((urls) => { | ||
const { siteUrl, liveUrl } = urls; | ||
aws | ||
.run(config, siteUrl) | ||
.then((url) => { | ||
console.log(`Remote URL: ${url}`); | ||
}) | ||
.catch(e => console.error(e)); | ||
const disk = new Stream('bushitsuchan'); | ||
disk | ||
.run() | ||
.then(async (mountPath) => { | ||
const ngrokUrl = await ngrok.run(process.env.NGROK_TOKEN); | ||
const awsUrl = await aws.run(config, ngrokUrl); | ||
// console.log(`Remote URL: ${awsUrl}`); | ||
|
||
return new Server( | ||
siteUrl, | ||
liveUrl, | ||
process.env.SLACK_CLIENT_ID, | ||
process.env.SLACK_CLIENT_SECRET, | ||
process.env.WORKSTATION_ID, | ||
process.env.LIVE_PRIVATE_KEY, | ||
); | ||
}) | ||
.then((server) => { | ||
server.run().then(port => console.log(`Express app listening on port ${port}`)); | ||
const server = new Server(ngrokUrl, awsUrl, mountPath, config); | ||
server.run(); | ||
}) | ||
.catch(e => console.error(e)); | ||
.catch((e) => { | ||
disk.close(); | ||
console.error(e); | ||
}); |
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 was deleted.
Oops, something went wrong.
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,14 +1,9 @@ | ||
const ngrok = require('ngrok'); | ||
|
||
module.exports.run = async (token, sitePort = 3000, livePort = 8000) => { | ||
module.exports.run = async (token, port = 3000) => { | ||
await ngrok.authtoken(token); | ||
const siteUrl = await ngrok.connect(sitePort); | ||
const liveUrl = await ngrok.connect(livePort); | ||
const url = await ngrok.connect(port); | ||
|
||
console.log(`Forwarding ${siteUrl} -> localhost:${sitePort}`); | ||
console.log(`Forwarding ${liveUrl} -> localhost:${livePort}`); | ||
return { | ||
siteUrl, | ||
liveUrl, | ||
}; | ||
console.log(`Forwarding ${url} -> localhost:${port}`); | ||
return url; | ||
}; |
Oops, something went wrong.