wseemann / FFmpegMediaMetadataRetriever

FFmpegMediaMetadataRetriever provides a unified interface for retrieving frame and meta data from an input media file.
1.73k stars 387 forks source link

Negative time passed to getFrameAtTime(..) returns black Bitmap only for some media #187

Closed masterwok closed 1 year ago

masterwok commented 6 years ago

For some media, getFrameAtTime(..) returns an all black bitmap when supplied a negative value for timeUs. This is only occurring with media where Android's MediaMetadataRetriever would fail to retrieve a frame. When I supply a non-negative position for the same media it works great. I would expect it to retrieve a non-black bitmap.

HBiSoft commented 6 years ago

Why would you want to pass a negative time stamp. AFAIK time starts at 0. It doesn't make sence, at all, passing a negative value.

masterwok commented 6 years ago

The documentation for MediaMetadataRetriever.getFrameAtTime(..) states the following:

If timeUs is negative, time position and option will ignored, and any frame that the implementation considers as representative may be returned.

Passing a negative value is useful when you want the retriever to determine the frame without specifying a time.

HBiSoft commented 6 years ago

I just can't think why you would want to do that? Also, you mentioned - This is only occurring with media where Android's MediaMetadataRetriever would fail to retrieve a frame. Can you please provide a code snippet?

masterwok commented 6 years ago

For my original use case, I was streaming a video file sequentially. Using a calculated time based on percentage complete and total time of the video might not guarantee a valid position. In this case, it was preferable to not have to pass a non-negative time. Note that when testing the negative time, I was using it against fully downloaded files and still getting all black bitmaps so this doesn't relate to partial files.

I don't have a code snippet/sample project that demonstrates this, but simply calling retriever.getFrameAtTime(-1) for some video where Android's MediaMetadataRetriever fails will return an all black bitmap.

In the end, I ended up just using the time at some percentage of the video file and so far it seems to work fine. However I still think this is a valid issue because regardless it shouldn't be returning a black bitmap if it wants to be one-to-one with the Android MediametadataRetriever.

HBiSoft commented 6 years ago

Ok, that makes more sense. When you say - for some video where Android's MediaMetadataRetriever fails will return an all black bitmap. do you mean that you first run MediaMetadataRetriever then FFmpegMediaMetadataRetriever and when MediaMetadataRetriever fails then you get a black frame? If this is the case, then it would be expected and the issue is then with MediaMetadataRetriever and not FFmpegMediaMetadataRetriever.

masterwok commented 6 years ago

No, I meant when MediaMetadataRetriever fails to produce a bitmap by returning null for some video, it is an indicator that the video file itself will result in a black bitmap when run through FFmpegmediaMetadataRetriever with a negative time. Not all video files will result in a black bitmap when getting a frame with a negative time using FFmpegmediaMetadataRetriever.

HBiSoft commented 6 years ago

Ok but if MediaMetadataRetriever and FFmpegmediaMetadataRetriever fails with the same file then the issue is not with FFmpegmediaMetadataRetriever?

HBiSoft commented 6 years ago

You also mentioned - However I still think this is a valid issue because regardless it shouldn't be returning a black bitmap if it wants to be one-to-one with the Android MediametadataRetriever., but this is implemented with this library, I just tested it (passing a negative value).

This is not a issue with FFmpegmediaMetadataRetriever, if both fail with the same file then the issue is with the file itself.

masterwok commented 6 years ago

I should clarify that when passing any time value to Android's MediaMetadataRetriever, it fails with a null bitmap and logs an error out to the console.

When using FFmpegMediaMetadataRetriever with a negative time, it fails with a black bitmap and no error logged out. When passed a valid positive time for the same media, it successfully pulls a bitmap so the issue is with the negative time.

HBiSoft commented 6 years ago

This is confusing....... MediaMetadataRetriever fails but FFmpegMediaMetadataRetriever should be successful?

masterwok commented 6 years ago

Sorry if this is confusing, maybe just forget I mentioned MediaMetadataRetriever.

The issue is passing negative time to FFmpegMediaMetadataRetriever produces a black bitmap while passing a positive value for the same media produces a bitmap as expected. If I remember correctly, I experienced this when working with any AVI file.

wseemann commented 6 years ago

Can you provide a sample video or url for me to test with?

masterwok commented 6 years ago

Sure thing, I'll try to get to it in the next day or so.