How camera video thumbnails are obtained

Source: Internet
Author: User

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.