FFmpegMediaMetadataRetriever icon indicating copy to clipboard operation
FFmpegMediaMetadataRetriever copied to clipboard

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

Open masterwok opened this issue 6 years ago • 13 comments

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.

masterwok avatar Aug 13 '18 04:08 masterwok

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.

HBiSoft avatar Sep 09 '18 12:09 HBiSoft

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.

masterwok avatar Sep 10 '18 04:09 masterwok

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?

HBiSoft avatar Sep 10 '18 04:09 HBiSoft

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.

masterwok avatar Sep 10 '18 05:09 masterwok

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.

HBiSoft avatar Sep 10 '18 05:09 HBiSoft

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.

masterwok avatar Sep 10 '18 05:09 masterwok

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

HBiSoft avatar Sep 10 '18 05:09 HBiSoft

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.

HBiSoft avatar Sep 10 '18 05:09 HBiSoft

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.

masterwok avatar Sep 10 '18 05:09 masterwok

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

HBiSoft avatar Sep 10 '18 05:09 HBiSoft

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.

masterwok avatar Sep 10 '18 06:09 masterwok

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

wseemann avatar Sep 24 '18 07:09 wseemann

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

masterwok avatar Sep 24 '18 07:09 masterwok