在视频上添加文字和图像后。视频质量输出松动

时间:2019-06-28 06:08:02

标签: android ffmpeg

我正在使用ffmpeg在图像上添加图像和文本。该命令运行正常,但视频质量下降。如何保持视频质量。

   String  imgcmd[]=new String[]{"-i", videopath ,"-i", imgpath,"-filter_complex", "[1]scale=720:1280[b];[0][b] overlay=main_w-overlay_w:main_h-overlay_h,drawtext=text="+text+":fontcolor=#FFFFFF:fontsize=18:x=(w-text_w)/2:y=(h-text_h)-145:fontfile="+fontpath ,  "-preset" ,"ultrafast","-codec:a", "copy",output};


   public void LoadFFmpegLibrary()
     {
    if(ffmpeg!=null)
    {

        try {
            ffmpeg.loadBinary(new LoadBinaryResponseHandler() {

                @Override
                public void onStart() {
                    Log.e("ffmpeg","Start to load");
                }

                @Override
                public void onFailure() {
                    Log.e("ffmpeg","failed to load");
                }

                @Override
                public void onSuccess() {

                    imageprogressDialog=  

  ConstantClass.ShowProgressDialog(VideoRecordingActivity.this,"Loading");
                    imageprogressDialog.show();
                    SharedPreferences 
        sharedPreferences=getSharedPreferences("shared",MODE_PRIVATE);
                    String 
      imgpath=sharedPreferences.getString("imgpath","");
                    String 
    fontpath=sharedPreferences.getString("fontpath","");
                    String  
      videopath=sharedPreferences.getString("videopath","");
                     //"-crf" ,"24"0
                    String  imgcmd[]=new String[]{"-i", videopath ,"-i", 
        imgpath,"-filter_complex", "[1]scale=720:1280[b];[0][b] 
       overlay=main_w-overlay_w:main_h- 
       overlay_h,drawtext=text="+text+":fontcolor=#FFFFFF:fontsize=18:x= 
       (w-text_w)/2:y=(h-text_h)-145:fontfile="+fontpath ,  "-preset" 
         ,"ultrafast","-codec:a", "copy",output};

                    ImageCommand(imgcmd);

                }

                @Override
                public void onFinish() {

                }
            });
        } catch (FFmpegNotSupportedException e) {
            // Handle if FFmpeg is not supported by device
            Log.e("ffmpeg",e.toString());
        }
    }
}





  public void ImageCommand(String command[])
{

    ffmpeg = FFmpeg.getInstance(VideoRecordingActivity.this);
    try {
        // to execute "ffmpeg -version" command you just need to pass "-version"
        ffmpeg.execute(command, new ExecuteBinaryResponseHandler() {

            @Override
            public void onStart() {
                Log.e("ffmpeg","Exaction Start");
            }

            @Override
            public void onProgress(String message) {}

            @Override
            public void onFailure(String message) {
                imageprogressDialog.dismiss();
                Log.e("ok",message);
            }

            @Override
            public void onSuccess(String message) {
                imageprogressDialog.dismiss();

                Toast.makeText(VideoRecordingActivity.this,"Video Edited Successfully", Toast.LENGTH_LONG).show();
                PlayVideo();
                playvideo.setVisibility(View.VISIBLE);

            }

            @Override
            public void onFinish() {
                imageprogressDialog.dismiss();
                Log.e("ffmpeg","Exaction Start");
            }
        });
    } catch (FFmpegCommandAlreadyRunningException e) {
        imageprogressDialog.dismiss();
        Log.e("ffmpeg",e.toString());
    }
}

1 个答案:

答案 0 :(得分:1)

此答案与您提出的评论有关,您想在视频末尾像youtube视频一样添加文字。这是一个执行命令,让我知道

allprojects {
  // ...
  configurations.all {
    resolutionStrategy {
      force 'com.google.firebase:firebase-common:17.0.0'
      force 'com.google.android.gms:play-services-basement:16.2.0'
      force 'com.google.firebase:firebase-iid:16.0.0'
      force 'com.google.firebase:firebase-auth:17.0.0'
    }
  }
}