当前位置: 移动技术网 > 移动技术>移动开发>Android > camera录制视频的缩略图获取原理心得分享

camera录制视频的缩略图获取原理心得分享

2019年07月24日  | 移动技术网移动技术  | 我要评论
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。

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网