For display only, one easy approach is to use a GLSurfaceView
, a SurfaceTexture
to render the video frames, and a MediaPlayer
. Prokash's answer links to an open source library that shows how to accomplish that. There are a number of other examples around if you search those terms together. Taking that route, you draw video frames to an OpenGL texture and create OpenGL shaders to manipulate how the texture is rendered. (I would suggest asking Prokash for further details and accepting his answer if this is enough to fill your requirements.)
Similarly, you could use the OpenGL tools with MediaCodec
and MediaExtractor
to decode video frames. The MediaCodec
would be configured to output to a SurfaceTexture
, so you would not need to do much more than code some boilerplate to get the output buffers rendered. The filtering process would be the same as with a MediaPlayer
. There are a number of examples using MediaCodec
as a decoder available, e.g. here and here. It should be fairly straightforward to substitute the TextureView
or SurfaceView
used in those examples with the GLSurfaceView
of Prokash's example.
The advantage of this approach is that you have access to all the separate tracks in the media file. Because of that, you should be able to filter the video track with OpenGL and straight copy other tracks for export. You would use a MediaCodec
in encode mode with the Surface
from the GLSurfaceView
as input and a MediaMuxer
to put it all back together. You can see several relevant examples at BigFlake.
You can use a MediaCodec
without a Surface
to access decoded byte data directly and manipulate it that way. This example illustrates that approach. You can manipulate the data and send it to an encoder for export or render it as you see fit. There is some extra complexity in dealing with the raw byte data. Note that I like this example because it illustrates dealing with the audio and video tracks separately.
You can also use FFMpeg, either in native code or via one of the Java wrappers out there. This option is more geared towards export than immediate playback. See here or here for some libraries that attempt to make FFMpeg available to Java. They are basically wrappers around the command line interface. You would need to do some extra work to manage playback via FFMpeg, but it is definitely doable.
If you have questions, feel free to ask, and I will try to expound upon whatever option makes the most sense for your use case.
GLSurfaceView
with aMediaPlayer
and applying OpenGL shaders to perform filtering on the display. That is definitely a reasonable approach if you don't need to export the filtered video. Where is yourSurface
coming from now? – AleshiaSurface
- that's what I am looking for :) – Gasaway