Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get last received statistics #139

Closed
shiv71 opened this issue Aug 27, 2021 · 8 comments
Closed

Get last received statistics #139

shiv71 opened this issue Aug 27, 2021 · 8 comments
Assignees
Labels
android Affect Android platform apple Affect Apple platforms bug Something isn't working fixed-in-v4.5 Fixed in release v4.5 library Affects the library mobile-ffmpeg Originates from MobileFFmpeg question Further information is requested v4.4 Affects v4.4 release

Comments

@shiv71
Copy link

shiv71 commented Aug 27, 2021

Is any method in FFmpegKit like below to get last received statistics in android
Statistics statistics = Config.getLastReceivedStatistics(); this is in mobile-ffmpeg library

@tanersener
Copy link
Collaborator

See the Migrating From MobileFFmpeg Android API wiki page.

Config.getLastReceivedStatistics() can be replaced with FFmpegKitConfig.getLastSession().getLastReceivedStatistics().

@tanersener tanersener added android Affect Android platform library Affects the library mobile-ffmpeg Originates from MobileFFmpeg question Further information is requested v4.4 Affects v4.4 release labels Aug 27, 2021
@tanersener tanersener self-assigned this Aug 27, 2021
@shiv71 shiv71 closed this as completed Sep 1, 2021
@shiv71
Copy link
Author

shiv71 commented Sep 1, 2021

I am using this library : com.arthenica:ffmpeg-kit-min:4.4.LTS
I have checked both methods but not find the getLastReceivedStatistics() method

FFmpegKitConfig.getLastSession().getLastReceivedStatistics()
FFmpegKitConfig.getLastCompletedSession().getLastReceivedStatistics()

getLastSession() method return Session class object and getLastReceivedStatistics() not exist in this class.
I have check in library code getLastReceivedStatistics() method exist in the FFmpegSession class.

@shiv71 shiv71 reopened this Sep 1, 2021
@tanersener
Copy link
Collaborator

You're right. Statistics is a feature provided for FFmpeg sessions only. And, getLastSession() returns a Session. So, that call will give you a compiler warning. Can you try by casting getLastSession() to FFmpegSession first?

((FFmpegSession)FFmpegKitConfig.getLastSession()).getLastReceivedStatistics()

@shiv71
Copy link
Author

shiv71 commented Sep 3, 2021

Statistics statistics = ((FFmpegSession)FFmpegKitConfig.getLastSession()).getLastReceivedStatistics();

This is not working it's returning null.

@tanersener
Copy link
Collaborator

tanersener commented Sep 4, 2021

If ffmpeg generates statistics for your command that statement will return it. If it returns null that means that ffmpeg didn't generate statistics.

Besides, if you suspect something is not working as expected then you need to provide more details e.g. logs.

@shiv71
Copy link
Author

shiv71 commented Sep 6, 2021

Statistics statistics = ((FFmpegSession)FFmpegKitConfig.getLastSession()).getLastReceivedStatistics();
I have debugged the code and it's returning statistics value but returning the same value.

Logs :

