UNPKG

use-ffmpeg

Version:

A React hook for browser-based media processing using FFmpeg WASM - handles video and other file formats conversion with ease

82 lines (77 loc) 2.79 kB
import React from 'react'; interface UseFFmpeg { loaded: boolean; loadFFmpeg: (baseUrl?: string, mt?: boolean) => Promise<void>; transcode: ( file: File, outputFileFullName: string, cmdOptions?: string[], ) => Promise<{ url: string; fileSize: string }>; } /** * FFmpegContextProvider is a React component that wraps the application and provides * the FFmpeg hook using context. This provider must be placed higher in the component tree * where the `useFFmpeg` hook needs access to FFmpeg functionality. * * @param {React.PropsWithChildren} props - The props to be passed to the children components. * @returns {React.ReactNode} - The wrapped children components with the FFmpeg context provided. * * @example * <FFmpegContextProvider> * <YourComponent /> * </FFmpegContextProvider> */ declare const FFmpegContextProvider: (props: React.PropsWithChildren) => React.JSX.Element; /** * Custom hook to access the FFmpeg context value. * If the context is not available (i.e., the hook is called outside the provider), * it will fallback to using the base `useFFmpeg` hook directly. * * @returns {UseFFmpeg} - The FFmpeg hook, providing FFmpeg functionality and methods. * * @throws {Error} - Throws an error if the hook is used outside of the FFmpegContextProvider * and the fallback logic is not invoked (since the base hook will be used in that case). * * @example * const ffmpeg = useFFmpeg(); * ffmpeg.load(); // Example usage */ declare const useFFmpeg: () => UseFFmpeg; declare const mimeTypes: { readonly video: { readonly mp4: "video/mp4"; readonly webm: "video/webm"; readonly mkv: "video/x-matroska"; readonly mov: "video/quicktime"; readonly avi: "video/x-msvideo"; readonly flv: "video/x-flv"; readonly ts: "video/MP2T"; readonly ogv: "video/ogg"; readonly asf: "video/x-ms-asf"; readonly "3gp": "video/3gpp"; readonly rm: "application/vnd.rn-realmedia"; }; readonly audio: { readonly mp3: "audio/mpeg"; readonly wav: "audio/x-wav"; readonly aac: "audio/aac"; readonly flac: "audio/flac"; readonly ogg: "audio/ogg"; readonly m4a: "audio/mp4"; readonly wma: "audio/x-ms-wma"; readonly amr: "audio/amr"; readonly opus: "audio/opus"; }; readonly image: { readonly png: "image/png"; readonly jpeg: "image/jpeg"; readonly jpg: "image/jpeg"; readonly gif: "image/gif"; readonly svg: "image/svg+xml"; readonly webp: "image/webp"; readonly bmp: "image/bmp"; readonly tiff: "image/tiff"; readonly ico: "image/x-icon"; }; }; export { FFmpegContextProvider, type UseFFmpeg, mimeTypes, useFFmpeg };