简体   繁体   English

带有openGL的Android MediaMuxer

[英]Android MediaMuxer with openGL

I am trying to generate movie using MediaMuxer . 我正在尝试使用MediaMuxer生成电影。 The Grafika example is an excellent effort, but when i try to extend it, I have some problems. Grafika示例是一项出色的工作,但是当我尝试扩展它时,我遇到了一些问题。

I am trying to draw some basic shapes like square, triangle, lines into the Movie. 我试图在电影中绘制一些基本形状,例如正方形,三角形,线条。 My openGL code works well if I draw the shapes into the screen but I couldn't draw the same shapes into the video. 如果将形状绘制到屏幕中,但是无法将相同的形状绘制到视频中,我的openGL代码效果很好。

I also have questions about setting up openGL matrix, program, shader and viewport. 我还对设置openGL矩阵,程序,着色器和视口有疑问。 Normally, there are methods like onSurfaceCreated and onSurfaceChanged so that I can setup these things. 通常,有诸如onSurfaceCreatedonSurfaceChanged类的方法,以便我可以设置这些东西。 What is the best way to do it in GeneratedMovie ? GeneratedMovie执行此操作的最佳方法是什么?

Anybody has examples of writing into video with more complicated shapes would be welcome 任何人都有将形状写成更复杂的视频的例子都会受到欢迎

The complexity of what you're drawing shouldn't matter. 您所绘制内容的复杂性无关紧要。 You draw whatever you're going to draw, then call eglSwapBuffers() to submit the buffer. 绘制任何要绘制的内容,然后调用eglSwapBuffers()提交缓冲区。 Whether you draw one flat-shaded triangle or 100K super-duper-shaded triangles, you're still just submitting a buffer of data to the video encoder or the surface compositor. 无论您绘制一个平面阴影的三角形还是100K超级双面阴影的三角形,您仍然只是将数据缓冲区提交给视频编码器或曲面合成器。

There is no equivalent to SurfaceView's surfaceCreated() and surfaceChanged() , because the Surface is created by MediaCodec#createInputSurface() (so you know when it's created), and the Surface does not change. 没有等效于SurfaceView的surfaceCreated()surfaceChanged() ,因为Surface是由MediaCodec#createInputSurface()创建的(所以您知道它是何时创建的),并且Surface不会更改。

The code that uses GeneratedMovie does some fairly trivial rendering (set scissor rect, call clear). 使用GeneratedMovie的代码做了一些相当琐碎的渲染(设置剪刀矩形,调用clear)。 The code in RecordFBOActivity is what you should probably be looking at -- it has a bouncing rect and a spinning triangle, and demonstrates three different ways to deal with the fact that you have to render twice. 您可能应该看一下RecordFBOActivity中的代码-它具有一个反弹的rect和一个旋转的三角形,并演示了三种不同的方式来处理必须渲染两次的事实。

(The code in HardwareScalerActivity uses the same GLES routines and demonstrates texturing, but it doesn't do recording.) (HardwareScalerActivity中的代码使用相同的GLES例程并演示纹理化,但不进行记录。)

The key thing is to manage your EGLContext and EGLSurfaces carefully. 关键是要小心管理EGLContext和EGLSurfaces。 The various bits of GLES state are held in the EGLContext, which can be current on only one thread at a time. GLES状态的各个位保存在EGLContext中,一次只能在一个线程上是最新的。 It's easiest to use a single context and set up a separate EGLSurface for each Surface, but you can also create separate contexts (with or without sharing) and switch between them. 使用单个上下文并为每个Surface设置单独的EGLSurface最简单,但是您也可以创建单独的上下文(共享或不共享)并在它们之间切换。

Some additional background material is available here . 一些其他背景资料可在此处获得

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

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