tanersener / react-native-ffmpeg

FFmpeg for react-native. Not maintained anymore. Superseded by FFmpegKit.
GNU General Public License v3.0
400 stars 51 forks source link

Cutting a video into frames and output each frame back into react native for processing #261

Closed AbirNadav-dev closed 2 years ago

AbirNadav-dev commented 3 years ago

Hello, I'm trying to cut a video into frames and output each frame back into react native for processing I cannot find a way to do so.

My goal here is to take a stream from inside react native and then use FFmpeg to break it into frames and perform some task upon each frame, I guess I'm doing something wrong.

This is the code im using:

let pipe1 = RNFFmpegConfig.registerNewFFmpegPipe().then(pipe => { console.log("New ffmpeg pipe: " + pipe); // return pipe console.log("🚀 ~ file: videoService.js ~ line 18 ~ pipe1 ~ pipe1", pipe1)

RNFFmpeg.execute(-i ${fileName} -vcodec png -f rawvideo -s 10*10 pipe:${pipe}, completedExecution => { if (completedExecution.returnCode === 0) { console.log("FFmpeg process completed successfully"); } else { console.log(FFmpeg process failed with rc=${completedExecution.returnCode}.); } }).then(executionId => console.log(Async FFmpeg process started with executionId ${executionId}.)); })

I'm kinda lost here, will appreciate any help!

Thanks!

kevinstubbs commented 2 years ago

Is it failing? Any error messages or exceptions? Or is it succeeding just not giving you the results you are expecting?

jaimish11 commented 2 years ago

I needed to do the same exact thing. I found two ways to do it:

Method 1 Decode an entire video and extract frames from it at a certain frame rate. let res = await RNFFmpeg.execute('-i '+videoUri + " -r 1/1 "+outputFileUri+".jpeg")

In the above statement:

Method 2 Extract particular frames from a video.

let res = await RNFFmpeg.execute("-ss "+timeInSeconds+ " -y -i "+videoUri+" -vframes 1 "+outputFileUri+".jpeg")

In the above statement:

A successful ffmpeg command will return 0 and so you can process the resulting output file urls however you want. Store them in an array, send them to different components, use them in Image components etc. A non-zero return indicates that the ffmpeg command failed.

References: https://stackoverflow.com/questions/10957412/fastest-way-to-extract-frames-using-ffmpeg https://video.stackexchange.com/questions/19873/extract-specific-video-frames

tanersener commented 2 years ago

This project will be retired. Please consider switching to FFmpegKit.