Fireship · @fireship

WASM + React... Easily build video editing software with JS & FFmpeg

Uploaded November 17, 2020 · Length 8:01

WASM + React... Easily build video editing software with JS & FFmpeg

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.

  1. 0:00

    webassembly opens the door to building

  2. 0:02

    high performance applications on the web

  3. 0:03

    in languages other than javascript

  4. 0:05

    in today's video we'll build a simple

  5. 0:07

    video editing tool that can take a video

  6. 0:09

    file

  7. 0:09

    and convert it to an animated gif the

  8. 0:11

    cool thing about this demo is that it's

  9. 0:13

    made possible by a library called ffmpeg

  10. 0:16

    which is a utility written in the c

  11. 0:17

    programming language but thanks to

  12. 0:19

    webassembly we can run this tool

  13. 0:20

    directly in the browser

  14. 0:22

    and that means we can perform cpu

  15. 0:23

    intensive video editing jobs without the

  16. 0:25

    need for a backend server

  17. 0:27

    for example here's how a traditional web

  18. 0:29

    application might work we collect a

  19. 0:30

    video file from the end user

  20. 0:32

    then upload it to the cloud we use our

  21. 0:34

    cloud server to run ffmpeg to encode the

  22. 0:36

    file

  23. 0:37

    and send it back down to the client that

  24. 0:39

    works fine but it's not very efficient

  25. 0:41

    and it also has no way to work offline

  26. 0:43

    if you're building a progressive web app

  27. 0:45

    what we'll do in this video is download

  28. 0:47

    the webassembly binary for

  29. 0:48

    ffmpeg directly into a react app

  30. 0:51

    allowing us to combine the c programming

  31. 0:52

    language with javascript

  32. 0:54

    and offload the video editing work to

  33. 0:56

    the end user's hardware

  34. 0:57

    if you're new here like and subscribe

  35. 0:59

    and follow along with the full write up

  36. 1:00

    and source code on fireship io and if

  37. 1:02

    you have no idea what webassembly is

  38. 1:04

    check out my 100 second breakdown on

  39. 1:06

    that topic this tutorial is very

  40. 1:08

    beginner friendly

  41. 1:08

    and doesn't require that you know

  42. 1:10

    anything about the c programming

  43. 1:11

    language

  44. 1:12

    that's because the ffmpeg.wasm package

  45. 1:14

    provides an api in javascript to

  46. 1:16

    interact with this low-level utility

  47. 1:18

    now before we jump into the code let's

  48. 1:20

    take a closer look at the demo we have a

  49. 1:22

    file input where we can select a video

  50. 1:24

    file

  51. 1:25

    the video can be previewed in a video

  52. 1:26

    element then when you click the convert

  53. 1:28

    button

  54. 1:29

    it runs ffmpeg to load the video file

  55. 1:31

    into memory

  56. 1:32

    and run the conversion very simple stuff

  57. 1:35

    but my main goal here is to give you a

  58. 1:36

    starting point for building more complex

  59. 1:38

    features through the magic of

  60. 1:39

    webassembly

  61. 1:40

    to get things started i'm generating a

  62. 1:42

    new react app using snowpack

  63. 1:44

    and keep in mind here the code is very

  64. 1:46

    simple so feel free to follow along with

  65. 1:48

    any other framework

  66. 1:49

    then from inside your project you'll

  67. 1:50

    want to install the following packages

  68. 1:52

    from the ffmpeg namespace and lastly you

  69. 1:55

    can run npm start which should give you

  70. 1:57

    the default react app running in the

  71. 1:59

    browser

  72. 1:59

    from there we'll go into the source