Overlay image on video using ffmpeg in android

2019-08-24 03:14发布

问题:

I am trying to overlay an image on video and save it. I saved the image in drawable, and use ffmpeg to do this. According to https://www.factorialcomplexity.com/blog/2016/12/11/adding-animated-overlays-to-videos-on-android.html I used below code to handle the video.

String strFilter = "[1:v]scale=h=-1:w=" + 100 + "[overlay_scaled],"
                + "[0:v][overlay_scaled]overlay=eval=init:x=W*" + 0.2
                + ":y=H*" + 0.2;

    String[] сmd = new String[]{
            "-i",
            videoPath,
            "-itsoffset",
            "0",
            "-i",
            "drawable://" + R.drawable.frame_green,
            "-filter_complex",
            strFilter,
            "-preset",
            "ultrafast",
            "-g",
            "120",
            getOutputMediaFile(MEDIA_TYPE_VIDEO).toString()
    };

try {
        ffmpeg.execute(cmdd, new ExecuteBinaryResponseHandler() {

            @Override
            public void onStart() {
            }

            @Override
            public void onProgress(String message) {
            }

            @Override
            public void onFailure(String message) {
            }

            @Override
            public void onSuccess(String message) {
            }

            @Override
            public void onFinish() {
            }
        });
    } catch (FFmpegCommandAlreadyRunningException e) {
        // Handle if FFmpeg is already running
        Log.i("12345", " FFMPGE execute failed");
    }

there are no exceptions when running the app, but there is no new video created with water marker. Can you guys help me have a look? is there something with the code above?

log:

11-28 17:01:15.655 29944-29944/com.pictureframe D/FFmpeg: Build.CPU_ABI : armeabi-v7a
11-28 17:01:15.682 29944-29944/com.pictureframe I/FFmpeg: Loading FFmpeg for armv7 CPU
11-28 17:01:16.346 29944-30625/com..pictureframe D/FFmpeg: Running publishing updates method