[英]In Android, how to pass surface to MediaCodec::configure API
I am trying to create a simple video player using MediaExtractor
and MediaCodec
API. 我正在尝试使用
MediaExtractor
和MediaCodec
API创建一个简单的视频播放器。
I am able to extract the individual tracks of a TS (Transport Stream) file. 我能够提取TS(传输流)文件的各个轨道。 I am also able to create the decoder and configure it and able to decode the content.
我还能够创建解码器并对其进行配置,并能够对内容进行解码。
When I want to render the video on a surface
, I understand that we should give the surface as a parameter to MediaCodec.configure
. 当我想在
surface
上渲染视频时,我知道我们应该将表面作为MediaCodec.configure
的参数。
status_t MediaCodec::configure (MediaFormat format, Surface surface, MediaCrypto crypto, int flags)
Now, I couldn't find any example on how to create a surface
and pass that to the configure
function. 现在,我找不到任何有关如何创建
surface
并将其传递给configure
函数的示例。 Can somebody please help me out ? 有人可以帮我吗?
First implement TextureView.SurfaceTextureListener as: 首先将TextureView.SurfaceTextureListener实现为:
public class MainActivity extends AppCompatActivity implements TextureView.SurfaceTextureListener {
private TextureView m_surface;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
m_surface = (TextureView)findViewById(R.id.textureView);
m_surface.setSurfaceTextureListener(this);
}
Now pass the Surface to MediaCodec like this 现在像这样将Surface传递给MediaCodec
m_codec.configure(format,new Surface(m_surface.getSurfaceTexture()), null, 0);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.