Skip to content

Commit 69fb8b7

Browse files
committed
feat: add AlphaFrameFilter
1 parent fe763ae commit 69fb8b7

File tree

8 files changed

+61
-11
lines changed

8 files changed

+61
-11
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,9 @@ Custom filters can be created by inheriting [GlFilter.java](https://github.com/M
6767
ePlayerView.setGlFilter(new GlSepiaFilter());
6868
```
6969

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

7174
## Special Thanks to
7275
* [android-gpuimage](https://github.com/CyberAgent/android-gpuimage)

epf/src/main/java/com/daasuu/epf/EPlayerView.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
package com.daasuu.epf;
22

33
import android.content.Context;
4+
import android.graphics.PixelFormat;
45
import android.opengl.GLSurfaceView;
56
import android.util.AttributeSet;
67

78
import com.daasuu.epf.chooser.EConfigChooser;
89
import com.daasuu.epf.contextfactory.EContextFactory;
10+
import com.daasuu.epf.filter.AlphaFrameFilter;
911
import com.daasuu.epf.filter.GlFilter;
1012
import com.google.android.exoplayer2.SimpleExoPlayer;
1113
import com.google.android.exoplayer2.video.VideoListener;
@@ -33,9 +35,12 @@ public EPlayerView(Context context, AttributeSet attrs) {
3335
setEGLContextFactory(new EContextFactory());
3436
setEGLConfigChooser(new EConfigChooser());
3537

38+
setZOrderOnTop(true);
39+
setEGLConfigChooser(8, 8, 8, 8, 16, 0);
40+
getHolder().setFormat(PixelFormat.RGBA_8888);
41+
3642
renderer = new EPlayerRenderer(this);
3743
setRenderer(renderer);
38-
3944
}
4045

4146
public EPlayerView setSimpleExoPlayer(SimpleExoPlayer player) {
@@ -49,8 +54,23 @@ public EPlayerView setSimpleExoPlayer(SimpleExoPlayer player) {
4954
return this;
5055
}
5156

57+
private GlFilter filter = null;
5258
public void setGlFilter(GlFilter glFilter) {
5359
renderer.setGlFilter(glFilter);
60+
if (glFilter != null) {
61+
if (glFilter instanceof AlphaFrameFilter) {
62+
videoAspect = videoAspect * 2;
63+
requestLayout();
64+
} else {
65+
if (filter != null) {
66+
if (filter instanceof AlphaFrameFilter) {
67+
videoAspect = videoAspect / 2;
68+
requestLayout();
69+
}
70+
}
71+
}
72+
}
73+
filter = glFilter;
5474
}
5575

5676
public void setPlayerScaleType(PlayerScaleType playerScaleType) {
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package com.daasuu.epf.filter;
2+
3+
public class AlphaFrameFilter extends GlFilter {
4+
private static final String VERTEX_SHADER =
5+
"attribute vec4 aPosition;\n" +
6+
"attribute vec4 aTextureCoord;\n" +
7+
"varying highp vec2 vTextureCoord;\n" +
8+
"varying highp vec2 vTextureCoord2;\n" +
9+
"void main() {\n" +
10+
"gl_Position = aPosition;\n" +
11+
"vTextureCoord = vec2(aTextureCoord.x, aTextureCoord.y*0.5+0.5);\n" +
12+
"vTextureCoord2 = vec2(aTextureCoord.x, aTextureCoord.y*0.5);\n" +
13+
"}\n";
14+
private static final String FRAGMENT_SHADER =
15+
"precision mediump float;\n" +
16+
"varying highp vec2 vTextureCoord;\n" +
17+
"varying highp vec2 vTextureCoord2;\n" +
18+
"uniform lowp sampler2D sTexture;\n" +
19+
"void main() {\n" +
20+
"vec4 color1 = texture2D(sTexture, vTextureCoord);\n" +
21+
"vec4 color2 = texture2D(sTexture, vTextureCoord2);\n" +
22+
"gl_FragColor = vec4(color1.rgb, color2.r);\n" +
23+
"}\n";
24+
25+
public AlphaFrameFilter() {
26+
super(VERTEX_SHADER, FRAGMENT_SHADER);
27+
}
28+
}
284 KB
Binary file not shown.

sample/src/main/java/com/daasuu/exoplayerfilter/FilterType.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import android.graphics.BitmapFactory;
66
import android.util.Log;
77

8+
import com.daasuu.epf.filter.AlphaFrameFilter;
89
import com.daasuu.epf.filter.GlBilateralFilter;
910
import com.daasuu.epf.filter.GlBoxBlurFilter;
1011
import com.daasuu.epf.filter.GlBrightnessFilter;
@@ -58,6 +59,7 @@
5859

5960
public enum FilterType {
6061
DEFAULT,
62+
ALPHA_FRAME,
6163
BITMAP_OVERLAY_SAMPLE,
6264
BILATERAL_BLUR,
6365
BOX_BLUR,
@@ -98,8 +100,7 @@ public enum FilterType {
98100
WATERMARK,
99101
WEAK_PIXEL,
100102
WHITE_BALANCE,
101-
ZOOM_BLUR,
102-
;
103+
ZOOM_BLUR;
103104

104105

105106
public static List<FilterType> createFilterList() {
@@ -269,6 +270,8 @@ public static GlFilter createGlFilter(FilterType filterType, Context context) {
269270
return new GlZoomBlurFilter();
270271
case BITMAP_OVERLAY_SAMPLE:
271272
return new GlBitmapOverlaySample(BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher_round));
273+
case ALPHA_FRAME:
274+
return new AlphaFrameFilter();
272275
default:
273276
return new GlFilter();
274277
}

sample/src/main/java/com/daasuu/exoplayerfilter/MainActivity.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,9 @@ private void setUpSimpleExoPlayer() {
123123
DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(this, Util.getUserAgent(this, "yourApplicationName"));
124124

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

129130
// SimpleExoPlayer
130131
player = ExoPlayerFactory.newSimpleInstance(this);

sample/src/main/java/com/daasuu/exoplayerfilter/MovieWrapperView.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,4 @@ public MovieWrapperView(@NonNull Context context, @Nullable AttributeSet attrs,
2525
super(context, attrs, defStyleAttr);
2626
}
2727

28-
@Override
29-
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
30-
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
31-
int measuredWidth = getMeasuredWidth();
32-
setMeasuredDimension(measuredWidth, measuredWidth / 16 * 9);
33-
}
3428
}

sample/src/main/res/layout/activity_main.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
<com.daasuu.exoplayerfilter.MovieWrapperView
1111
android:id="@+id/layout_movie_wrapper"
12+
android:background="@color/colorPrimary"
1213
android:layout_width="match_parent"
1314
android:layout_height="wrap_content" />
1415

0 commit comments

Comments
 (0)