首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Android中向视频/ VideoURI添加水印/文本

如何在Android中向视频/ VideoURI添加水印/文本
EN

Stack Overflow用户
提问于 2017-08-28 07:09:30
回答 1查看 4.2K关注 0票数 0

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

但我需要实现这样的特性:

在视频的某个角落,我需要添加一些水印/文本。例如,我录制了一个视频,我需要添加水标记到视频(任何角落)。例如,我想添加abc.com,比如dubsmash应用程序。

在dubsmash应用程序中录制了一个水渍,对不对?

EN

回答 1

Stack Overflow用户

发布于 2017-08-28 08:03:02

下面是我在视频中添加图像的方法,我在这里将图像路径作为参数传递,首先初始化我的ffmpeg,然后在后台线程中执行命令,将视频转换为在defined和command处定义图像的位置

代码语言:javascript
复制
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();
    }
}
票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45913512

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档