I/ffmpeg-kit: frame=    1 fps=0.0 q=7.8 size=       0kB time=00:00:00.09 bitrate=   3.8kbits/s speed=1.77x    
I/ffmpeg-kit: frame=    7 fps=0.0 q=6.7 size=     512kB time=00:00:00.37 bitrate=11290.6kbits/s speed=0.639x    
I/ffmpeg-kit: frame=   15 fps= 13 q=10.9 size=     768kB time=00:00:00.60 bitrate=10421.7kbits/s speed=0.514x    
I/ffmpeg-kit: frame=   23 fps= 14 q=6.3 size=     768kB time=00:00:00.88 bitrate=7130.7kbits/s speed=0.524x    
I/ffmpeg-kit: frame=   33 fps= 15 q=6.2 size=    1024kB time=00:00:01.20 bitrate=6947.7kbits/s speed=0.551x    
I/ffmpeg-kit: frame=   44 fps= 16 q=8.0 size=    1536kB time=00:00:01.57 bitrate=7969.4kbits/s speed=0.583x    
I/ffmpeg-kit: frame=   55 fps= 17 q=7.7 size=    1792kB time=00:00:01.95 bitrate=7526.6kbits/s speed=0.602x    
I/ffmpeg-kit: frame=   67 fps= 18 q=7.6 size=    2304kB time=00:00:02.32 bitrate=8128.7kbits/s speed=0.621x    
I/ffmpeg-kit: frame=   78 fps= 18 q=7.9 size=    2560kB time=00:00:02.73 bitrate=7654.1kbits/s speed=0.642x    
I/ : ffmpeg-kit: frame=   89 fps= 19 q=9.1 size=    3072kB time=00:00:03.06 bitrate=8210.7kbits/s speed=0.642x    
I/ffmpeg-kit: frame=  100 fps= 19 q=6.6 size=    3328kB time=00:00:03.43 bitrate=7933.3kbits/s speed=0.65x    
I/ffmpeg-kit: frame=  111 fps= 19 q=7.4 size=    3584kB time=00:00:03.80 bitrate=7710.1kbits/s speed=0.656x    
I/ffmpeg-kit: frame=  122 fps= 19 q=7.5 size=    4096kB time=00:00:04.17 bitrate=8028.2kbits/s speed=0.662x    
I/ffmpeg-kit: frame=  134 fps= 20 q=7.3 size=    4352kB time=00:00:04.55 bitrate=7833.7kbits/s speed=0.665x    
I/ffmpeg-kit: frame=  145 fps= 20 q=5.3 size=    4864kB time=00:00:04.92 bitrate=8094.5kbits/s speed=0.669x  

Statistics :

E/Statistics: Statistics{sessionId=4, videoFrameNumber=1, videoFps=0.0, videoQuality=0.0, size=44, time=92, bitrate=3.789836347975883, speed=1.770424293624621}
E/Statistics: Statistics{sessionId=4, videoFrameNumber=1, videoFps=0.0, videoQuality=0.0, size=44, time=92, bitrate=3.789836347975883, speed=1.770424293624621}
E/Statistics: Statistics{sessionId=4, videoFrameNumber=1, videoFps=0.0, videoQuality=0.0, size=44, time=92, bitrate=3.789836347975883, speed=1.770424293624621}
E/Statistics: Statistics{sessionId=4, videoFrameNumber=1, videoFps=0.0, videoQuality=0.0, size=44, time=92, bitrate=3.789836347975883, speed=1.770424293624621}
E/Statistics: Statistics{sessionId=4, videoFrameNumber=1, videoFps=0.0, videoQuality=0.0, size=44, time=92, bitrate=3.789836347975883, speed=1.770424293624621}
E/Statistics: Statistics{sessionId=4, videoFrameNumber=1, videoFps=0.0, videoQuality=0.0, size=44, time=92, bitrate=3.789836347975883, speed=1.770424293624621}
E/Statistics: Statistics{sessionId=4, videoFrameNumber=1, videoFps=0.0, videoQuality=0.0, size=44, time=92, bitrate=3.789836347975883, speed=1.770424293624621}
E/Statistics: Statistics{sessionId=4, videoFrameNumber=1, videoFps=0.0, videoQuality=0.0, size=44, time=92, bitrate=3.789836347975883, speed=1.770424293624621}
E/Statistics: Statistics{sessionId=4, videoFrameNumber=1, videoFps=0.0, videoQuality=0.0, size=44, time=92, bitrate=3.789836347975883, speed=1.770424293624621}
E/Statistics: Statistics{sessionId=4, videoFrameNumber=1, videoFps=0.0, videoQuality=0.0, size=44, time=92, bitrate=3.789836347975883, speed=1.770424293624621}
E/Statistics: Statistics{sessionId=4, videoFrameNumber=1, videoFps=0.0, videoQuality=0.0, size=44, time=92, bitrate=3.789836347975883, speed=1.770424293624621}
E/Statistics: Statistics{sessionId=4, videoFrameNumber=1, videoFps=0.0, videoQuality=0.0, size=44, time=92, bitrate=3.789836347975883, speed=1.770424293624621}
E/Statistics: Statistics{sessionId=4, videoFrameNumber=1, videoFps=0.0, videoQuality=0.0, size=44, time=92, bitrate=3.789836347975883, speed=1.770424293624621}
E/Statistics: Statistics{sessionId=4, videoFrameNumber=1, videoFps=0.0, videoQuality=0.0, size=44, time=92, bitrate=3.789836347975883, speed=1.770424293624621}
E/Statistics: Statistics{sessionId=4, videoFrameNumber=1, videoFps=0.0, videoQuality=0.0, size=44, time=92, bitrate=3.789836347975883, speed=1.770424293624621}
E/Statistics: Statistics{sessionId=4, videoFrameNumber=1, videoFps=0.0, videoQuality=0.0, size=44, time=92, bitrate=3.789836347975883, speed=1.770424293624621}
E/Statistics: Statistics{sessionId=4, videoFrameNumber=1, videoFps=0.0, videoQuality=0.0, size=44, time=92, bitrate=3.789836347975883, speed=1.770424293624621}
E/Statistics: Statistics{sessionId=4, videoFrameNumber=1, videoFps=0.0, videoQuality=0.0, size=44, time=92, bitrate=3.789836347975883, speed=1.770424293624621}

