Git Product home page Git Product logo

react-video-trimmer's Introduction

react-video-trimmer

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.

Demo

See Demo

Installation

npm install --save react-video-trimmer

or:

yarn add react-video-trimmer

Usage

NOTE: Do import the styles from react-video-trimmer/dist/style.css

import ReactVideoTrimmer from "react-video-trimmer";
<div>
  <ReactVideoTrimmer timeLimit={20} showEncodeBtn />
</div>;

Props

timeRange: Number

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>
  );
};

onVideoEncode: function

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>
  );
};

loadingFFMPEGText: string

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>
  );
};

React Ref

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>
  );
};

Methods

handleFFMPEGStdout: void

A listener to ffmpeg-webworker FFMPEGStdout event

handleFFMPEGReady: void

A listener to ffmpeg-webworker FFMPEGReady event

handleFFMPEGFileReceived: void

A listener to ffmpeg-webworker FFMPEGFileReceived event

handleFFMPEGDone: void

A listener to ffmpeg-webworker FFMPEGDone event

Converts the returned result into a Blob, before updating the video player

decodeVideoFile: void

params
  • file: Blob A Blob/File with type matching video/*
  • doneCB: function Called after the decode action is completed

handleFileSelected: void

Called when a valid video file is selected, in turn calls decodeVideoFile for proper handling

params
  • file: Blob A Blob/File with type matching video/*

handleEncodeVideo: void

Called when a valid video file is selected, in turn calls decodeVideoFile for proper handling

params
  • file: Blob A Blob/File with type matching video/*

handleDownloadVideo: void

Handler for the Download button onClick event. Downloads the converted video file

params
  • encodedVideo: Blob Encoded video data converted to Blob

Preloading ffmpeg

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();

License

MIT

Credit

This library uses the work of the guys at ffmpeg-webworker

react-video-trimmer's People

Contributors

limistah avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.