简体   繁体   English

Android中的视频清理是否需要MediaCodec-MediaExtractor组合?

[英]Is the MediaCodec-MediaExtractor combo necessary for video scrubbing in Android?

I'm implementing a slider that lets me choose the frame I want to save as an image, and as everyone probably knows, the seekTo() function of Android's default MediaPlayer sucks - it doesn't actually seek to the closest frame to the timestamp, but to the closest I-frame, meaning the sought-after frame can be off by as much as a few seconds. 我正在实现一个滑块,该滑块使我可以选择要保存为图像的帧,并且众所周知,Android默认MediaPlayerseekTo()函数很烂-它实际上并没有寻求最接近时间戳的帧,但是最接近的I帧,这意味着所需的帧可能会偏离几秒钟之久。

That's why I'm considering making a custom MediaPlayer implementation that uses MediaCodec and MediaExtractor . 这就是为什么我要考虑使用MediaCodecMediaExtractor定制MediaPlayer实现。 Are they necessary for exact seeking? 是否需要精确寻找?

Use ExoPlayer instead, it will save you time and headache. 改用ExoPlayer,它将节省您的时间和头痛。

https://github.com/google/ExoPlayer https://github.com/google/ExoPlayer

If you still want to make your own video player, MediaExtractor can not do the accurate seek (in fact it should not seek to frame other than I frame, since decoding can only starts from I frame) 如果您仍想制作自己的视频播放器, MediaExtractor将无法进行精确搜索(实际上,它不应搜索除I帧以外的其他帧,因为解码只能从I帧开始)

So what you should do is seek to previous I frame using MediaExtractor and start decoding frame from that point using MediaCodec ( you can discard the result ) until you reach your desired frame. 因此,您应该做的是使用MediaExtractor搜索先前的I帧,然后使用MediaCodec从该点开始解码帧(您可以丢弃结果),直到达到所需的帧为止。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM