2017-08-28 119 views
-2

我正在开发录像机应用程序。现在我可以录制和保存视频并成功将视频转换为URI。如何在Android Studio中为视频/ VideoURI添加水印/文字

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

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

在dubsmash应用程序录制一个水印后添加右键?

+0

https://stackoverflow.com/a/25504718/5502638 这里是你的答案 –

+0

@AkashDubey没有ffmpeg的......还有没有其他的可用性,因为我不是让ffmpeg的使用 – Tirupatirao

+0

不,如果没有ffmpeg,你必须使用原生MediaParser来做,并且没有可用的演示! –

回答

0

以下是我在视频中添加图像的方法,我将图像路径作为参数传递 这里我首先初始化我的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(); 
    } 
} 
+0

是需要安装任何库,如果是的意思是提供给我库链接...谢谢 – Tirupatirao

+0

它不工作它显示这样的异常 文件/ ffmpeg文本重定位。这浪费了内存并阻止了安全强化。请修复。 @AkashDubey – Tirupatirao

+0

你需要在你的项目中添加这个库并做必要的修改,我刚给你提供了我使用的特定代码,你需要根据你的需要来改变它,这一切都可以帮助亲爱的人没有人会为您编写代码, 您需要期待它 –

相关问题