Android Camera缩率图所成的图像不是录像播放的第一帧

56 篇文章 0 订阅
2 篇文章 0 订阅

修改方法如下:
vendor/mediatek/proprietary/packages/apps/Camera2/common/src/com/mediatek/camera/common/utils/BitmapCreator.java

-            bitmap = retriever.getFrameAtTime(-1);
+            bitmap = retriever.getFrameAtTime(0);

getFrameAtTime 这个方法的参数代表啥意思?

/**
 * This method is similar to {@link #getFrameAtTime(long, int, BitmapParams)}
 * except that the device will choose the actual {@link Bitmap.Config} to use.
 *
 * @param timeUs The time position where the frame will be retrieved.
 * When retrieving the frame at the given time position, there is no
 * guarantee 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.
 *
 * @param option a hint on how the frame is found. Use
 * {@link #OPTION_PREVIOUS_SYNC} if one wants to retrieve a sync frame
 * that has a timestamp earlier than or the same as timeUs. Use
 * {@link #OPTION_NEXT_SYNC} if one wants to retrieve a sync frame
 * that has a timestamp later than or the same as timeUs. Use
 * {@link #OPTION_CLOSEST_SYNC} if one wants to retrieve a sync frame
 * that has a timestamp closest to or the same as timeUs. Use
 * {@link #OPTION_CLOSEST} if one wants to retrieve a frame that may
 * or may not be a sync frame but is closest to or the same as timeUs.
 * {@link #OPTION_CLOSEST} often has larger performance overhead compared
 * to the other options if there is no sync frame located at timeUs.
 *
 * @return A Bitmap containing a representative video frame, which can be null,
 *         if such a frame cannot be retrieved. {@link Bitmap#getConfig()} can
 *         be used to query the actual {@link Bitmap.Config}.
 *
 * @see #getFrameAtTime(long, int, BitmapParams)
 */
public @Nullable Bitmap getFrameAtTime(long timeUs, @Option int option) {
    if (option < OPTION_PREVIOUS_SYNC ||
        option > OPTION_CLOSEST) {
        throw new IllegalArgumentException("Unsupported option: " + option);
    }

    return _getFrameAtTime(timeUs, option, -1 /*dst_width*/, -1 /*dst_height*/, null);
}
@param timeUs The time position where the frame will be retrieved.
When retrieving the frame at the given time position, there is no
guarantee 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.

从上面这段注释中可以看出,如果 timeUs 参数是负数,time positionoption 参数会被忽略,可能返回可以代表这个视频的任何帧
如果 timeUs 是非负数,就优先返回 timeUs 所在帧,如果找不到就找附近的帧。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在Android播放H.265裸流,可以使用Android提供的MediaCodec API。以下是基本的步骤: 1. 创建一个MediaCodec对象,用于解码H.265视频。 ``` MediaCodec codec = MediaCodec.createDecoderByType("video/hevc"); ``` 2. 配置MediaCodec对象的输入格式,包括视频的宽度、高度、率等信息。 ``` MediaFormat format = MediaFormat.createVideoFormat("video/hevc", width, height); format.setInteger(MediaFormat.KEY_FRAME_RATE, frameRate); codec.configure(format, surface, null, 0); ``` 其中,surface参数是用于将解码后的视频渲染到屏幕上的Surface对象。 3. 启动MediaCodec对象,开始解码。 ``` codec.start(); ``` 4. 将H.265裸流写入MediaCodec对象的输入缓冲区。 ``` ByteBuffer[] inputBuffers = codec.getInputBuffers(); int inputBufferIndex = codec.dequeueInputBuffer(10000); if (inputBufferIndex >= 0) { ByteBuffer inputBuffer = inputBuffers[inputBufferIndex]; inputBuffer.clear(); inputBuffer.put(h265Data); codec.queueInputBuffer(inputBufferIndex, 0, h265Data.length, 0, 0); } ``` 其中,h265Data是H.265裸流数据。 5. 从MediaCodec对象的输出缓冲区获取解码后的视频。 ``` ByteBuffer[] outputBuffers = codec.getOutputBuffers(); MediaCodec.BufferInfo bufferInfo = new MediaCodec.BufferInfo(); int outputBufferIndex = codec.dequeueOutputBuffer(bufferInfo, 10000); if (outputBufferIndex >= 0) { ByteBuffer outputBuffer = outputBuffers[outputBufferIndex]; codec.releaseOutputBuffer(outputBufferIndex, true); } ``` 6. 最后,记得在不使用MediaCodec对象时进行释放。 ``` codec.stop(); codec.release(); ``` 需要注意的是,H.265是一种高压缩率的视频编码格式,解码需要较高的计算能力,因此在较低端的Android设备上可能会出现卡顿等问题。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值