I am using statistics for calculation progress. Below is my code.

 final Handler handler = new Handler();
        final int delay = 200; // 1000 milliseconds == 1 second

        handler.postDelayed(new Runnable() {
            public void run() {
                Statistics statistics = ((FFmpegSession)FFmpegKitConfig.getLastSession()).getLastReceivedStatistics();
                int progress = 0;
                if (statistics != null){
                    Log.e("Statistics", statistics.toString());
                }

                if (statistics != null && statistics.getSessionId() == executionId) {
                    try {
                       // calculating the compression progress
                        progress = (int) ((statistics.getTime() / Double.parseDouble(duration)) / 10);
                        int pro = progress + bgPostDataModel.getCurrentBarLength();
                        if (pro <= 100) {
                            String remainingTime = BGUtils.calculateRemeaningTime(statistics.getTime(), ((long) Double.parseDouble(duration)) * 1000, compressionStartedTime, BGState.COMPRESSING);

                            sendBroadcastMsg(true, uploading, progress + bgPostDataModel.getCurrentBarLength(), false, remainingTime);
                            uploadProgressNotification.updateProcess(progress + bgPostDataModel.getCurrentBarLength(), remainingTime);
                        }


                    } catch (Exception e) {

                    }
                }
                if (!isCompressionComplete && progress < 100)
                    handler.postDelayed(this, delay);
            }
        }, delay);

@tanersener tanersener added this to To Do in FFmpegKit 21.07 GA Release via automation Sep 7, 2021
@tanersener tanersener added the bug Something isn't working label Sep 7, 2021
@tanersener
Copy link
Collaborator

Thanks. It seems like there is a bug there.

Can you use the following snippet until it is fixed.

List<Statistics> statisticsList = ((FFmpegSession) FFmpegKitConfig.getLastSession()).getStatistics();
statisticsList.get(statisticsList.size() - 1);

@tanersener tanersener added the apple Affect Apple platforms label Sep 15, 2021
@tanersener tanersener moved this from To Do to Done in FFmpegKit 21.07 GA Release Sep 15, 2021
@tanersener
Copy link
Collaborator

Fixed in the development branch.

@tanersener tanersener added the fixed-on-development Fixed on the development branch. Not released yet. label Sep 15, 2021
@tanersener tanersener added fixed-in-v4.5 Fixed in release v4.5 and removed fixed-on-development Fixed on the development branch. Not released yet. labels Sep 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
android Affect Android platform apple Affect Apple platforms bug Something isn't working fixed-in-v4.5 Fixed in release v4.5 library Affects the library mobile-ffmpeg Originates from MobileFFmpeg question Further information is requested v4.4 Affects v4.4 release
Projects
No open projects
Development

No branches or pull requests

2 participants