2017-08-28 121 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

你需要在你的項目中添加這個庫並做必要的修改,我剛給你提供了我使用的特定代碼,你需要根據你的需要來改變它,這一切都可以幫助親愛的人沒有人會爲您編寫代碼, 您需要期待它 –

相關問題