Giter Club home page Giter Club logo

pavelsemak / alpha-movie Goto Github PK

View Code? Open in Web Editor NEW
141.0 6.0 41.0 3.39 MB

Android video player with alpha channel (chroma key) support

Home Page: https://github.com/pavelsemak/alpha-movie

License: Apache License 2.0

Java 100.00%
android video alpha alphachannel channel transparency videoplayer alpha-channel video-player android-video-player alpha-video tranparent-video transparent green-channel green alpha-green alpha-compositing chroma-key chromakey

alpha-movie's Introduction

Alpha Movie

Alpha Movie is an Android video player library with alpha channel support.

Video Player uses OpenGL to render video and apply shader that makes alpha compositing possible. The player encapsulates MediaPlayer and has its base functionality. Video stream is displayed by TextureView.


Gradle Dependency

jCenter License

The easiest way to start using Alpha Movie is to add it as a Gradle Dependency. The Gradle dependency is available via jCenter. Please make sure that you have the jcenter repository included in the project's build.gradle file (jCenter is the default Maven repository used by Android Studio):

repositories {
    jcenter()
}

Then add this dependency to your module's build.gradle file:

dependencies {
    // ... other dependencies
    compile 'com.alphamovie.library:alpha-movie:1.2.1'
}

Getting Started

Add AlphaMovieView into you activity layout:

<com.alphamovie.lib.AlphaMovieView
    android:id="@+id/video_player"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"/>

Next you need to initialize the player. In your Activity class add:

public class MainActivity extends AppCompatActivity {

    private AlphaMovieView alphaMovieView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        alphaMovieView = (AlphaMovieView) findViewById(R.id.video_player);
        alphaMovieView.setVideoFromAssets("video.mp4");
    }

    @Override
    public void onResume() {
        super.onResume();
        alphaMovieView.onResume();
    }

    @Override
    public void onPause() {
        super.onPause();
        alphaMovieView.onPause();
    }
}

In this code snippet we load video from assets specifying filename video.mp4:

alphaMovieView.setVideoFromAssets("video.mp4");

Video can also be set by Url, FileDescriptor, MediaSource and other sources.

You need to add alphaMovieView.onPause() and alphaMovieView.onResume() in activity's onPause() and onResume() callbacks. Calling these methods will pause and resume OpenGL rendering thread.

Video playback can be paused and resumed using alphaMovieView.pause() and alphaMovieView.start() methods.


How it works?

Alpha Movie player uses OpenGL to render video with a shader attached to gl renderer. This shader modifies each pixel of video frame. By default it converts green color to transparent.

So default alpha channel color is green. This color can be changed to any rgb color by adding xml attribute alphaColor:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:custom="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.alphamovie.lib.AlphaMovieView
        android:id="@+id/video_player"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        custom:alphaColor="#ff0000"
        custom:accuracy="0.7"/>
</FrameLayout>

In the code snippet above we set custom:alphaColor="#ff0000". It means that alpha channel color is set to red.

Also we specify accuracy attr to be 0.7. Accuracy is the value between 0 and 1. It should be lower if you wish more shades of specified color be transparent and vice versa. By default accuracy="0.95".

Custom shader

There is a possibility to apply your own custom shader. Add shader attr:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:custom="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <com.alphamovie.lib.AlphaMovieView
        android:id="@+id/video_player"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        custom:shader="@string/shader_custom"/>
</FrameLayout>

And define your custom shader in string values, for example:

<resources>
    <!-- ... other string resources -->
    <string name="shader_custom">#extension GL_OES_EGL_image_external : require\n
            precision mediump float;
            varying vec2 vTextureCoord;
            uniform samplerExternalOES sTexture;
            varying mediump float text_alpha_out;
            void main() {
              vec4 color = texture2D(sTexture, vTextureCoord);
              if (color.g - color.r >= 0.1 &amp;&amp; color.g - color.b >= 0.1) {
                  gl_FragColor = vec4(color.r, (color.r + color.b) / 2.0, color.b, 1.0 - color.g);
              } else {
                  gl_FragColor = vec4(color.r, color.g, color.b, color.a);
              }
            }
    </string>
</resources>

In this case accuracy and alphaColor attrs are not affecting anything because they are used only when custom shader is not defined.

alpha-movie's People

Contributors

pavelsiamak avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

alpha-movie's Issues

Black screen appears before start in DialogFragment

Hi, thanks for the library. It's really cool. But I have some troubles with your library in DialogFragment.
I have black screen before video start. It is appear for a second, after that video start.
What is it? In Activity all alright, but I have to use DialogFragment.

How to merge it into a video after cutting.

./ffmpeg -i ~/fuck.mp4 -i ~/1.mp4 -shortest -filter_complex "[1:v]chromakey=0x70de77:0.1:0.2[ckout];[0:v][ckout]overlay[out]" -map "[out]" output.mp4
How does this command come true?

Doesn't play video after seekTo();

I am open new activity and use

String contentUri = (String) getIntent().getExtras().get("url");
int getCurrentPosition = (int) getIntent().getExtras().get("currentPosition");
alphaMovieView.seekTo(currentPosition);
alphaMovieView.start();

but video doesn't play. When i remove alphaMovieView.seekTo(currentPosition); it play for start/

Notworking in Huawei devices

been using the library but I found that Huawei devices is showing green color instead of the alpha transparent.

Do not Change Color?

At the same activity, alpha color not changing. If i use two color code like black and green in same view then only one color is working. I would take different view to work with other color. Is it possible to work different color code in same View ? If is it possible then please tell me how to do.
Thank you.

public class MainActivity extends AppCompatActivity {


  1. ERROR in /storage/emulated/0/.sketchware/mysc/620/app/src/main/java/com/my/newproject2/MainActivity.java (at line 64)
    public class MainActivity extends AppCompatActivity {
    ^^^^^^^^^^^^
    The nested type MainActivity cannot hide an enclosing type

  1. ERROR in /storage/emulated/0/.sketchware/mysc/620/app/src/main/java/com/my/newproject2/MainActivity.java (at line 64)
    public class MainActivity extends AppCompatActivity {
    ^^^^^^^^^^^^
    Illegal modifier for the local class MainActivity; only abstract or final is permitted

2 problems (2 errors)

MP4 from InputStream, is that possible?

Can I play some MP4 video obtained from an InputStream using alpha-movie. The video can't be stored in the local files system for security purposes. Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.