Easy steps to watermark a video(AS+FFmpeg)

How to import FFmpeg in Android project (Only use Java)

  1. Download this https://drive.google.com/file/d/0B2aT0QoEmtuaN0VJZ2Z4ODY3T2s/view
  2. File => New => import module => go find the folder downloaded at step1:
    ffmpeg4android_demo_studio\ffmpeg4android_lib
    
  3. Add permission in AndroidManifest.xml

     <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
     <uses-permission android:name="android.permission.WAKE_LOCK" />
    

    if the version is higher than Android 6, add the following code in onCreate() of your Activity

         GeneralUtils.checkForPermissionsMAndAbove(MainActivity.this, false);
    

    Alt+Enter if encounter red font, AndroidStudio would help you to modify "build.gradle(Module)"

  4. (Not sure if necessary) In build.gradle(Module)

     Android{
     .......
         defaultConfig{
         ....
             targetSdkVersion ...
             <Add the following code>
             ndk{
                 abiFilter "armeabi-v7a"
             }
         }
     }
     .....
     dependencies{
         ...
         <Add the following code if doesn't exist>
         compile project(':ffmpeg4android_lib')
     }
    
  5. add following code in "gradle.properties"

     android.useDeprecatedNdk=true
    

    and then async project

    How to use WaterMarkHelper(by Johnny Tu) to add watermark on video

  6. After import "WaterMarkHelper.java" in your project, declare the following in your Activity
     WaterMarkHelper myHelper;
    
  7. initialize myHelper with arguments

    Arguments description:

         String inputVideoPath        (ex:"/sdcard/input.mp4")
         String inputWaterMarkPath    (ex:"/sdcard/waterMark.png")
         String outputVideoPath        (ex:"/sdcard/output.mp4")
         String waterMarkX        the X-coordinate    
             Video width: main_w, Video height: main_h, Image Width: overlay_w, Image Height: overlay_h
         String waterMarkY
    

    example code:

     myHelper = new WaterMarkHelper("/sdcard/in.mp4", //be sure that in.mp4 exist in /sdcard/
                         "/sdcard/watermark.png", //be sure that watermark.png exist in /sdcard/
                         "/sdcard/testOut.mp4", //
                         "main_w/2 - overlay_w/2", // in the middle of X-axis
                         "main_h/2 - overlay_h/2"); // in the middle of Y-axis
    
  8. adding watermark on video

     myHelper.addVideoWaterMark(MainActivity.this); //MainActivity改成你自己的Activity
    

    there should be try/catch exception outside the above code, press Alt+Enter should work.

    example code:

         try {
                 myHelper.addVideoWaterMark(MainActivity.this);
         } catch (CommandValidationException e) {
                 e.printStackTrace();
         }
    

References:

Android Warzone - FFmpeg4Android

results matching ""

    No results matching ""