How to create a video to GIF converter using ReactJS ?
Last Updated :
23 Jul, 2025
When you think about a GIF image, a video is a must convert into a .gif format to an image. For this project, we are using FFMPEG library utility written in the C programming language. With the support of web Assembly, it can run in browsers easily without any need for a server, also here we are using the ReactJS library to make it simple and more understandable.
You can know about web Assembly from the below Links:
Also, you can learn about FFMPEG which is a free and open-source software project consisting of a large suite of libraries and programs for handling video, audio, and other multimedia files and streams you can check from the https://ffmpeg.org/ link.
FFMPEG: FFmpeg.wasm is a WebAssembly port of FFmpeg, which you can install via npm and use within Node or the browser just like any other JavaScript module. Create a simple client-side transcoder that streams data into a video element.
Before going to make this project you have a hands-on experience on ReactJS because we are using react hook that is useState. So, ok with that concept go further and create your directory for the project.
- Create our React app with snowpack by following the command:
npm create vite@latest gifconverter --template react
- After installation above command then installs another package called FFMPEG by the following command:
npm install @ffmpeg/ffmpeg @ffmpeg/core
- For our styling purpose, you install the styled component by the following command. It is most likely CSS, but as we play with JavaScript it creates the user-defined variable, in that variable, we can write CSS properties, it is also used for making components without making a new JSX file.
npm i styled-components
Project Structure: All installation for the project is complete, and we are now going for developing our aiming project. Now you can see the project directory looks like the following and you're all dependencies are installed successfully than good to go.

Now you open your command prompt and type the following command to start your server by running the below command. Then your browser opens in port number 8080 where your app is running, If your browser looks like this then you are in the right place.
cd gifconverter
npm run dev
Now open your project folder in your code editor and make a folder in src directory called components and under this folder make various JSX components file by following
src/components:
- Button.jsx
- Dbutton.jsx
- Header.jsx
- Inputfile.jsx
- Inputvideo.jsx
- Resultimg.jsx

