react-native-ffmpeg icon indicating copy to clipboard operation
react-native-ffmpeg copied to clipboard

Progress bar compression

Open issamabdelkrim opened this issue 7 years ago • 9 comments

Hello everyone I use ffmpeg to compress video , but i have a progress bar that indicate the state of compres . How i can get the percent of compres . Can anyone help me thanks a lot .

issamabdelkrim avatar Oct 30 '19 15:10 issamabdelkrim

You need to set a statistics callback and calculate the percentage yourself inside the statistics callback block.

statisticsCallback = (statisticsData) => {
    console.log('Statistics; frame: ' + statisticsData.videoFrameNumber.toFixed(1) + ', fps: ' + statisticsData.videoFps.toFixed(1) + ', quality: ' + statisticsData.videoQuality.toFixed(1) +
    ', size: ' + statisticsData.size + ', time: ' + statisticsData.time);
};
...
RNFFmpeg.enableStatisticsCallback(this.statisticsCallback);

tanersener avatar Oct 31 '19 21:10 tanersener

@tanersener thanks for your response for statisticsData.size it's the size that compressed ?

issamabdelkrim avatar Oct 31 '19 21:10 issamabdelkrim

Yes, it is the new size of the file. You'll see that it is very small in the beginning and grows over time.

tanersener avatar Nov 01 '19 08:11 tanersener

@tanersener first of all, thanks for this outstanding, so easy implementation of this library for a so complex issue, it is working great in both platforms, god bless you man!

we are getting the info during compression: Stats: {"videoFps":22.998626708984375,"videoFrameNumber":545,"speed":0.7625134705987272,"size":1310768,"videoQuality":4,"time":18069,"bitrate":580.3282279428909,"executionId":3005}

but we don't know how to calculate the percentage/progress of the compression with this info.

Any help will be aprecciated :)

matamicen avatar Oct 27 '20 14:10 matamicen

Find the duration of your input video. Divide the time value with that duration and that will be the percentage/progress.

tanersener avatar Oct 27 '20 17:10 tanersener

Thanks @tanersener , I thougth time was the compression elapsed time and not the compressed video timecode :) Great!

matamicen avatar Oct 28 '20 14:10 matamicen

Sorry for digging up this old thread! And first of all, couldn't agree more with matamicen, thank you so much for providing this library @tanersener!

I might be stretching things a bit, but I was wondering if it was possible to get statistics on multiple parallel ffmpeg processes.

To illustrate what I mean: If I am kicking off multiple ffmpeg jobs similar to this:

    let [result1, result2] = await Promise.all([
        RNFFmpeg.execute(command1),
        RNFFmpeg.execute(command2)
    ])

and have a statistics callback such as the following enabled:

    const statisticsCallback = (statisticsData: Statistics) => {
        console.log(statisticsData)
    }

    RNFFmpegConfig.enableStatisticsCallback(statisticsCallback)

I will receive statistics from both of the jobs - but I can't tell which of the jobs a particular callback invocation is associated with.

This makes it kinda hard to show a percentage (for the individual jobs but also an overall percentage). Is there a way to know which ffmpeg job is responsible for the invocation of the stats callback?

fabschn avatar Apr 15 '21 19:04 fabschn

@fabschn You must use RNFFmpeg.executeAsync method to start an ffmpeg job. This method will give you a unique executionId.

Statistics received by statisticsCallback also includes an executionId field. You can compare these two executionId values and understand which statistics belongs to which command.

tanersener avatar Apr 15 '21 21:04 tanersener

Thanks a lot for the quick reply, @tanersener!

And thanks for the pointers, I noticed that I had a quite old version included in my project that didn't have executeAsync available. After upgrading and a bit of rewriting, the approach you described works like a charm.

Again, thanks a lot for your help and this library!

fabschn avatar Apr 18 '21 18:04 fabschn