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

getFrameAtTime returning the same frame #45

Closed
maxandron opened this issue Mar 26, 2015 · 7 comments
Closed

getFrameAtTime returning the same frame #45

maxandron opened this issue Mar 26, 2015 · 7 comments

Comments

@maxandron
Copy link

Hello,

What I'm trying to do, is capture a video and then play it frame-by-frame.
The way I decided to do this is load the video into your library, and using a SeekBar change the "Preview" image.

The first problem I encountered was the duration I received was always 0. After playing around with this for a little bit, I found that the library returns only duration in multiplications of a thousand. (0-1000-2000-etc).

When I try getting frames using getFrameAtTime - I get the same frame and not actual frames from the video.

At first I thought the problem was relating to the video being time lapsed (using setCaptureRate) - but after removing this option it didn't change much.
When pulling the video to my computer it plays fine and recognized as MPEG format.

What could be the problem?

Here is the extraction code:

// Set the media player with the video
final FFmpegMediaMetadataRetriever metadataRetriever =
        new FFmpegMediaMetadataRetriever();
final SeekBar videoSeek = (SeekBar) view.findViewById(R.id.video_seek);
videoSeek.bringToFront();

Log.d(TAG, mMediaFilepath);
metadataRetriever.setDataSource(mMediaFilepath);
String duration = metadataRetriever
        .extractMetadata(FFmpegMediaMetadataRetriever.METADATA_KEY_DURATION);

Log.d(TAG, "Duration = " + duration);
mediaPreview.setImageBitmap(metadataRetriever.getFrameAtTime(0));

videoSeek.setMax(Integer.parseInt(duration));

// Set the seek bar actions
videoSeek.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
    @Override
    public void onProgressChanged(SeekBar seekBar, int progress,
                                  boolean fromUser) {
        Bitmap bm2 = metadataRetriever.getFrameAtTime();
        Bitmap bm = metadataRetriever.getFrameAtTime(progress,
                FFmpegMediaMetadataRetriever.OPTION_CLOSEST);
        if (bm == null || bm2 == null) {
            Log.e(TAG, "bm is null");
        }
        mediaPreview.setImageBitmap(bm);
    }

    @Override
    public void onStartTrackingTouch(SeekBar seekBar) {
    }

    @Override
    public void onStopTrackingTouch(SeekBar seekBar) {
    }
});

One thing to note:
the function never return's a null value - just the same bitmap all over again.

Thank you,
Ron.

P.S.: Here is a link to the video just in case it will help you: https://drive.google.com/file/d/0B50D54gw1jgHT25rQ0ZuRFc5cFk/view?usp=sharing

@shukob
Copy link

shukob commented Mar 29, 2015

This is very confusing, but getFrameAtTime takes Us instead of ms for time parameter, so you may success by passing progress*1000 for it.

@maxandron
Copy link
Author

Yes I tried that, but still the same frame is showing.
I'm going another way now, but I would still love to hear a solution in case it helps someone else

@wseemann
Copy link
Owner

wseemann commented Apr 4, 2015

As skonb said, you aren't passing the correct unit of time to getFrameAtTime. If you are still having problems please email me a link to the file in question so I can test myself.

@wseemann wseemann closed this as completed Apr 4, 2015
@maxandron
Copy link
Author

And as I said, I tried passing everything *1000 and it made no difference.

@wseemann
Copy link
Owner

wseemann commented Apr 4, 2015

As I said, send me a link to the video so I can test myself, otherwise I
have no way of debugging your issue.
On Apr 4, 2015 5:41 PM, "Ron Suhodrev" notifications@github.com wrote:

And as I said, I tried passing everything *1000 and it made no difference.


Reply to this email directly or view it on GitHub
#45 (comment)
.

@maxandron
Copy link
Author

I did attach a link in the first post.

@clementiano9
Copy link

As skonb said, you aren't passing the correct unit of time to getFrameAtTime. If you are still having problems please email me a link to the file in question so I can test myself.

Please what is the actual time unit the method should receive?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants