Android视频播放器使用NDK,OpenGL ES的,和FFmpeg的 [英] Android Video Player Using NDK, OpenGL ES, and FFmpeg

查看:2699
本文介绍了Android视频播放器使用NDK,OpenGL ES的,和FFmpeg的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好了,所以这里是我到目前为止所。我已经建立了FFmpeg的在Android和我能够精细使用它。我已经能够从Java端传递所选择的文件名后加载视频到FFmpeg的。为了节省性能我写的视频播放器在NDK,而不是从FFmpeg的通过JNI传递帧到Java。我想从视频帧发送给一个OpenGL表面。我无法搞清楚如何获得视频的每一帧,并使其到OpenGL的表面。我一直在坚持努力,现在摸不着头脑了几个星期,没有运气。希望有人能在正确的方向指向我。

Ok so here is what I have so far. I have built FFmpeg on android and am able to use it fine. I have been able to load a video into FFmpeg after passing the chosen filename from the java side. To save on performance I am writing video player in the NDK rather than passing frames from FFmpeg to java through JNI. I want to send frames from the video to an OpenGL surface. I am having trouble figuring out how to get each frame of video and render it onto the OpenGL surface. I have been stuck trying to figure this out for a couple weeks now with no luck. Hopefully someone can point me in the right direction.

谢谢!

推荐答案

这弹簧想到一个办法是绘制帧的像素到纹理,然后使用OpenGL渲染纹理。

One way that springs to mind is to draw the pixels of your frame into a texture and then render that texture using OpenGL.

我写了一篇博客文章而回如何去这个,主要是为老斯库尔像素的视频游戏,但它也适用于您的情况。该职位 Android原生编码用C 和我成立了一个 GitHub的资源库和一个例子。使用这种技术我已经能够拿到60 FPS,即使是在第一代的硬件。

I wrote a blog post a while back on how to go about this, primarily for old-skool pixel-based video games, but it also applies for your situation. The post is Android Native Coding in C, and I set up a github repository with an example. Using this technique I have been able to get 60 FPS, even on first generation hardware.

修改有关glTexImage2D VS glTexSubImage2D这种方法。

EDIT regarding glTexImage2D vs glTexSubImage2D for this approach.

调用glTexImage2D将分配显存的纹理和复制传递到内存中的像素(如果你没有通过NULL)。调用glTexSubImage2D将更新您在已分配的纹理指定像素。

Calling glTexImage2D will allocate video memory for your texture and copy the pixels you pass it into that memory (if you don't pass NULL). Calling glTexSubImage2D will update the pixels you specify in an already-allocated texture.

如果您更新的纹理则几乎没有区别调用一个或另一个,其实glTexImage2D通常更快的所有的。但是如果你只更新纹理的一部分glTexSubImage2D赢得了速度。

If you update all of the texture then there's little difference calling one or the other, in fact glTexImage2D is usually faster. But if you only update part of the texture glTexSubImage2D wins out on speed.

您必须使用电源的-2纹理尺寸,所以在覆盖在屏幕上高分辨率的设备需要1024×512的纹理,以及512x512的纹理中的决议。质地比屏幕面积(高清晰度是800x400-ISH),这意味着你只需要更新它的一部分,所以glTexSubImage2D的路要走较大。

You have to use power-of-2 texture sizes, so in covering the screen on hi-res devices requires a 1024x512 texture, and a 512x512 texture on medium resolutions. The texture is larger than the screen area (hi-res is 800x400-ish), which means you only need to update part of it, so glTexSubImage2D is the way to go.

这篇关于Android视频播放器使用NDK,OpenGL ES的,和FFmpeg的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