栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 移动开发 > Android

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

Android 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

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。
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/165194.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号