WaterMarkHelper.java

import android.content.Context;
import android.util.Log;

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

/**
 * Created by johnnytu on 2017/5/26.
 */

public class WaterMarkHelper {
    private String videoPath; //可任意
    private String waterMarkPath; //可任意
    private String overlayX;//影片寬=main_w, 浮水印寬=overlay_w
    private String overlayY;//影片高=main_h, 浮水印寬=overlay_h
    private String videoOutputPath; //可任意
    private String videoOutputWidth;
    private String videoOutputHeight;
    private String videoOutputFps;
    private String imgBiteRate;
    private String voiceBiteRate;
    private String voiceChannelAmount;
    private String voiceSampleFrequency;// 聲音的取樣頻率

    // 以下參數產生自 以上參數
    private String videoOutputSize;
    private String waterMarkSettings;
    private String[] complexCommand;
    WaterMarkHelper(String inputVideoPath,String inputWaterMarkPath,String outputVideoPath,String waterMarkX,String waterMarkY){
        videoPath = inputVideoPath;
        waterMarkPath = inputWaterMarkPath;
        videoOutputPath = outputVideoPath;
        overlayX = waterMarkX;
        overlayY = waterMarkY;
        videoOutputWidth = "";
        videoOutputHeight = "";
        videoOutputFps = "";
        imgBiteRate = "";
        voiceBiteRate = "";
        voiceChannelAmount = "";
        voiceSampleFrequency = "";// 聲音的取樣頻率
        videoOutputSize = videoOutputWidth+"x"+videoOutputHeight; //= "320x240";
        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]";
        complexCommand = new String[]{"ffmpeg", "-y", "-i", videoPath, "-strict", "experimental",
                "-vf", waterMarkSettings, "-vcodec", "mpeg4", videoOutputPath};
        //vk.run(complexCommand,workFolder,getApplicationContext());
    }

    public void addVideoWaterMark(Context context) throws CommandValidationException {
        Log.d("WaterMarkHelper","starting addVideoWaterMark");
        long startTime = System.currentTimeMillis();
        LoadJNI vk = new LoadJNI();
        String workFolder = context.getApplicationContext().getFilesDir() + "/";
        vk.run(complexCommand,workFolder,context.getApplicationContext());
        Log.d("WaterMarkHelper","finish addVideoWaterMark, took "+
                (System.currentTimeMillis()-startTime)/1000+"seconds.");
    }


}

results matching ""

    No results matching ""