24
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Androidで、Mp4にウォータマークつけたり、フィルターかけたりする

Last updated at Posted at 2018-01-29

#Mp4Composer-android

Mp4Composer-android

AndroidでMp4にウォータマークつけたり、フィルターかけたりするのを簡単にできるライブラリを作成しました。
yprestoさん記事ライブラリを大変参考にして作成しました。

Gradle

    dependencies {
        // jCenter
        implementation 'com.daasuu:Mp4Composer-android:0.1.0'
    }

Usage

ウォーターマークをてっとり早くつけたいという場合は下記で完了です。

    new Mp4Composer(srcMp4Path, destMp4Path)
            .filter(new GlWatermarkFilter(watermarkBitmap, GlWatermarkFilter.Position.RIGHT_BOTTOM))
            .start();

フィルターをかけたいんだよねという場合は下記で完了です。

    new Mp4Composer(srcMp4Path, destMp4Path)
            .filter(new GlSepiaFilter())
            .start();

その他、オプション、ビルダーメソッドは基本的に下記の感じになります。

    new Mp4Composer(srcMp4Path, destMp4Path)
            .rotation(Rotation.ROTATION_90)
            .size((width) 540, (height) 960)
            .fillMode(FillMode.PRESERVE_ASPECT_FIT)
            .filter(new GlSepiaFilter())
            .listener(new Mp4Composer.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)
videoBitrate Set Video Bitrate, default video bitrate is 0.25 * 30 * outputWidth * outputHeight

フィルターをカスタムする場合は、GlFilterを継承すれば作成可能です。


是非、Mp4Composer-androidをご覧になり、Starもつけていただけるととても嬉しく思います。 こんなフィルターも作れるとか、機能追加したい等のpull reqestも大歓迎です!
24
7
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
24
7

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?