After creating the above JSX components, Let's go for add the code for our project:
Filename- Button.jsx: This component is a convert button, when you click on it automatically changes the .mp4 file to .gif file.
JavaScript
import React from "react";
import styled from "styled-components";
const Btn = styled.button`
background-color: #000;
color: #fff;
border-radius: 18px;
border: 1px solid #000;
outline: none;
font-weight: 700;
cursor: pointer;
font-size: 1.2em;
padding: 10px;
min-width: 20%;
transition: all 0.2s ease-in-out;
:hover {
background-color: #3f3f3f;
color: #efefef;
}
`;
export const Button = ({ convertToGif }) => {
return <Btn onClick={convertToGif}>Convert</Btn>;
};
Filename- Dbutton.jsx: This component is a download button where you can download the .gif image after the convert from the .mp4 file.
JavaScript
import React from "react";
import styled from "styled-components";
const Btn = styled.a`
display: flex;
left: 0;
right: 0;
margin: 20px auto;
margin-top: -20px;
background-color: #000;
color: #fff;
border-radius: 35.5px;
border: 1px solid #000;
outline: none;
font-weight: 700;
cursor: pointer;
font-size: 1.2em;
padding: 10px;
padding-left: 50px;
max-width: 10%;
text-decoration: none;
transition: all 0.2s ease-in-out;
:hover {
background-color: #3f3f3f;
color: #efefef;
}
`;
export const Dbutton = ({ gif, download }) => {
return (
<Btn href={gif} download onClick={(e) => download(e)}>
Download
</Btn>
);
};
Filename- Header.jsx:
JavaScript
import React from "react";
import styled from "styled-components";
const H1 = styled.h1`
margin: 0;
padding: 12px;
background-color: #000;
color: #fff;
font-family: sans-serif;
font-size: 3em;
`;
export const Header = () => {
return (
<div>
<H1>video to gif converter</H1>
</div>
);
};
Filename- Inputfile.jsx: This component used for getting user input of video file (.mp4 file)
JavaScript
import React from "react";
import styled from "styled-components";
const Section = styled.div`
display: flex;
left: 0;
right: 0;
margin: 50px auto;
width: 30%;
border: 2px dashed #000;
border-radius: 18px;
padding: 10px;
`;
export const Inputfile = ({ setVideo }) => {
return (
<Section>
<input type="file" onChange={(e) => setVideo(e.target.files?.item(0))} />
</Section>
);
};
Filename- Inputvideo.jsx:
JavaScript
import React from "react";
import styled from "styled-components";
const Video = styled.video`
width: 40%;
margin: 20px;
border: 1px dashed #045ca3;
`;
export const Inputvideo = ({ video }) => {
return <Video controls width="250" src={URL.createObjectURL(video)} />;
};
Filename- Resultimage.jsx: This component is showing the .gif image which converter from a video file.
JavaScript
import React from "react";
import styled from "styled-components";
const Img = styled.img`
width: 50%;
height: 100%;
border: 4px solid #000;
margin: 40px auto;
`;
export const Resultimg = ({ gif }) => {
return <Img src={gif} />;
};
From the above individual components you can see there are many useState props are passed in the arrow function using curly bracket, don't worry that state you can find in the App.jsx. I prefer to consider all hooks in the App.jsx.
So, we are adding all code for our required components that are used for our project. After the adding of all the code, then we have to import the components file to the App.jsx
Filename- App.jsx: Here is our App.jsx code. Let's import our components into this file. In the below App.jsx , we are importing a library as discussed previously that is FFmpeg as createFFmpeg , fetchFile.
We are in the last phase of our project to finalize is our project working well or not ?:) Then after refreshing, you can see what your GIF converter looks like in the following image.
JavaScript
import React, { useState, useEffect } from "react";
import "./App.css";
import { createFFmpeg, fetchFile } from "@ffmpeg/ffmpeg";
import { Button } from "./components/Button";
import { Inputfile } from "./components/Inputfile";
import { Header } from "./components/Header";
import { Resultimg } from "./components/Resultimage";
import { Inputvideo } from "./components/Inputvideo";
import { Dbutton } from "./components/Dbutton";
// Create the FFmpeg instance and load it
const ffmpeg = createFFmpeg({ log: true });
function App() {
const [ready, setReady] = useState(false);
const [video, setVideo] = useState();
const [gif, setGif] = useState();
const load = async () => {
await ffmpeg.load();
setReady(true);
};
useEffect(() => {
load();
}, []);
const convertToGif = async () => {
// Write the .mp4 to the FFmpeg file system
ffmpeg.FS("writeFile", "video1.mp4", await fetchFile(video));
// Run the FFmpeg command-line tool, converting
// the .mp4 into .gif file
await ffmpeg.run(
"-i",
"video1.mp4",
"-t",
"2.5",
"-ss",
"2.0",
"-f",
"gif",
"out.gif"
);
// Read the .gif file back from the FFmpeg file system
const data = ffmpeg.FS("readFile", "out.gif");
const url = URL.createObjectURL(
new Blob([data.buffer], { type: "image/gif" })
);
setGif(url);
};
const download = (e) => {
console.log(e.target.href);
fetch(e.target.href, {
method: "GET",
headers: {},
})
.then((response) => {
response.arrayBuffer().then(function (buffer) {
const url = window.URL.createObjectURL(new Blob([buffer]));
const link = document.createElement("a");
link.href = url;
link.setAttribute("download", "image.gif");
document.body.appendChild(link);
link.click();
});
})
.catch((err) => {
console.log(err);
});
};
return ready ? (
<div className="App">
<Header />
{video && <Inputvideo video={video} />}
<Inputfile setVideo={setVideo} />
<Button convertToGif={convertToGif} />
<h1>Result</h1>
{gif && <Resultimg gif={gif} />}
{gif && <Dbutton gif={gif} download={download} />}
</div>
) : (
<p>Loading...</p>
);
}
export default App;
Output: If your browser gives this output, Then your project is running fine. Then choose a video file to convert into the image, After converting click on the convert button you can see it gives us a .gif format animated image.
How to create a video to GIF converter using ReactJS ?
Similar Reads
React Tutorial React is a powerful JavaScript library for building fast, scalable front-end applications. Created by Facebook, it's known for its component-based structure, single-page applications (SPAs), and virtual DOM,enabling efficient UI updates and a seamless user experience.Note: The latest stable version
7 min read
React Fundamentals
React IntroductionReactJS is a component-based JavaScript library used to build dynamic and interactive user interfaces. It simplifies the creation of single-page applications (SPAs) with a focus on performance and maintainability. Why Use React?Before React, web development faced issues like slow DOM updates and mes
7 min read
React Environment SetupTo run any React application, we need to first setup a ReactJS Development Environment. In this article, we will show you a step-by-step guide to installing and configuring a working React development environment.Pre-requisite:We must have Nodejs installed on our PC. So, the very first step will be
3 min read
React JS ReactDOMReactDOM is a core React package that provides methods to interact with the Document Object Model, or DOM. This package allows developers to access and modify the DOM. It is a package in React that provides DOM-specific methods that can be used at the top level of a web app to enable an efficient wa
3 min read
React JSXJSX stands for JavaScript XML, and it is a special syntax used in React to simplify building user interfaces. JSX allows you to write HTML-like code directly inside JavaScript, enabling you to create UI components more efficiently. Although JSX looks like regular HTML, itâs actually a syntax extensi
5 min read
ReactJS Rendering ElementsIn this article we will learn about rendering elements in ReactJS, updating the rendered elements and will also discuss about how efficiently the elements are rendered.What are React Elements?React elements are the smallest building blocks of a React application. They are different from DOM elements
3 min read
React ListsReact Lists are used to display a collection of similar data items like an array of objects and menu items. It allows us to dynamically render the array elements and display repetitive data.Rendering List in ReactTo render a list in React, we will use the JavaScript array map() function. We will ite
5 min read
React FormsForms are an essential part of any application used for collecting user data, processing payments, or handling authentication. React Forms are the components used to collect and manage the user inputs. These components include the input elements like text field, check box, date input, dropdowns etc.
5 min read
ReactJS KeysA key serves as a unique identifier in React, helping to track which items in a list have changed, been updated, or removed. It is particularly useful when dynamically creating components or when users modify the list. In this article, we'll explore ReactJS keys, understand their importance, how the
5 min read
Components in React
React ComponentsIn React, React components are independent, reusable building blocks in a React application that define what gets displayed on the UI. They accept inputs called props and return React elements describing the UI.In this article, we will explore the basics of React components, props, state, and render
4 min read
ReactJS Functional ComponentsIn ReactJS, functional components are a core part of building user interfaces. They are simple, lightweight, and powerful tools for rendering UI and handling logic. Functional components can accept props as input and return JSX that describes what the component should render.Stateless (before hooks)
5 min read
React Class ComponentsClass components are ES6 classes that extend React.Component. They allow state management and lifecycle methods for complex UI logic.Used for stateful components before Hooks.Support lifecycle methods for mounting, updating, and unmounting.The render() method in React class components returns JSX el
4 min read
ReactJS Pure ComponentsReactJS Pure Components are similar to regular class components but with a key optimization. They skip re-renders when the props and state remain the same. While class components are still supported in React, it's generally recommended to use functional components with hooks in new code for better p
4 min read
ReactJS Container and Presentational Pattern in ComponentsIn this article we will categorise the react components in two types depending on the pattern in which they are written in application and will learn briefly about these two categories. We will also discuss about alternatives to this pattern. Presentational and Container ComponentsThe type of compon
2 min read
ReactJS PropTypesIn ReactJS PropTypes are the property that is mainly shared between the parent components to the child components. It is used to solve the type validation problem. Since in the latest version of the React 19, PropeTypes has been removed. What is ReactJS PropTypes?PropTypes is a tool in React that he
5 min read
React Lifecycle In React, the lifecycle refers to the various stages a component goes through. These stages allow developers to run specific code at key moments, such as when the component is created, updated, or removed. By understanding the React lifecycle, you can better manage resources, side effects, and perfo
7 min read
React Hooks
Routing in React
Advanced React Concepts
React Projects