简体   繁体   English

Android:如何通过硬件加速将图像流编码为h264?

[英]Android: how to encode a stream of images to h264 with hardware acceleration?

I am currently working on an app, to read the camera images and process them using OpenCV. 我目前正在开发一个应用程序,以读取相机图像并使用OpenCV处理它们。 I would like to store the original images as a "normal" video and to drop the processed images after processing (after the information is extracted). 我想将原始图像存储为“正常”视频,并在处理后(提取信息后)删除处理后的图像。 For this I basically need to encode the image stream to h264. 为此,我基本上需要将图像流编码为h264。 It will not be possible to use ffmpeg or other solutions wich do it on the general cpu. 无法在通用CPU上使用ffmpeg或其他解决方案。 It has to be done using the internal hardware acceleration. 必须使用内部硬件加速来完成。 Because of this I have actually three questions: 因此,我实际上有三个问题:

  • Does somebdy know how to achieve h264 encoding using the internal hw-modules to encode videos? 有人知道如何使用内部硬件模块对视频进行编码来实现h264编码吗?

  • Or does ffmpeg really support this on Android? 还是ffmpeg确实在Android上支持此功能?

  • Or is there a way access the image stream during the "usual" encoding process? 还是在“常规”编码过程中有访问图像流的方法?

Thanks alot! 非常感谢!

You can run the MediaRecorder to create the video using h264 hardware encoder (if available) and at the same time register your preview frame handler. 您可以使用h264硬件编码器(如果有)运行MediaRecorder来创建视频,同时注册预览帧处理程序。 I cannot guarantee that all preview frames will go in both directions, though. 但是,我不能保证所有预览框都可以双向移动。

Alternatively, you can compile ffmpeg with libstagefright, and it will use hardware avc encoder. 或者,您可以使用libstagefright编译ffmpeg,它将使用硬件avc编码器。

Alternatively, you can use stagefright directly from your app (via JNI). 或者,您可以直接通过您的应用程序(通过JNI)使用stagefright。

Finally, you can follow the approach of libstreaming to find the optimal recording API for your platform (be it MediaRecorder API, or MediaCodec buffer-to-buffer method which requires Android 4.1, or MediaCodec surface-to-buffer method which requires Android 4.3. 最后,您可以按照libstreaming的方法找到适合您平台的最佳录制API(无论是MediaRecorder API,还是需要Android 4.1的MediaCodec缓冲区到缓冲区方法,还是需要Android 4.3的MediaCodec表面到缓冲区方法。

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

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