0

currently, I am playing a video on a GLSurfaceView using OpenGL ES 2.0. Now, I am searching for a way to encode this video played on the surface view into a MP4 video using MediaCodec.

Therefore, I found the bigflake example, which seems to solve my issue perfectly (http://bigflake.com/mediacodec/EncodeAndMuxTest.java.txt).

However, it seems that I am too stupid to set the input source right. This example uses mEncoder.createInputSurface() to create the input source, however I have a GLSurfaceView where the video is actually played. So how do I set my own surface as input source for the encoder?

genpfault
  • 51,148
  • 11
  • 85
  • 139
Florian
  • 2,048
  • 3
  • 28
  • 36
  • Some additional samples can be found in Grafika (https://github.com/google/grafika). With GLSurfaceView you don't control the EGL context, so you can either share it (awkwardly; see "show + capture camera" for an example) or just use a plain SurfaceView and manage EGL yourself (which is what most of the examples in Grafika do). – fadden Jul 10 '14 at 15:33

1 Answers1

3

Since you are using GLSurfaceView, you need to insert intercepting code in onDrawFrame(), while allocating surface in onSurfaceCreated(). Input surface can be created as usual after setting up encoder parameters. Interceptor can be done in a form of copying egl scene into frame buffer via copying shader. And then do swapbuffer to encode frame. Try look at tutorial for arbitrary elg scene capturing at https://software.intel.com/en-us/articles/intel-inde-media-pack-for-android-tutorials-video-capturing-for-opengl-applications

ugene
  • 146
  • 3
  • Okay, thank you. That's one possibility. I also thought of something different. The basic thing I want to do is the following: I have an existing MP4 file that I wish to edit (change the framesize by cropping etc), then save the edited file again. I also had a look at https://android.googlesource.com/platform/cts/+/jb-mr2-release/tests/tests/media/src/android/media/cts/DecodeEditEncodeTest.java The thing is that I am not sure how to get the Video Chunk data from the MP4 instead of creating a video. – Florian Jul 10 '14 at 14:15
  • So if you need to say visually setting crop and then apply that to whole stream, i would recommend, 2 stages. 1st - detect crop settings user want, then run transcode scenario with applied video cropping effect. So in those link i provided also a sample with effect applied during end to end transcoding, called "Video Effect" https://software.intel.com/en-us/articles/intel-inde-media-pack-for-android-tutorials-running-samples – ugene Jul 10 '14 at 14:51