Comments (7)
Lets say I've like 500 images in an array that I want to convert in a video, so do I run this in a loop and writeFile 500 times?
Yes, exactly. Just be aware of memory limits, especially on mobile devices.
from ffmpeg.wasm.
Yes, we can 🦾
With help of ffmpeg command: --pattern_type glob
Pass array of images with num pattern like: -i frame_*.jpg
. Remember that your frames should have correct number relative to video that you want to get. Ex:
const num = `00${index}`.slice(-3);
await this.ffmpeg.writeFile(`frame_${num}.jpg`, new Uint8Array(buffer));
from ffmpeg.wasm.
check ffmpeg docs: https://ffmpeg.org/
from ffmpeg.wasm.
Yes, we can 🦾 With help of ffmpeg command:
--pattern_type glob
Pass array of images with num pattern like:-i frame_*.jpg
. Remember that your frames should have correct number relative to video that you want to get. Ex:const num = `00${index}`.slice(-3); await this.ffmpeg.writeFile(`frame_${num}.jpg`, new Uint8Array(buffer));
Hi @tini2n,
Thanks for your response. I am trying to record the stream getting from navigator.mediaDevices.getUserMedia by painting the video into a canvas and then storing the imageData using ffmpeg.writeFile method and then trying to convert the images into video using ffmpeg.exe method but it is not working for me. I am sharing the code I used here. Kindly please assist me if I did anything wrong.
const ffmpegRef = useRef(new FFmpeg());
const canvasRef = useRef<HTMLCanvasElement | null>(null);
const videoRef = useRef<HTMLVideoElement | null>(null);
const fps = 30;
let uuid = crypto.randomUUID();
let images: Record<string, string[]> = {
[uuid]: [],
};
useEffect(() => {
initFFmpeg();
}, []);
const initFFmpeg = async () => {
const baseURL = "https://unpkg.com/@ffmpeg/[email protected]/dist/esm";
const ffmpeg = ffmpegRef.current;
ffmpeg.on("log", ({ message }) => {
console.log(message);
});
ffmpeg.on("progress", ({ progress, time }) => {
console.log(time, progress);
});
// toBlobURL is used to bypass CORS issue, urls with the same
// domain can be used directly.
await ffmpeg.load({
coreURL: await toBlobURL(`${baseURL}/ffmpeg-core.js`, "text/javascript"),
wasmURL: await toBlobURL(
`${baseURL}/ffmpeg-core.wasm`,
"application/wasm"
),
workerURL: await toBlobURL(
`${baseURL}/ffmpeg-core.worker.js`,
"text/javascript"
),
});
getVideoStream();
};
const getVideoStream = async () => {
if (!videoRef.current) return;
try {
let stream = await navigator.mediaDevices.getUserMedia({
audio: false,
video: true,
});
videoRef.current.srcObject = stream;
await videoRef.current.play();
console.log(ffmpegRef.current);
setInterval(renderCanvas, 1000 / fps);
} catch (error) {
console.log(error);
}
};
const renderCanvas = async () => {
if (!videoRef.current || !canvasRef.current || !ffmpegRef.current) return;
let ctx = canvasRef.current.getContext("2d");
if (!ctx) return;
let canvasWidth = canvasRef.current.width;
let canvasHeight = canvasRef.current.height;
ctx.clearRect(0, 0, canvasWidth, canvasHeight);
ctx.drawImage(
videoRef.current,
0,
0,
canvasRef.current.width,
canvasRef.current.height
);
let fileName = `image-${uuid}-${images[uuid].length + 1}.png`;
let base64 = canvasRef.current.toDataURL("image/png");
let unit8Array = await fetchFile(base64);
await ffmpegRef.current.writeFile(fileName, unit8Array);
images[uuid].push(fileName);
if (images[uuid].length === 125) convertImagesToVideo(uuid);
};
const convertImagesToVideo = async (id: string) => {
try {
uuid = crypto.randomUUID();
images[uuid] = [];
let ffmpeg = ffmpegRef.current;
const input = image-${id}-%d.png
;
const output = "output.mp4";
const args = -start_number 1 -i ${input} -c:v libx264 ${output}
;
await ffmpeg.exec(args.split(" "));
let data = await ffmpeg.readFile(output);
console.log(data);
} catch (error) {
console.log(error);
}
};
Thanks
from ffmpeg.wasm.
Hi @vkaswin, you can have a look here, this stop motion app seems to be doing the same thing you'd like to do:
https://github.com/kitsteam/stop-motion-app/blob/main/src/app/services/video/video.service.ts
https://github.com/kitsteam/stop-motion-app/blob/main/src/app/models/animator.ts#L148
from ffmpeg.wasm.
Hi @nwittstruck ,
Thanks for your response will check the stop motion github repository.
from ffmpeg.wasm.
Yes, we can 🦾 With help of ffmpeg command:
--pattern_type glob
Pass array of images with num pattern like:-i frame_*.jpg
. Remember that your frames should have correct number relative to video that you want to get. Ex:const num = `00${index}`.slice(-3); await this.ffmpeg.writeFile(`frame_${num}.jpg`, new Uint8Array(buffer));
Lets say I've like 500 images in an array that I want to convert in a video, so do I run this in a loop and writeFile 500 times?
from ffmpeg.wasm.
Related Issues (20)
- Did anyone encounter this issue when adding subtitles? HOT 2
- Deploying to server error: Missing download-assets.js
- Hi! I have built a collaborative video editor with ffmpeg wasm HOT 4
- support silk format
- Who has encountered this problem, which brother will help me
- 'Cross-Origin-Opener-Policy': 'same-origin', 'Cross-Origin-Embedder-Policy': 'require-corp' HOT 8
- Failed to load resource: net::ERR_REQUEST_RANGE_NOT_SATISFIABLE HOT 3
- load() error!!
- createDir error HOT 2
- load error
- When can ffprobe be used?ffprobe
- Upgrade to FFmpeg 6.x HOT 2
- Memory error HOT 1
- (bug/question) How to properly use one ffmpeg.exec() execution output as another's ffmpeg.exec() input? HOT 3
- Help needed solving -> DOMException: Failed to construct 'Worker': Script at 'https://reddit.com/814.ffmpeg.js' cannot be accessed from origin 'https://reddit.com.'
- Why can't ffmpeg.wasm work well on Chrome? Please answer. HOT 2
- Can't absolute paths be used in the ffmpeg.run method HOT 2
- ffmpeg.mount - ErrnoError: FS error HOT 4
- @ffmpeg/core and @ffmpeg/core-mt missing export for the ffmpeg-core.worker.js file.
- Who can give me an example of adding subtitles to a video? When I add subtitles, I always report that the font cannot be found HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ffmpeg.wasm.