0

I'm developing video recorder app. Right now I'm able to record and saving video and successfully converting video as URI.

But I need to implement feature like this:

Some corner of the video I need to add some watermark / text. For example I recorded one video I need to add water mark to that video (any corner). For example I want to add abc.com, like dubsmash app.

In dubsmash app after recording one water mark add right?

halfer
  • 19,824
  • 17
  • 99
  • 186
Tirupatirao
  • 165
  • 3
  • 9
  • https://stackoverflow.com/a/25504718/5502638 here is your answer – Akash Dubey Aug 28 '17 at 07:12
  • @AkashDubey without ffmpeg ... is there any other availability because im not getting ffmpeg usage – Tirupatirao Aug 28 '17 at 07:18
  • No, without ffmpeg u have to do it using native MediaParser and there are no demos available for that!! – Akash Dubey Aug 28 '17 at 07:25
  • so ffmpeg only better option you are saying right?? – Tirupatirao Aug 28 '17 at 07:35
  • then i have a videoURI how can i add watermark could you tell me how to achieve please///... – Tirupatirao Aug 28 '17 at 07:36
  • Do you want to add watermarks to videos in an Android app itself? Unless you are building a video editor, I would do this on a (Linux) server, where ffmpeg will be available. – halfer Aug 28 '17 at 08:21
  • Please read [Under what circumstances may I add “urgent” or other similar phrases to my question, in order to obtain faster answers?](//meta.stackoverflow.com/q/326569) - the summary is that this is not an ideal way to address volunteers, and is probably counterproductive to obtaining answers. Please refrain from adding this to your questions. – halfer Aug 28 '17 at 08:21
  • 1
    yes after recording video i'm generating video URI i need to add some water mark text to that video in bottom right @halfer my machine is mac and android studio 2.3.3 – Tirupatirao Aug 28 '17 at 09:05

1 Answers1

3

below is my method to add image in a video, I am passing image path as a parameter Here I am first initializing my ffmpeg and then by executing the command in background thread I am converting the video for having the Image at position defined at xposition and ypposition

private void doReplaceTheFrame(String image) {



    String[] complexCommand;

    int frameCount = (int) (timeInsec * 30);
    int startTimeFrame = frameCount - 5;

    File f = new File("/storage/emulated/0");

    String rootPath = f.getPath();


    complexCommand =
            new String[]{"-y", "-i", VideoPath1, "-i", image, "-filter_complex",
                    "[0:v][1:v]overlay=" + xPosition + ":" + yPosition + 10 +
                            ":enable='between" + "(t," + 0 + "," + endTimeOfVideo + ")"
                            + "'[out]", "-map", "[out]", rootPath + "/outputFrame.mp4"};


    FFmpeg ffmpeg = FFmpeg.getInstance(this);

    try {
        //Load the binary
        ffmpeg.loadBinary(new LoadBinaryResponseHandler() {

            @Override
            public void onFailure() {
            }

            @Override
            public void onStart() {
            }


            @Override
            public void onSuccess() {
            }

            @Override
            public void onFinish() {
            }
        });
    } catch (FFmpegNotSupportedException e) {
        // Handle if FFmpeg is not supported by device
        Toast.makeText(getApplicationContext(), "Not Supported by Device",
                Toast.LENGTH_LONG).show();
    }

    try {

        final String finalRootPath = rootPath;
        ffmpeg.execute(complexCommand, new FFmpegExecuteResponseHandler() {
            @Override
            public void onSuccess(String message) {
                Log.d("Success", message);

                Toast.makeText(getApplicationContext(), "Successful" + finalRootPath
                                .toString(),
                        Toast.LENGTH_LONG).show();
                Uri path = Uri.parse(finalRootPath + "/outputFrame.mp4");
                playVideo(path.toString());

            }

            @Override
            public void onStart() {
                Log.d("Start", "merge started");
            }

            @Override
            public void onProgress(String message) {
                Log.d("progress", message);
                pd.show();
            }

            @Override
            public void onFailure(String message) {
                Log.d("failure", message);
                pd.dismiss();

            }


            @Override
            public void onFinish() {
                Log.d("finish", "merge finish");
                pd.dismiss();
            }
        });
    } catch (FFmpegCommandAlreadyRunningException e) {
        e.printStackTrace();
    }
}
Akash Dubey
  • 1,508
  • 17
  • 34
  • is need to install any library if yes means provide me library link... thanks – Tirupatirao Aug 28 '17 at 08:58
  • its not working it showing exception like this files/ffmpeg has text relocations. This is wasting memory and prevents security hardening. Please fix. @AkashDubey – Tirupatirao Aug 28 '17 at 10:44
  • You need to add this library in your project and do the needful changes, I have just given you the specific code which I used, u need to change it as per your needs, that's all one can help dear no one will write code for you, You need to look forward to it – Akash Dubey Aug 28 '17 at 11:31