Android ffmpeg如何在视频文件上添加水印

时间:2017-08-05 06:37:45

标签: android ffmpeg android-ffmpeg

我正在尝试使用FFmpegFrameFilter在视频文件上添加水印,但水印没有添加输出视频。也输出视频不正确只获得视频长度为8秒的一秒视频。请帮我。这是我的代码

  class FinishWaterMarkTask extends ProgressDialogTask<Void, Integer, Void> {


    private FFmpegFrameGrabber VIDEO_GRABBER;
    private FFmpegFrameRecorder videoRecorder;
    private FFmpegFrameFilter filter;


    @Override
    protected Void doInBackground(Void... params) {


        Frame tempVideoFrame;
        try {
            VIDEO_GRABBER.start();
            String OutputPath = path + outputVideo;
            initVideoRecorder(OutputPath);
            filter.start();
            while (VIDEO_GRABBER.grab() != null) {
                tempVideoFrame = VIDEO_GRABBER.grabImage();
                if (tempVideoFrame != null) {
                    filter.push(tempVideoFrame);
                    tempVideoFrame = filter.pull();
                    videoRecorder.record(tempVideoFrame);
                }
            }
            videoRecorder.stop();
            filter.stop();
            videoRecorder.release();
            VIDEO_GRABBER.stop();
            VIDEO_GRABBER.release();
        } catch (FrameGrabber.Exception e) {
            e.printStackTrace();
        } catch (FrameRecorder.Exception e) {
            e.printStackTrace();
        } catch (FrameFilter.Exception e) {
            e.printStackTrace();
        }
        return null;
    }

    private void initVideoRecorder(String path) {
        try {
 VIDEO_GRABBER = new FFmpegFrameGrabber(mVideo.getAbsolutePath());
            String imgPath = audioPath + "jodelicon.png";
            filter = new FFmpegFrameFilter("movie=" + imgPath + " [logo];[in][logo]overlay=0:0:1:format=rgb [out]", VIDEO_GRABBER.getImageWidth(), VIDEO_GRABBER.getImageHeight());
            videoRecorder = FFmpegFrameRecorder.createDefault(path, VIDEO_GRABBER.getImageWidth(), VIDEO_GRABBER.getImageHeight());
            videoRecorder.setAudioChannels(VIDEO_GRABBER.getAudioChannels());
            videoRecorder.setFrameRate(VIDEO_GRABBER.getFrameRate());

            videoRecorder.start();
        } catch (FrameRecorder.Exception e) {
            e.printStackTrace();
        }
    }


}

0 个答案:

没有答案