【问题标题】:How to add watermark / text to the video / VideoURI in Android Studio如何在 Android Studio 中为视频/VideoURI 添加水印/文字
【发布时间】:2017-08-28 07:09:30
【问题描述】:

我正在开发录像机应用程序。现在我可以录制和保存视频,并成功地将视频转换为 URI。

但我需要实现这样的功能:

视频的某个角落我需要添加一些水印/文字。例如,我录制了一个视频,我需要在该视频(任何角落)中添加水印。比如我要添加abc.com,比如dubsmash app。

在dubsmash app中录制一个水印后添加对吗?

【问题讨论】:

  • @AkashDubey without ffmpeg ...是否还有其他可用性,因为我没有使用 ffmpeg
  • 不,如果没有 ffmpeg,您必须使用本机 MediaParser 来完成,并且没有可用的演示!
  • 所以 ffmpeg 只有你说的更好的选择??
  • 那我有一个videoURI我怎么加水印你能告诉我如何实现请///...

标签: android video text add watermark


【解决方案1】:

以下是我在视频中添加图像的方法,我将图像路径作为参数传递 在这里,我首先初始化我的 ffmpeg,然后通过在后台线程中执行命令,我将视频转换为在 xposition 和 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();
    }
}

【讨论】:

  • 如果是的话需要安装任何库意味着提供我库链接...谢谢
  • 它不工作它显示像这样的异常文件/ffmpeg 有文本重定位。这会浪费内存并防止安全加固。请修复。 @AkashDubey
  • 您需要在您的项目中添加这个库并进行必要的更改,我刚刚给您提供了我使用的具体代码,您需要根据您的需要进行更改,这一切都可以提供帮助亲爱的,没人会为你写代码,你需要期待
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-12-05
  • 1970-01-01
  • 1970-01-01
  • 2014-10-27
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多