-
Notifications
You must be signed in to change notification settings - Fork 0
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
7 changed files
with
9,613 additions
and
1,251 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
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
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,55 @@ | ||
const { S3Client, PutObjectCommand } = require("@aws-sdk/client-s3"); | ||
const AWS = require('aws-sdk'); | ||
const ffmpeg = require('fluent-ffmpeg'); | ||
const stream = require('stream'); | ||
|
||
module.exports.handler = async (event) => { | ||
|
||
console.log("start-audio-transcode.js: event: ", event); | ||
|
||
const s3 = new AWS.S3(); | ||
const url = event.streamingUrl; | ||
const referer = event.referer || null; | ||
const inputOptions = referer ? ["-referer", referer] : []; | ||
const BUCKET = event.destinationBucket; | ||
const KEY = event.destinationKey; | ||
const pass = new stream.PassThrough(); | ||
|
||
pass.on('close', () => { | ||
console.log('PassThrough stream closed'); | ||
}); | ||
|
||
|
||
return new Promise((resolve, reject) => { | ||
ffmpeg() | ||
.input(url) | ||
.inputOptions(inputOptions) | ||
.format('mp3') | ||
.output(pass, { end: true }) | ||
.on('start', () => { | ||
console.log('ffmpeg process started'); | ||
s3.upload({ | ||
Bucket: BUCKET, | ||
Key: KEY, | ||
Body: pass, | ||
}, (error, data) => { | ||
if (error) { | ||
console.error('upload failed', error); | ||
reject(error); | ||
} else { | ||
console.log('upload completed'); | ||
resolve({ success: true }); | ||
} | ||
}); | ||
}) | ||
.on('error', (error) => { | ||
console.error('ffmpeg error', error); | ||
reject(error); | ||
}) | ||
.on('end', () => { | ||
console.log('ffmpeg process ended'); | ||
}) | ||
.on('progress', (p) => console.log('progress', p)) | ||
.run(); | ||
}); | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
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