wseemann / FFmpegMediaMetadataRetriever

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

getScaledFrameAtTime returns black bitmap on some videos #265

Open DeVictorVH opened 1 year ago

DeVictorVH commented 1 year ago

final FFmpegMediaMetadataRetriever retriever = new FFmpegMediaMetadataRetriever(); retriever.setDataSource(source.getPath()); final Bitmap bitmap = retriever.getScaledFrameAtTime(10000000L, width, height);

It returns black bitmap on some videos, but using a different option (FFmpegMediaMetadataRetriever.OPTION_CLOSEST, OPTION_CLOSEST_SYNC, etc) fixes it but others get the same problem;

Tested on a Redmi 9 (android 11) and Bluestacks emulator (android 7)

DeVictorVH commented 1 year ago

In your test application use the following code: Bitmap b = fmmr.getFrameAtTime(); if (b != null) { Bitmap b2 = fmmr.getFrameAtTime(4000000, FFmpegMediaMetadataRetriever.OPTION_CLOSEST_SYNC); if (b2 != null) { b = b2; } } This fixes the problem but calls getFrameAtTime() 2 times. Is this a hack and how does it work?

kyriej commented 1 year ago

same problem ,hope to solved it

wseemann commented 1 year ago

Are all of your videos greater or equal to 10000000L in length? If not, then the library is probably returning the last available frame in the video, which may be black, since your timestamp exceeds the content duration.

DeVictorVH commented 1 year ago

The duration of the videos is greater than 10000000L.

Some months ago I tried to fix the error, so I downloaded the project, started modifying the native code and if I remember correctly the problem was that FFmpeg couldn't do seek in some situations.

wseemann commented 1 year ago

That makes sense. Thanks for the reply @DeVictorVH. Sorry this library didn't quite meet your needs.

DeVictorVH commented 1 year ago

That makes sense. Thanks for the reply @DeVictorVH. Sorry this library didn't quite meet your needs.

Bitmap b = fmmr.getFrameAtTime(); if (b != null) { Bitmap b2 = fmmr.getFrameAtTime(4000000, FFmpegMediaMetadataRetriever.OPTION_CLOSEST_SYNC); if (b2 != null) { b = b2; } }

This is in the test app but I don't understand why it fixes the problem.

guiguzixiansheng commented 1 year ago

Can you let the lib avoid crash?