Skip to content

Repository files navigation

GPUVideo-android

PlatformAPI

This library apply video filter on generate an Mp4 and on ExoPlayer video and Video Recording with Camera2.
Android MediaCodec API is used this library.

Features

  • apply video filter, scale, and rotate Mp4.
  • apply video filter on ExoPlayer video.
  • apply video filter on Video Recording with Camera2.

apply video filter on generate an Mp4


Sample Video
No filter

GlGlayScaleFilter
apply

GlMonochromeFilter
apply

GlWatermarkFilter
apply

apply video filter on ExoPlayer video

apply video filter on Video Recording with Camera2.

Gradle

Step 1. Add the JitPack repository to your build file

allprojects {
repositories {
...
maven { url 'https://jitpack.io' }
}
}

Step 2. Add the dependency

dependencies {
implementation 'com.github.MasayukiSuda:GPUVideo-android:v0.1.2'// if apply video filter on ExoPlayer video
implementation 'com.google.android.exoplayer:exoplayer-core:2.15.1'
}

Sample Usage apply video filter on generate an Mp4

 new GPUMp4Composer(srcMp4Path, destMp4Path)
.rotation(Rotation.ROTATION_90)
.size((width) 540, (height) 960)
.fillMode(FillMode.PRESERVE_ASPECT_FIT)
.filter(new GlFilterGroup(new GlMonochromeFilter(), new GlVignetteFilter()))
.listener(new GPUMp4Composer.Listener() {
@Override
public void onProgress(double progress) {
Log.d(TAG, "onProgress = " + progress);
}
@Override
public void onCompleted() {
Log.d(TAG, "onCompleted()");
runOnUiThread(() -> {
Toast.makeText(context, "codec complete path =" + destPath, Toast.LENGTH_SHORT).show();
});
}
@Override
public void onCanceled() {
Log.d(TAG, "onCanceled");
}
@Override
public void onFailed(Exception exception) {
Log.e(TAG, "onFailed()", exception);
}
})
.start();

Builder Method

methoddescription
rotationRotation of the movie, default Rotation.NORMAL
sizeResolution of the movie, default same resolution of src movie
fillModeOptions for scaling the bounds of an movie. PRESERVE_ASPECT_FIT is fit center. PRESERVE_ASPECT_CROP is center crop , default PRESERVE_ASPECT_FIT
filterThis filter is OpenGL Shaders to apply effects on video. Custom filters can be created by inheriting GlFilter.java. , default GlFilter(No filter). Filters is here.
videoBitrateSet Video Bitrate, default video bitrate is 0.25 * 30 * outputWidth * outputHeight
muteMute audio track on exported video. Default mute = false.
flipVerticalFlip Vertical on exported video. Default flipVertical = false.
flipHorizontalFlip Horizontal on exported video. Default flipHorizontal = false.

Sample Usage apply video filter on ExoPlayer video

STEP 1

Create SimpleExoPlayer instance. In this case, play MP4 file.
Read this if you want to play other video formats.

TrackSelectortrackSelector = newDefaultTrackSelector();
// Measures bandwidth during playback. Can be null if not required.DefaultBandwidthMeterdefaultBandwidthMeter = newDefaultBandwidthMeter();
// Produces DataSource instances through which media data is loaded.DataSource.FactorydataSourceFactory = newDefaultDataSourceFactory(context, Util.getUserAgent(context, "yourApplicationName"), defaultBandwidthMeter);
// This is the MediaSource representing the media to be played.MediaSourcemediaSource = newExtractorMediaSource.Factory(dataSourceFactory).createMediaSource(Uri.parse(MP4_URL));
// SimpleExoPlayerplayer = ExoPlayerFactory.newSimpleInstance(context, mediaSource);
// Prepare the player with the source.player.prepare(videoSource);
player.setPlayWhenReady(true);

STEP 2

Create GPUPlayerView and set SimpleExoPlayer to GPUPlayerView.

gpuPlayerView = newGPUPlayerView(this);
// set SimpleExoPlayergpuPlayerView.setSimpleExoPlayer(player);
gpuPlayerView.setLayoutParams(newRelativeLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
// add gpuPlayerView to WrapperView
((MovieWrapperView) findViewById(R.id.layout_movie_wrapper)).addView(gpuPlayerView);
gpuPlayerView.onResume();

STEP 3

Set Filter. Filters is here.
Custom filters can be created by inheriting GlFilter.java.

gpuPlayerView.setGlFilter(newGlSepiaFilter());

Sample Usage apply video filter on Video Recording with Camera2.

SetUp on onResume method.

sampleGLView = newGLSurfaceView(getApplicationContext());
FrameLayoutframeLayout = findViewById(R.id.wrap_view);
frameLayout.addView(sampleGLView);
gpuCameraRecorder = newGPUCameraRecorderBuilder(activity, sampleGLView)
.lensFacing(LensFacing.BACK)
.build();

Release on onPause method.

sampleGLView.onPause(); gpuCameraRecorder.stop();
gpuCameraRecorder.release();
gpuCameraRecorder = null;
((FrameLayout) findViewById(R.id.wrap_view)).removeView(sampleGLView);
sampleGLView = null;

Start and Stop Video record.

// record start.gpuCameraRecorder.start(filepath);
// record stop.gpuCameraRecorder.stop();

This filter is OpenGL Shaders to apply effects on camera preview. Custom filters can be created by inheriting GlFilter.java. , default GlFilter(No filter). Filters is here.

gpuCameraRecorder.setFilter(GlFilter);

Other methods.

// if flash enable, turn on or off camera flash. gpuCameraRecorder.switchFlashMode();
// autofocus change.gpuCameraRecorder.changeAutoFocus();
// set focus point at manual.gpuCameraRecorder.changeManualFocusPoint(floateventX, floateventY, intviewWidth, intviewHeight); // scale camera previewgpuCameraRecorder.setGestureScale(floatscale);

Builder Method

methoddescription
cameraRecordListeneronGetFlashSupport, onRecordComplete, onError, and onCameraThreadFinish. Detail is here.
filterThis filter is OpenGL Shaders to apply effects on camera preview. Custom filters can be created by inheriting GlFilter.java. , default GlFilter(No filter). Filters is here.
videoSizeResolution of the movie, default width=720, height=1280.
cameraSizePreview size.
lensFacingSelect back or front camera. Default LensFacing.FRONT.
flipHorizontalFlip Horizontal on recorded video. Default flipHorizontal = false.
flipVerticalFlip Vertical on recorded video. Default flipVertical = false.
muteMute audio track on recorded video. Default mute = false.
recordNoFilterNo Filter on recorded video although preview apply a filter. Default recordNoFilter = false.

Filters

  • Bilateral
  • BoxBlur
  • Brightness
  • BulgeDistortion
  • CGAColorspace
  • Contrast
  • Crosshatch
  • Exposure
  • FilterGroup
  • Gamma
  • GaussianBlur
  • GrayScale
  • Halftone
  • Haze
  • HighlightShadow
  • Hue
  • Invert
  • LookUpTable
  • Luminance
  • LuminanceThreshold
  • Monochrome
  • Opacity
  • Overlay
  • Pixelation
  • Posterize
  • RGB
  • Saturation
  • Sepia
  • Sharpen
  • Solarize
  • SphereRefraction
  • Swirl
  • ToneCurve
  • Tone
  • Vibrance
  • Vignette
  • Watermark
  • WeakPixelInclusion
  • WhiteBalance
  • ZoomBlur

References And Special Thanks to

Sample Dependencies

License

MIT License

ExoPlayer and ExoPlayer demo.

Copyright (C) 2014 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Releases

Packages

Contributors

Languages