1. In the thumbnail. java file, call bitmap = retriever. getFrameAtTime (-1 );
This code returns bitmap,
2. The code is called in MediaMetadataRetriever. java.
The Code getFrameAtTime (timeUs, OPTION_CLOSEST_SYNC) is as follows:
Explain the meanings of timeUs and OPTION_CLOSEST_SYNC.
TimeUs The time position where the frame will be retrieved.
* When retrieving the frame at the given time position, there is no
* Guarentee that the data source has a frame located at the position.
* When this happens, a frame nearby will be returned. If timeUs is
* Negative, time position and option will ignored, and any frame
* That the implementation considers as representative may be returned
3. Because timeUs is equal to-1
ExtractVideoFrameWithCodecFlags () functionCopy codeThe Code is as follows: if (frameTimeUs <0 ){
If (! TrackMeta-> findInt64 (kKeyThumbnailTime, & thumbNailTime)
| ThumbNailTime <0 ){
ThumbNailTime = 0;
}
Options. setSeekTo (thumbNailTime, mode );
} Else {
...................
}
Obtain thumbnailTime,
ThumbnailTime is the largest frame of data in the synchronous frame, that is, it may not be the first I frame of the video file.
4. in the extractVideoFrameWithCodecFlags () function, go to the second line, and then call the err = decoder-> read (& buffer, & options); Code, whose options-> seekMode is SEEK_CLOSEST_SYNC.
5. If video codec is mpeg4, call the read () function in MPEG4Extractor. cpp,
Based on the previous thumnailtime, locate the vidoe frame index at this time point, and then use the video frame index to find the adjacent synchronous frame (that is, I frame)
6. In the findSyncSampleNear () function of SampleTable. cpp, locate the adjacent synchronous frame,
The video file contains all the synchronized frames. This synchronized frame may also be the first value in the number of synchronized frames, or the video frame index obtained in step 1, it may also be located between two synchronous frames, so we can find a synchronous frame closest to the video frame index through calculation.
7. After finding the synchronous frame through the above steps, the bitmap of thumbnail is generated based on the synchronous frame.