camera录制视频的缩略图获取原理心得分享
更新时间:2013年06月02日 17:01:18 作者:
camera录制的视频的缩略图如何获取,想必有很多的朋友都不会吧,下面与大家分享下获取的原理,感兴趣的你可不要错过了哈
1、在thumbnail.java文件里通过调用bitmap = retriever.getFrameAtTime(-1);
这句代码得到bitmap,
2、那么这句代码在MediaMetadataRetriever.java 中调用
getFrameAtTime(timeUs, OPTION_CLOSEST_SYNC)这句代码:
解释一下timeUs,和OPTION_CLOSEST_SYNC这2个变量的含义
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.由于timeUs等于-1,那么在stagefrightMetadataRetriver.cpp中通过
extractVideoFrameWithCodecFlags()函数
if (frameTimeUs < 0) {
if (!trackMeta->findInt64(kKeyThumbnailTime, &thumbNailTime)
|| thumbNailTime < 0) {
thumbNailTime = 0;
}
options.setSeekTo(thumbNailTime, mode);
}else{
...................
}
取得thumbnailTime,
thumbnailTime是取同步帧中最大一帧数据,即有可能不是视频文件的第一个I帧。
4.extractVideoFrameWithCodecFlags()函数中,接着第3条,然后调用err = decoder->read(&buffer, &options);这句代码,其options->seekMode为SEEK_CLOSEST_SYNC这个值
5.如果video codec是mpeg4,则调用MPEG4Extractor.cpp中的read()的函数,
根据前面thumnailtime,找到此时间点的vidoe frame index,然后通过 video frame index,再找临近的同步帧(即I帧)
6.SampleTable.cpp中findSyncSampleNear()函数中,找临近同步帧,
视频文件中会存有所有的同步帧,这个同步帧也有可能是这个同步帧数组中第一个值,也有可能在第5步中得到的video frame index,也有可能位于2个同步帧之间,那么我们通过计算找到这2个同步帧最靠近video frame index的一个同步帧
7.通过上述步骤,找到同步帧,那么根据这个同步帧生成thumbnail的bitmap。
这句代码得到bitmap,
2、那么这句代码在MediaMetadataRetriever.java 中调用
getFrameAtTime(timeUs, OPTION_CLOSEST_SYNC)这句代码:
解释一下timeUs,和OPTION_CLOSEST_SYNC这2个变量的含义
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.由于timeUs等于-1,那么在stagefrightMetadataRetriver.cpp中通过
extractVideoFrameWithCodecFlags()函数
复制代码 代码如下:
if (frameTimeUs < 0) {
if (!trackMeta->findInt64(kKeyThumbnailTime, &thumbNailTime)
|| thumbNailTime < 0) {
thumbNailTime = 0;
}
options.setSeekTo(thumbNailTime, mode);
}else{
...................
}
取得thumbnailTime,
thumbnailTime是取同步帧中最大一帧数据,即有可能不是视频文件的第一个I帧。
4.extractVideoFrameWithCodecFlags()函数中,接着第3条,然后调用err = decoder->read(&buffer, &options);这句代码,其options->seekMode为SEEK_CLOSEST_SYNC这个值
5.如果video codec是mpeg4,则调用MPEG4Extractor.cpp中的read()的函数,
根据前面thumnailtime,找到此时间点的vidoe frame index,然后通过 video frame index,再找临近的同步帧(即I帧)
6.SampleTable.cpp中findSyncSampleNear()函数中,找临近同步帧,
视频文件中会存有所有的同步帧,这个同步帧也有可能是这个同步帧数组中第一个值,也有可能在第5步中得到的video frame index,也有可能位于2个同步帧之间,那么我们通过计算找到这2个同步帧最靠近video frame index的一个同步帧
7.通过上述步骤,找到同步帧,那么根据这个同步帧生成thumbnail的bitmap。
相关文章
Android开发之拖动条/滑动条控件、星级评分控件功能的实例代码
这篇文章主要介绍了Android开发之拖动条/滑动条控件、星级评分控件功能的实例代码,需要的朋友可以参考下2019-05-05
Android关于Glide的使用(高斯模糊、加载监听、圆角图片)
这篇文章主要为大家详细介绍了Android关于Glide的使用,内容丰富,高斯模糊、加载监听、圆角图片希望大家可以掌握,感兴趣的小伙伴们可以参考一下2016-11-11
Android开发Jetpack组件Lifecycle使用篇
这一篇文章来介绍Android Jetpack架构组件的Lifecycle; Lifecycle用于帮助开发者管理Activity和Fragment 的生命周期, 由于Lifecycle是LiveData和ViewModel的基础;所以需要先学习它2022-08-08


最新评论