Fireship · @fireship
WASM + React... Easily build video editing software with JS & FFmpeg
Uploaded November 17, 2020 · Length 8:01
Summary
Build a video editing tool with JavaScript and FFmpeg using WebAssembly in a React app.
- webassembly
- react
- ffmpeg
- video editing
- javascript
- web development
Transcript preview
The first 2 minutes of the transcript. Select a timestamp to watch that moment on YouTube.
- 0:00
webassembly opens the door to building
- 0:02
high performance applications on the web
- 0:03
in languages other than javascript
- 0:05
in today's video we'll build a simple
- 0:07
video editing tool that can take a video
- 0:09
file
- 0:09
and convert it to an animated gif the
- 0:11
cool thing about this demo is that it's
- 0:13
made possible by a library called ffmpeg
- 0:16
which is a utility written in the c
- 0:17
programming language but thanks to
- 0:19
webassembly we can run this tool
- 0:20
directly in the browser
- 0:22
and that means we can perform cpu
- 0:23
intensive video editing jobs without the
- 0:25
need for a backend server
- 0:27
for example here's how a traditional web
- 0:29
application might work we collect a
- 0:30
video file from the end user
- 0:32
then upload it to the cloud we use our
- 0:34
cloud server to run ffmpeg to encode the
- 0:36
file
- 0:37
and send it back down to the client that
- 0:39
works fine but it's not very efficient
- 0:41
and it also has no way to work offline
- 0:43
if you're building a progressive web app
- 0:45
what we'll do in this video is download
- 0:47
the webassembly binary for
- 0:48
ffmpeg directly into a react app
- 0:51
allowing us to combine the c programming
- 0:52
language with javascript
- 0:54
and offload the video editing work to
- 0:56
the end user's hardware
- 0:57
if you're new here like and subscribe
- 0:59
and follow along with the full write up
- 1:00
and source code on fireship io and if
- 1:02
you have no idea what webassembly is
- 1:04
check out my 100 second breakdown on
- 1:06
that topic this tutorial is very
- 1:08
beginner friendly
- 1:08
and doesn't require that you know
- 1:10
anything about the c programming
- 1:11
language
- 1:12
that's because the ffmpeg.wasm package
- 1:14
provides an api in javascript to
- 1:16
interact with this low-level utility
- 1:18
now before we jump into the code let's
- 1:20
take a closer look at the demo we have a
- 1:22
file input where we can select a video
- 1:24
file
- 1:25
the video can be previewed in a video
- 1:26
element then when you click the convert
- 1:28
button
- 1:29
it runs ffmpeg to load the video file
- 1:31
into memory
- 1:32
and run the conversion very simple stuff
- 1:35
but my main goal here is to give you a
- 1:36
starting point for building more complex
- 1:38
features through the magic of
- 1:39
webassembly
- 1:40
to get things started i'm generating a
- 1:42
new react app using snowpack
- 1:44
and keep in mind here the code is very
- 1:46
simple so feel free to follow along with
- 1:48
any other framework
- 1:49
then from inside your project you'll
- 1:50
want to install the following packages
- 1:52
from the ffmpeg namespace and lastly you
- 1:55
can run npm start which should give you
- 1:57
the default react app running in the
- 1:59
browser
- 1:59
from there we'll go into the source


