1 Star 0 Fork 1

落霞孤鹜 / GPUVideo-android

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README
MIT

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.
MIT License Copyright (c) 2019 Masayuki Suda Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

简介

This library apply video filter on generate an Mp4 and on ExoPlayer video and Video Recording with Camera2. 展开 收起
MIT
取消

发行版

暂无发行版

贡献者

全部

近期动态

加载更多
不能加载更多了
1
https://gitee.com/shanxsx/GPUVideo-android.git
git@gitee.com:shanxsx/GPUVideo-android.git
shanxsx
GPUVideo-android
GPUVideo-android
master

搜索帮助