Android extracts multiple pictures and video information examples

The live broadcast in 2016 was quite popular, and the short video was popular again in 2017. But for developers, the technology behind this is what we care about. After all, we rely on technology.

Now in Android, multimedia services are relatively powerful, and it is necessary to learn the basic video processing technology related to video. Some time ago, I was also doing some requirements for video, and of course, it also involves the title of this article.

After testing and research, it is found that the only method to extract video images in Android is mediametadataretriever, which is reliable, simple and practical. Of course, OpenGL - can also do it! (the latter is not introduced),

Finally, the complete demo will be presented.

design sketch

Technical requirements

investigation and research

Let's first look at the third question, which is relatively simple. It is mainly the system API class mediametadataretriever.

Given a media file, it can retrieve / output some metadata and frames. It's interesting. It loads the dynamic library media_ JNI, it can be seen that it is a class very close to the bottom.

Technology implementation - acquisition of basic video information

Look at the class structure. There are some constants. As a first-line code farmer, I know you.

I simply wrote a util class myself, and finally presented it.

Technology implementation - obtain video key frames

Go straight to the code. - I know you

Directly when practical: Bitmap bitmap = extractframe (0); Filelength is the duration of the video (in milliseconds). It returns bitmap. Then you can operate the bitmap, such as saving it to an SD card. It depends on your hobby. Some people ask: Yi, how can I do this? It's like this. I've encountered that sometimes the 0 you pass in sometimes returns a null bitmap and can't find the key frame, so you need to increment it by 1 second for many times. Then the implementation of requirement 1 is OK, but one thing to note is that the width and height of the control displaying the video are the same as the width and height of the control covering the picture above, so it will be consistent when you play.

Technology implementation - obtain multiple pictures of video

I believe everyone can think of a for loop of demand one. Yes, that's right.

First, it may take time to extract a picture when encountering high-definition video. After testing, I use vivo-xplay-5a, 1080 high-definition video to extract a picture, that is, the method of mmetadataretriever. Getframeattime() is about 90-120ms.

Stop is the flag to stop extracting pictures. The extractframe method is metadataretriever. Getframeattime() to return bitmap and then bitmap. Compress () return the image path saved on the SD card. Finally, sendapic processes the extracted image path and time into an object, updates it to the UI thread with the help of the handler, and then displays it to the recycleview. For the specific code, please refer to the demo. The images saved here are not compressed, which will be discussed in detail in the second article.

Demo address: https://github.com/ta893115871/MediaMetadataRetrieverDemo

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>