0

I am trying to add watermark on video file using FFmpegFrameFilter but watermark is not adding on output video. also output video not correct getting only one second video where video length is 8 seconds. please help me. here my code

  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();
        }
    }


}
Hitesh Gehlot
  • 1,307
  • 1
  • 15
  • 30
  • This is the command i'm using for this....may help you...ffmpeg -i video.mp4 -i path+watermark.png -filter_complex "overlay=10:10" video.mp4 – kulvinder Aug 05 '17 at 06:44
  • @kulvinder i am using this library. compile group: 'org.bytedeco', name: 'javacv', version: '1.3'. can you please tell me how can i execute this command briefly – Hitesh Gehlot Aug 05 '17 at 09:19
  • okey let me try to explain: follow this file https://github.com/WritingMinds/ffmpeg-android-java/blob/master/app/src/main/java/com/github/hiteshsondhi88/sampleffmpeg/Home.java there is method in this class execFFmpegBinary(string[] command) just call this method by passing String command=""ffmpeg", "-i", "video.mp4", "-i", "path+watermark.png", "-filter_complex", "overlay=10:10", "video.mp4""; ...hope it will help you lot – kulvinder Aug 05 '17 at 09:41
  • i know about writingMinds ffmpeg library but i can't use both library in project. getting unstisfied link error. in or.bytedoco gradle there is no way to execute comands. I can only use FFmpegFrameFilter for add watermark on video – Hitesh Gehlot Aug 05 '17 at 09:48
  • Hi @hitesh, Have you found any solution? – Deepak Gupta Jan 25 '18 at 10:01

0 Answers0