camera录制的视频的缩略图的获取原理 android

本文详细介绍了从视频文件中提取代表性缩略图的过程,包括如何使用MediaMetadataRetriever类选择时间位置,以及在不同层级源码中实现同步帧检索的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值