Skip to content

Instantly share code, notes, and snippets.

View jeromewu's full-sized avatar
:octocat:
Working on ffmpeg.wasm and tesseract.js

jeromewu jeromewu

:octocat:
Working on ffmpeg.wasm and tesseract.js
View GitHub Profile
public class Main {
public static void main(String[] args) {
Set<String> ingredients = new HashSet();
Set<String> allergens = new HashSet();
for (int i = 0; i < args.length(); i++) {
String[] cols = args.get(i).split(" (contains ");
String[] ings = cols[0].split(" ");
for (Sring ing : ings) {
ingredients.add(ing);
@jeromewu
jeromewu / a-little-js-problem.js
Created February 8, 2021 09:55
My Answer for a little javascript problem
/**
* Link to the problem: http://lisperator.net/blog/a-little-javascript-problem/
*/
const node = (val) => (next) => (key) => {
return (key === 'value' ? val : next);
};
const range = (start, end) => {
return (start === end ? node(end)(null) : node(start)(range(++start, end)));
};
@jeromewu
jeromewu / ffmpeg.wasm-example.js
Last active November 4, 2020 10:46
ffmpeg.wasm-example.js
const fs = require('fs');
const { createFFmpeg, fetchFile } = require('@ffmpeg/ffmpeg');
const ffmpeg = createFFmpeg({ log: true });
(async () => {
await ffmpeg.load();
ffmpeg.FS('writeFile', 'test.avi', await fetchFile('./test.avi'));
await ffmpeg.run('-i', 'test.avi', 'test.mp4');
fs.writeFileSync('./test.mp4', ffmpeg.FS('readFile', 'test.mp4'));
process.exit(0);
})();
<html>
<head>
<style>
html, body {
margin: 0;
width: 100%;
height: 100%
}
body {
display: flex;
#!/bin/bash -x
# ...
CONFIG_ARGS=(
--target-os=none # use none to prevent any os specific configurations
--arch=x86_32 # use x86_32 to achieve minimal architectural optimization
--enable-cross-compile # enable cross compile
--disable-x86asm # disable x86 asm
--disable-inline-asm # disable inline asm
#!/bin/bash -x
ARGS=(
--host=i686-gnu # use i686 gnu
--enable-static # enable building static library
--disable-cli # disable cli tools
--disable-asm # disable asm optimization
--extra-cflags="-s USE_PTHREADS=1" # pass this flags for using pthreads
)
emconfigure ./configure "${ARGS[@]}"
const fs = require('fs');
const Module = require('./dist/ffmpeg-core');
Module.onRuntimeInitialized = () => {
const data = Uint8Array.from(fs.readFileSync('./flame.avi'));
Module.FS.writeFile('flame.avi', data);
const ffmpeg = Module.cwrap('proxy_main', 'number', ['number', 'number']);
const args = ['ffmpeg', '-hide_banner', '-report', '-i', 'flame.avi', 'flame.mp4'];
const argsPtr = Module._malloc(args.length * Uint32Array.BYTES_PER_ELEMENT);
const fs = require('fs');
const Module = require('./dist/ffmpeg-core');
Module.onRuntimeInitialized = () => {
const data = Uint8Array.from(fs.readFileSync('./flame.avi'));
Module.FS.writeFile('flame.avi', data);
const ffmpeg = Module.cwrap('proxy_main', 'number', ['number', 'number']);
const args = ['ffmpeg', '-hide_banner'];
const argsPtr = Module._malloc(args.length * Uint32Array.BYTES_PER_ELEMENT);
const Module = require('./dist/ffmpeg-core');
Module.onRuntimeInitialized = () => {
const ffmpeg = Module.cwrap('proxy_main', 'number', ['number', 'number']);
const args = ['ffmpeg', '-hide_banner'];
const argsPtr = Module._malloc(args.length * Uint32Array.BYTES_PER_ELEMENT);
args.forEach((s, idx) => {
const buf = Module._malloc(s.length + 1);
Module.writeAsciiToMemory(s, buf);
Module.setValue(argsPtr + (Uint32Array.BYTES_PER_ELEMENT * idx), buf, 'i32');
const ptrs = [123, 3455];
const buf = Module._malloc(ptrs.length * Uint32Array.BYTES_PER_ELEMENT);
ptrs.forEach((p, idx) => {
Module.setValue(buf + (Uint32Array.BYTES_PER_ELEMENT * idx), p, 'i32');
});