MainActivity.java

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.View;
import android.widget.Button;

import com.netcompss.ffmpeg4android.CommandValidationException;
import com.netcompss.ffmpeg4android.GeneralUtils;
import com.netcompss.loader.LoadJNI;


public class MainActivity extends AppCompatActivity {

    Button btnTest;
    WaterMarkHelper myHelper;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        // for Android 6 and above, add permission
        GeneralUtils.checkForPermissionsMAndAbove(MainActivity.this, false);
        btnTest = (Button)findViewById(R.id.btnTest);
        btnTest.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
//                try {
//                    waterMarkVideo();
//                } catch (CommandValidationException e) {
//                    e.printStackTrace();
//                }
                myHelper = new WaterMarkHelper("/sdcard/videokit/in.mp4",
                        "/sdcard/videokit/watermark.png",
                        "/sdcard/testOut.mp4",
                        "main_w/2 - overlay_w/2",
                        "main_h/2 - overlay_h/2");
                try {
                    myHelper.addVideoWaterMark(MainActivity.this);
                } catch (CommandValidationException e) {
                    e.printStackTrace();
                }
            }
        });


    }
    /*
    private void test(){
        GeneralUtils.checkForPermissionsMAndAbove(MainActivity.this, true);
        LoadJNI vk = new LoadJNI();
        try {
            String workFolder = getApplicationContext().getFilesDir().getAbsolutePath();
            String[] complexCommand = {"ffmpeg","-i", "/sdcard/videokit/in.mp4"};
            vk.run(complexCommand , workFolder , getApplicationContext());
            Log.i("test", "ffmpeg4android finished successfully");
        } catch (Throwable e) {
            Log.e("test", "vk run exception.", e);
        }
    }
    private void waterMarkVideo() throws CommandValidationException {
        LoadJNI vk = new LoadJNI();
        String workFolder = getApplicationContext().getFilesDir() + "/";
        String videoPath = "/sdcard/videokit/in2.mp4"; //可任意
        String videoOutputWidth = "320";
        String videoOutputHeight = "240";
        String waterMarkPath = "/sdcard/videokit/watermark.png"; //可任意
        String overlayX = "main_w/2 - overlay_w/2";//影片寬=main_w, 浮水印寬=overlay_w
        String overlayY = "main_h/2 - overlay_h/2";//影片高=main_h, 浮水印寬=overlay_h
        String videoOutputPath = "/sdcard/videokit/testOut.mp4"; //可任意
        String videoOutputFps = "30";
        String imgBiteRate = "15496k";
        String voiceBiteRate = "48000";
        String voiceChannelAmount = "2";
        String voiceSampleFrequency = "22050";// 聲音的取樣頻率

        String videoOutputSize = videoOutputWidth+"x"+videoOutputHeight; //= "320x240";
        String waterMarkSettings = "movie="+waterMarkPath+" [watermark]; [in][watermark] overlay="
                +overlayX+":"+overlayY+" [out]";
        // overlay = 寬:高, 影片寬main_w, 浮水印寬overlay_w
        //String waterMarkSettings = "movie=/sdcard/videokit/watermark.png [watermark]; [in][watermark] overlay=main_w-overlay_w-10:10 [out]";
        String[] complexCommand = {"ffmpeg","-y" ,"-i", videoPath,"-strict","experimental",
                "-vf", waterMarkSettings,"-s", videoOutputSize,"-r", videoOutputFps, "-b", imgBiteRate,
                "-vcodec", "mpeg4","-ab", voiceBiteRate, "-ac", voiceChannelAmount, "-ar", voiceSampleFrequency, videoOutputPath};
        //vk.run(complexCommand,workFolder,getApplicationContext());
        vk.run(complexCommand,workFolder,getApplicationContext());

    }
    */
}

activity_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    tools:context="com.yutouch.watermarkapp.MainActivity">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:orientation="vertical">

        <Button
            android:id="@+id/btnTest"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Button" />

        <TextView
            android:id="@+id/textView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:text="Hello World!"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

    </LinearLayout>

</LinearLayout>

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.yutouch.watermarkapp">
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
    <uses-permission android:name="android.permission.WAKE_LOCK" />


    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:roundIcon="@mipmap/ic_launcher_round"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity android:name=".MainActivity">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>

</manifest>

results matching ""

    No results matching ""