Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ Custom filters can be created by inheriting [GlFilter.java](https://github.com/M
ePlayerView.setGlFilter(new GlSepiaFilter());
```

## AlphaVideo
Use `AlphaFrameFilter` render video with alpha
[how-to-create-an-alpha-video](https://felgo.com/doc/felgo-alphavideo/#how-to-create-an-alpha-video)

## Special Thanks to
* [android-gpuimage](https://github.com/CyberAgent/android-gpuimage)
Expand Down
4 changes: 3 additions & 1 deletion epf/src/main/java/com/daasuu/epf/EPlayerRenderer.java
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public void run() {

@Override
public void onSurfaceCreated(final EGLConfig config) {
GLES20.glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
GLES20.glClearColor(0.0f, 0.0f, 0.0f, 0.0f);

final int[] args = new int[1];

Expand Down Expand Up @@ -136,6 +136,8 @@ public void onSurfaceChanged(final int width, final int height) {

@Override
public void onDrawFrame(final EFramebufferObject fbo) {
GLES20.glEnable(GLES20.GL_BLEND);
GLES20.glBlendFunc(GLES20.GL_SRC_ALPHA, GLES20.GL_ONE_MINUS_SRC_ALPHA);

synchronized (this) {
if (updateSurface) {
Expand Down
22 changes: 21 additions & 1 deletion epf/src/main/java/com/daasuu/epf/EPlayerView.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.daasuu.epf;

import android.content.Context;
import android.graphics.PixelFormat;
import android.opengl.GLSurfaceView;
import android.util.AttributeSet;

import com.daasuu.epf.chooser.EConfigChooser;
import com.daasuu.epf.contextfactory.EContextFactory;
import com.daasuu.epf.filter.AlphaFrameFilter;
import com.daasuu.epf.filter.GlFilter;
import com.google.android.exoplayer2.SimpleExoPlayer;
import com.google.android.exoplayer2.video.VideoListener;
Expand Down Expand Up @@ -33,9 +35,12 @@ public EPlayerView(Context context, AttributeSet attrs) {
setEGLContextFactory(new EContextFactory());
setEGLConfigChooser(new EConfigChooser());

setZOrderOnTop(true);
setEGLConfigChooser(8, 8, 8, 8, 16, 0);
getHolder().setFormat(PixelFormat.RGBA_8888);

renderer = new EPlayerRenderer(this);
setRenderer(renderer);

}

public EPlayerView setSimpleExoPlayer(SimpleExoPlayer player) {
Expand All @@ -49,8 +54,23 @@ public EPlayerView setSimpleExoPlayer(SimpleExoPlayer player) {
return this;
}

private GlFilter filter = null;
public void setGlFilter(GlFilter glFilter) {
renderer.setGlFilter(glFilter);
if (glFilter != null) {
if (glFilter instanceof AlphaFrameFilter) {
videoAspect = videoAspect * 2;
requestLayout();
} else {
if (filter != null) {
if (filter instanceof AlphaFrameFilter) {
videoAspect = videoAspect / 2;
requestLayout();
}
}
}
}
filter = glFilter;
}

public void setPlayerScaleType(PlayerScaleType playerScaleType) {
Expand Down
28 changes: 28 additions & 0 deletions epf/src/main/java/com/daasuu/epf/filter/AlphaFrameFilter.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.daasuu.epf.filter;

public class AlphaFrameFilter extends GlFilter {
private static final String VERTEX_SHADER =
"attribute vec4 aPosition;\n" +
"attribute vec4 aTextureCoord;\n" +
"varying highp vec2 vTextureCoord;\n" +
"varying highp vec2 vTextureCoord2;\n" +
"void main() {\n" +
"gl_Position = aPosition;\n" +
"vTextureCoord = vec2(aTextureCoord.x, aTextureCoord.y*0.5+0.5);\n" +
"vTextureCoord2 = vec2(aTextureCoord.x, aTextureCoord.y*0.5);\n" +
"}\n";
private static final String FRAGMENT_SHADER =
"precision mediump float;\n" +
"varying highp vec2 vTextureCoord;\n" +
"varying highp vec2 vTextureCoord2;\n" +
"uniform lowp sampler2D sTexture;\n" +
"void main() {\n" +
"vec4 color1 = texture2D(sTexture, vTextureCoord);\n" +
"vec4 color2 = texture2D(sTexture, vTextureCoord2);\n" +
"gl_FragColor = vec4(color1.rgb, color2.r);\n" +
"}\n";

public AlphaFrameFilter() {
super(VERTEX_SHADER, FRAGMENT_SHADER);
}
}
Binary file added sample/src/main/assets/playdoh_bat.mp4
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import android.graphics.BitmapFactory;
import android.util.Log;

import com.daasuu.epf.filter.AlphaFrameFilter;
import com.daasuu.epf.filter.GlBilateralFilter;
import com.daasuu.epf.filter.GlBoxBlurFilter;
import com.daasuu.epf.filter.GlBrightnessFilter;
Expand Down Expand Up @@ -58,6 +59,7 @@

public enum FilterType {
DEFAULT,
ALPHA_FRAME,
BITMAP_OVERLAY_SAMPLE,
BILATERAL_BLUR,
BOX_BLUR,
Expand Down Expand Up @@ -98,8 +100,7 @@ public enum FilterType {
WATERMARK,
WEAK_PIXEL,
WHITE_BALANCE,
ZOOM_BLUR,
;
ZOOM_BLUR;


public static List<FilterType> createFilterList() {
Expand Down Expand Up @@ -269,6 +270,8 @@ public static GlFilter createGlFilter(FilterType filterType, Context context) {
return new GlZoomBlurFilter();
case BITMAP_OVERLAY_SAMPLE:
return new GlBitmapOverlaySample(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher_round));
case ALPHA_FRAME:
return new AlphaFrameFilter();
default:
return new GlFilter();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,9 @@ private void setUpSimpleExoPlayer() {
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this, Util.getUserAgent(this, "yourApplicationName"));

// This is the MediaSource representing the media to be played.
MediaSource videoSource = new ProgressiveMediaSource.Factory(dataSourceFactory)
.createMediaSource(Uri.parse(Constant.STREAM_URL_MP4_VOD_LONG));
// MediaSource videoSource = new ProgressiveMediaSource.Factory(dataSourceFactory)
// .createMediaSource(Uri.parse(Constant.STREAM_URL_MP4_VOD_LONG));
MediaSource videoSource = new ProgressiveMediaSource.Factory(dataSourceFactory).createMediaSource(Uri.parse("asset:///playdoh_bat.mp4"));

// SimpleExoPlayer
player = ExoPlayerFactory.newSimpleInstance(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,4 @@ public MovieWrapperView(@NonNull Context context, @Nullable AttributeSet attrs,
super(context, attrs, defStyleAttr);
}

@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int measuredWidth = getMeasuredWidth();
setMeasuredDimension(measuredWidth, measuredWidth / 16 * 9);
}
}
1 change: 1 addition & 0 deletions sample/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

<com.daasuu.exoplayerfilter.MovieWrapperView
android:id="@+id/layout_movie_wrapper"
android:background="@color/colorPrimary"
android:layout_width="match_parent"
android:layout_height="wrap_content" />

Expand Down