Skip to content

This library apply video filter on generate an Mp4 and on ExoPlayer video and Video Recording with Camera2.

License

Notifications You must be signed in to change notification settings

andreiverdes/GPUVideo-android

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

36 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GPUVideo-android

Platform API

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.1'
        // if apply video filter on ExoPlayer video
        implementation 'com.google.android.exoplayer:exoplayer-core:2.9.3'
}

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

method description
rotation Rotation of the movie, default Rotation.NORMAL
size Resolution of the movie, default same resolution of src movie
fillMode Options for scaling the bounds of an movie. PRESERVE_ASPECT_FIT is fit center. PRESERVE_ASPECT_CROP is center crop , default PRESERVE_ASPECT_FIT
filter This 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.
videoBitrate Set Video Bitrate, default video bitrate is 0.25 * 30 * outputWidth * outputHeight
mute Mute audio track on exported video. Default mute = false.
flipVertical Flip Vertical on exported video. Default flipVertical = false.
flipHorizontal Flip 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.

    TrackSelector trackSelector = new DefaultTrackSelector();

    // Measures bandwidth during playback. Can be null if not required.
    DefaultBandwidthMeter defaultBandwidthMeter = new DefaultBandwidthMeter();
    // Produces DataSource instances through which media data is loaded.
    DataSource.Factory dataSourceFactory = new DefaultDataSourceFactory(context, Util.getUserAgent(context, "yourApplicationName"), defaultBandwidthMeter);
    // This is the MediaSource representing the media to be played.
    MediaSource mediaSource = new ExtractorMediaSource.Factory(dataSourceFactory).createMediaSource(Uri.parse(MP4_URL));

    // SimpleExoPlayer
    player = 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 = new GPUPlayerView(this);
    // set SimpleExoPlayer
    gpuPlayerView.setSimpleExoPlayer(player);
    gpuPlayerView.setLayoutParams(new RelativeLayout.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(new GlSepiaFilter());

Sample Usage apply video filter on Video Recording with Camera2.

SetUp on onResume method.

  sampleGLView = new GLSurfaceView(getApplicationContext());
  FrameLayout frameLayout = findViewById(R.id.wrap_view);
  frameLayout.addView(sampleGLView);
  
  gpuCameraRecorder = new GPUCameraRecorderBuilder(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(float eventX, float eventY, int viewWidth, int viewHeight); 
  // scale camera preview
  gpuCameraRecorder.setGestureScale(float scale);

Builder Method

method description
cameraRecordListener onGetFlashSupport, onRecordComplete, onError, and onCameraThreadFinish. Detail is here.
filter 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.
videoSize Resolution of the movie, default width=720, height=1280.
cameraSize Preview size.
lensFacing Select back or front camera. Default LensFacing.FRONT.
flipHorizontal Flip Horizontal on recorded video. Default flipHorizontal = false.
flipVertical Flip Vertical on recorded video. Default flipVertical = false.
mute Mute audio track on recorded video. Default mute = false.
recordNoFilter No 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.

About

This library apply video filter on generate an Mp4 and on ExoPlayer video and Video Recording with Camera2.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%