录制的视频中的缩略图 (Thumbnail)是怎样产生的?
时间:10-02
整理:3721RD
点击:
[DESCRIPTION]
介绍CAMERA录制的视频的缩略图的获取原理
[SOLUTION]
在thumbnail.java文件里通过如下调用即可得到bitmap。
bitmap = retriever.getFrameAtTime(0); //找到视频文件中第一个同步帧(即I帧)
bitmap = retriever.getFrameAtTime(-1); //找到同步帧中最大一帧数据,即有可能不是视频文件的第一个同步帧
下面具体介绍下函数:public Bitmap getFrameAtTime(long timeUs)
谷歌对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.
在stagefrightMetadataRetriver.cpp中的extractVideoFrameWithCodecFlags()函数里有下面代码;
if (frameTimeUs < 0) {
if (!trackMeta->findInt64(kKeyThumbnailTime, &thumbNailTime)
|| thumbNailTime < 0) {
thumbNailTime = 0;
}
options.setSeekTo(thumbNailTime, mode);
}else{
...................
}
由于timeUs等于-1,所以取的是thumbnailTime,即kKeyThumbnailTime,对于不同extractor取值都不同。
若是MP4/3GP文件,是取前20个同步帧中最大一帧数据,即有可能不是视频文件的第一个同步帧。
介绍CAMERA录制的视频的缩略图的获取原理
[SOLUTION]
在thumbnail.java文件里通过如下调用即可得到bitmap。
bitmap = retriever.getFrameAtTime(0); //找到视频文件中第一个同步帧(即I帧)
bitmap = retriever.getFrameAtTime(-1); //找到同步帧中最大一帧数据,即有可能不是视频文件的第一个同步帧
下面具体介绍下函数:public Bitmap getFrameAtTime(long timeUs)
谷歌对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.
在stagefrightMetadataRetriver.cpp中的extractVideoFrameWithCodecFlags()函数里有下面代码;
if (frameTimeUs < 0) {
if (!trackMeta->findInt64(kKeyThumbnailTime, &thumbNailTime)
|| thumbNailTime < 0) {
thumbNailTime = 0;
}
options.setSeekTo(thumbNailTime, mode);
}else{
...................
}
由于timeUs等于-1,所以取的是thumbnailTime,即kKeyThumbnailTime,对于不同extractor取值都不同。
若是MP4/3GP文件,是取前20个同步帧中最大一帧数据,即有可能不是视频文件的第一个同步帧。
