-
-
Notifications
You must be signed in to change notification settings - Fork 311
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
11 changed files
with
277 additions
and
17 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
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,104 @@ | ||
<!doctype html> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>ffmpeg.wasm video-only example - Record Plugin for Video.js</title> | ||
|
||
<link href="../../node_modules/video.js/dist/video-js.min.css" rel="stylesheet"> | ||
<link href="../../dist/css/videojs.record.css" rel="stylesheet"> | ||
<link href="../assets/css/examples.css" rel="stylesheet"> | ||
|
||
<script src="../../node_modules/video.js/dist/video.min.js"></script> | ||
<script src="../../node_modules/recordrtc/RecordRTC.js"></script> | ||
<script src="../../node_modules/webrtc-adapter/out/adapter.js"></script> | ||
<script src="../../node_modules/@ffmpeg/ffmpeg/dist/ffmpeg.min.js"></script> | ||
|
||
<script src="../../dist/videojs.record.js"></script> | ||
<script src="../../dist/plugins/videojs.record.ffmpeg-wasm.js"></script> | ||
|
||
<script src="../browser-workarounds.js"></script> | ||
|
||
<style> | ||
/* change player background color */ | ||
#myVideo { | ||
background-color: #F5BDAB; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
|
||
<video id="myVideo" playsinline class="video-js vjs-default-skin"></video> | ||
|
||
<script> | ||
/* eslint-disable */ | ||
var options = { | ||
controls: true, | ||
width: 320, | ||
height: 240, | ||
fluid: false, | ||
bigPlayButton: false, | ||
controlBar: { | ||
volumePanel: false | ||
}, | ||
plugins: { | ||
record: { | ||
audio: false, | ||
video: true, | ||
maxLength: 20, | ||
debug: true, | ||
displayMilliseconds: false, | ||
convertEngine: 'ffmpeg.wasm', | ||
// convert recorded data to MP3 | ||
convertOptions: ['-f', 'mp3', '-codec:a', 'libmp3lame', '-qscale:a', '2'], | ||
// specify MP3 output mime-type | ||
pluginLibraryOptions: { | ||
outputType: 'audio/mpeg' | ||
}, | ||
convertWorkerURL: '../../node_modules/@ffmpeg/core/dist/ffmpeg-core.js' | ||
} | ||
} | ||
}; | ||
|
||
// apply some workarounds for opera browser | ||
applyVideoWorkaround(); | ||
|
||
var player = videojs('myVideo', options, function() { | ||
// print version information at startup | ||
videojs.log('Using video.js', videojs.VERSION, | ||
'with videojs-record', videojs.getPluginVersion('record'), | ||
'and recordrtc', RecordRTC.version); | ||
}); | ||
// error handling | ||
player.on('deviceError', function() { | ||
console.log('device error:', player.deviceErrorCode); | ||
}); | ||
player.on('error', function(element, error) { | ||
console.error(error); | ||
}); | ||
|
||
// user clicked the record button and started recording | ||
player.on('startRecord', function() { | ||
console.log('started recording!'); | ||
}); | ||
|
||
// converter started processing | ||
player.on('startConvert', function() { | ||
console.log('started converting!'); | ||
}); | ||
|
||
// user completed recording and stream is available | ||
player.on('finishRecord', function() { | ||
// the blob object contains the recorded data that | ||
// can be downloaded by the user, stored on server etc. | ||
console.log('finished recording: ', player.recordedData); | ||
}); | ||
|
||
// converter completed and stream is available | ||
player.on('finishConvert', function() { | ||
// the convertedData object contains the recorded data that | ||
// can be downloaded by the user, stored on server etc. | ||
console.log('finished converting: ', player.convertedData); | ||
}); | ||
</script> | ||
</body> | ||
</html> |
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
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
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,98 @@ | ||
/** | ||
* @file ffmpeg-wasm-plugin.js | ||
* @since 4.2.0 | ||
*/ | ||
|
||
import videojs from 'video.js'; | ||
|
||
const ConvertEngine = videojs.getComponent('ConvertEngine'); | ||
|
||
/** | ||
* Converter engine using the ffmpeg.wasm library. | ||
* | ||
* @class | ||
* @augments videojs.ConvertEngine | ||
*/ | ||
class FFmpegWasmEngine extends ConvertEngine { | ||
/** | ||
* Creates an instance of this class. | ||
* | ||
* @param {Player} player | ||
* The `Player` that this class should be attached to. | ||
* | ||
* @param {Object} [options] | ||
* The key/value store of player options. | ||
*/ | ||
constructor(player, options) { | ||
super(player, options); | ||
|
||
/** | ||
* Enables console logging for debugging purposes. | ||
* | ||
* @type {boolean} | ||
*/ | ||
this.debug = false; | ||
/** | ||
* Path to script `ffmpeg-core.js`. | ||
* | ||
* @type {string} | ||
*/ | ||
this.convertWorkerURL = './node_modules/@ffmpeg/core/dist/ffmpeg-core.js'; | ||
/** | ||
* Mime-type for output. | ||
* | ||
* @type {string} | ||
*/ | ||
this.outputType = null; | ||
/** | ||
* Additional configuration options for the ffmpeg.wasm library. | ||
* | ||
* @type {object} | ||
*/ | ||
this.pluginLibraryOptions = {}; | ||
} | ||
|
||
/** | ||
* Inject metadata. | ||
* | ||
* @param {Blob} data - Recorded data that needs to be converted. | ||
*/ | ||
async convert(data) { | ||
const { createFFmpeg, fetchFile } = FFmpeg; | ||
const ffmpeg = createFFmpeg({ | ||
corePath: this.convertWorkerURL, | ||
log: this.debug | ||
}); | ||
const name = "foo"; | ||
|
||
// save timestamp | ||
const timestamp = new Date(); | ||
timestamp.setTime(data.lastModified); | ||
|
||
// notify listeners | ||
this.player().trigger('startConvert'); | ||
|
||
// load and convert blob | ||
await ffmpeg.load(); | ||
ffmpeg.FS('writeFile', name, await fetchFile(data)); | ||
await ffmpeg.run('-i', name, 'output.mp4'); | ||
const output = ffmpeg.FS('readFile', 'output.mp4'); | ||
|
||
// create new blob | ||
let result = new Blob([output.buffer], {type: 'video/mp4'}); | ||
|
||
// add existing file info | ||
this.addFileInfo(result, timestamp); | ||
|
||
// store result | ||
this.player().convertedData = result; | ||
|
||
// notify listeners | ||
this.player().trigger('finishConvert'); | ||
} | ||
} | ||
|
||
// expose plugin | ||
videojs.FFmpegWasmEngine = FFmpegWasmEngine; | ||
|
||
export default FFmpegWasmEngine; |
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
Oops, something went wrong.