Amazing React component for manipulating video length.
With the aid of FFMPEG in the browser, it get easier to do amazing things with media content.
npm install --save react-video-trimmer
or:
yarn add react-video-trimmer
NOTE: Do import the styles from react-video-trimmer/dist/style.css
import ReactVideoTrimmer from "react-video-trimmer";
<div>
<ReactVideoTrimmer timeLimit={20} showEncodeBtn />
</div>;
Start and end value in seconds the trimmer should restrict to.ti
import React from "react";
import ReactVideoTrimmer from "react-video-trimmer";
import "react-video-trimmer/dist/style.css";
const Trimmer = () => {
return (
<div>
<ReactVideoTrimmer timeRange={20} />
</div>
);
};
Handler that receives the video encoding once it has been encoded
import React from "react";
import ReactVideoTrimmer from "react-video-trimmer";
import "react-video-trimmer/dist/style.css";
const Trimmer = () => {
const handleVideoEncode = React.useCallback(result => {
console.log("Encoding Result:", result);
});
return (
<div>
<ReactVideoTrimmer
onVideoEncode={handleVideoEncode}
timeRange={{ start: 10, end: 100 }}
/>
</div>
);
};
A text to tell users that FFMPEG is being loaded in the background.
Default: Please wait...
import React from "react";
import ReactVideoTrimmer from "react-video-trimmer";
import "react-video-trimmer/dist/style.css";
const Trimmer = () => {
const handleVideoEncode = React.useCallback(result => {
console.log("Encoding Result:", result);
});
return (
<div>
<ReactVideoTrimmer
onVideoEncode={handleVideoEncode}
timeRange={{ start: 10, end: 100 }}
loadingFFMPEGText="Loading required libs..."
/>
</div>
);
};
Pass a ref to access all the static methods of ReactVideoTrimmer methods
import React from "react";
import ReactVideoTrimmer from "react-video-trimmer";
import "react-video-trimmer/dist/style.css";
const Trimmer = () => {
const trimmerRef = React.useRef();
return (
<div>
<ReactVideoTrimmer timeRange={{ start: 10, end: 100 }} ref={trimmerRef} />
</div>
);
};
A listener to ffmpeg-webworker
FFMPEGStdout
event
A listener to ffmpeg-webworker
FFMPEGReady
event
A listener to ffmpeg-webworker
FFMPEGFileReceived
event
A listener to ffmpeg-webworker
FFMPEGDone
event
Converts the returned result into a
Blob
, before updating the video player
- file: Blob A Blob/File with type matching
video/*
- doneCB: function Called after the decode action is completed
Called when a valid video file is selected, in turn calls decodeVideoFile
for
proper handling
- file: Blob A Blob/File with type matching
video/*
Called when a valid video file is selected, in turn calls decodeVideoFile
for
proper handling
- file: Blob A Blob/File with type matching
video/*
Handler for the Download button onClick
event. Downloads the converted video
file
- encodedVideo: Blob Encoded video data converted to
Blob
ffmpeg.js will not load until the component is in scope. To override this, a
preloadWebVideo
field has been included to make ffmpeg load ahead of this
component mount period.
import React from "react";
import { preloadWebVideo } from "react-video-trimmer";
// It is a function, no other process is required
preloadWebVideo();
MIT
This library uses the work of the guys at ffmpeg-webworker