我需要在Android(MediaPlayer)上播放一個視頻的繪製過濾器,這個過濾器只是將背景變成透明的,但我如何讀取要處理的字節?由於Android似乎不跑alpha通道電影:(如何在MediaPlayer上使用SurfaceView應用濾鏡?
我需要這把視頻全屏覆蓋相機預覽(AR)。這就是爲什麼我需要電影的背景是透明的。
我的想法是發送在MediaPlayer幀數據(位圖數據),以NDK過程,然後返回已處理的位圖來surfaceview
PS:Android的API8,目標2.2+
波紋管跟隨我的代碼:
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.util.Log;
import android.view.SurfaceView;
public class MovieSurfaceView extends SurfaceView {
public MovieSurfaceView(Context context) {
super(context);
}
@Override
protected void onDraw(Canvas c) {
super.onDraw(c);
}
}
/** The main activity for the ImageTargets sample. */
public class ImageTargets extends Activity implements SurfaceHolder.Callback
{
private MovieSurfaceView mPreview;
private MediaPlayer mMediaPlayer;
private SurfaceHolder holder;
private String videoPath = "/LAST.3g2";
protected void onCreate(Bundle savedInstanceState)
{
DebugLog.LOGD("ImageTargets::onCreate");
super.onCreate(savedInstanceState);
initApplicationAR();
}
private void initApplicationAR()
{
mPreview = new MovieSurfaceView(this);
addContentView(mPreview, new LayoutParams(
LayoutParams.FILL_PARENT,
LayoutParams.FILL_PARENT));
// holder = mGlView.getHolder();
holder = mPreview.getHolder();
holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
holder.addCallback(this);
}
@Override
public void surfaceChanged(SurfaceHolder arg0, int arg1, int arg2, int arg3) {
}
@Override
public void surfaceCreated(SurfaceHolder arg0) {
mMediaPlayer = new MediaPlayer();
mMediaPlayer.setDisplay(holder);
mMediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mMediaPlayer.setOnPreparedListener(new OnPreparedListener()
{
public void onPrepared(MediaPlayer mp)
{
mp.start();
}
}
);
mMediaPlayer.setOnCompletionListener(new OnCompletionListener()
{
@Override
public void onCompletion(MediaPlayer mp)
{
mp.reset();
}
}
);
iniPlayer();
}
@Override
public void surfaceDestroyed(SurfaceHolder arg0)
{
// TODO Auto-generated method stub
}
}
的問題是Android的目標隊友,我不能用表面紋理的視頻幀發送到OpenGL,一些替代電影幀的紋理? – GTSouza
你說得對,使用SurfaceTexture就容易多了,但我在2.2上實現了類似的任務。我使用相機預覽回調,glTexSubImage2D和着色器將yuv轉換爲rgb。 –
相機可以,但關於視頻文件? mp4,3gp等,你怎麼知道一些技巧發送到當前幀到OpenGL? – GTSouza