This file contains hidden or 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
| #!/bin/bash | |
| NPROC=$(grep -c ^processor /proc/cpuinfo) | |
| BUILD_DIR=$PWD/build | |
| git submodule add [email protected]:jeromewu/lame.git third_party/lame | |
| cd third_party/lame | |
| git checkout 3.100 | |
| emconfigure ./configure --prefix=$BUILD_DIR |
This file contains hidden or 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
| emcc \ | |
| -Llibavcodec -Llibavdevice -Llibavfilter -Llibavformat -Llibavresample -Llibavutil -Llibpostproc -Llibswscale -Llibswresample \ | |
| -Qunused-arguments -Oz \ | |
| -o javascript/ffmpeg-core.js fftools/ffmpeg_opt.o fftools/ffmpeg_filter.o fftools/ffmpeg_hw.o fftools/cmdutils.o fftools/ffmpeg.o \ | |
| -lavdevice -lavfilter -lavformat -lavcodec -lswresample -lswscale -lavutil -lm \ | |
| -s MODULARIZE=1 \ | |
| -s EXPORTED_FUNCTIONS="[_ffmpeg]" \ | |
| -s EXTRA_EXPORTED_RUNTIME_METHODS="[cwrap, FS, getValue, setValue]" \ | |
| -s TOTAL_MEMORY=33554432 \ | |
| -s ALLOW_MEMORY_GROWTH=1 |
This file contains hidden or 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
| const fs = require('fs'); | |
| const ffmpeg = require('@ffmpeg/ffmpeg'); | |
| (async () => { | |
| await ffmpeg.load(); | |
| const data = ffmpeg.transcode('./input.avi', 'mp4'); | |
| fs.writeFileSync('./output.mp4', data); | |
| })(); |
This file contains hidden or 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
| const { setModule } = require('./util/module'); | |
| const FFmpegCore = require('./ffmpeg-core'); | |
| module.exports = () => ( | |
| new Promise((resolve, reject) => { | |
| FFmpegCore() | |
| .then((Module) => { | |
| setModule(Module); | |
| resolve(); | |
| }); |
This file contains hidden or 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
| const { getModule } = require('./module'); | |
| module.exports = (s) => { | |
| const Module = getModule(); | |
| const ptr = Module._malloc((s.length+1)*Uint8Array.BYTES_PER_ELEMENT); | |
| for (let i = 0; i < s.length; i++) { | |
| Module.setValue(ptr+i, s.charCodeAt(i), 'i8'); | |
| } | |
| Module.setValue(ptr+s.length, 0, 'i8'); | |
| return ptr; |
This file contains hidden or 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
| const { getModule } = require('./module'); | |
| const str2ptr = require('./str2ptr'); | |
| module.exports = (strList) => { | |
| const Module = getModule(); | |
| const listPtr = Module._malloc(strList.length*Uint32Array.BYTES_PER_ELEMENT); | |
| strList.forEach((s, idx) => { | |
| const strPtr = str2ptr(s); | |
| Module.setValue(listPtr + (4*idx), strPtr, 'i32'); |
This file contains hidden or 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
| const fs = require('fs'); | |
| const { getModule } = require('./util/module'); | |
| const strList2ptr = require('./util/strList2ptr'); | |
| module.exports = (inputPath, outputExt) => { | |
| const Module = getModule(); | |
| const data = new Uint8Array(fs.readFileSync(inputPath)); | |
| const ffmpeg = Module.cwrap('ffmpeg', 'number', ['number', 'number']); | |
| const args = ['./ffmpeg', '-i', 'input.avi', `output.${outputExt}`]; | |
| Module.FS.writeFile('input.avi', data); |
This file contains hidden or 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 script is loaded by ffmpegwasm-v0.2.js | |
| */ | |
| let Module = null; | |
| let ffmpeg = null; | |
| const load = () => { | |
| global.importScripts('./ffmpeg-core.js'); | |
| global.Module() |
This file contains hidden or 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
| const resolves = {}; | |
| const rejects = {}; | |
| const worker = new Worker('./worker.js'); | |
| worker.onmessage = ({ action, payload }) => { | |
| resolves[action](payload); | |
| }; | |
| exports.load = () => new Promise((resolve) => { |
This file contains hidden or 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
| const { load, transcode } = require('./ffmpegwasm-v0.2'); | |
| (async () => { | |
| await load(); | |
| const { data } = await transcode(mediaData, 'mp4'); | |
| // do something with data | |
| })(); |