android - 在视频上添加文本和图像后。视频质量的输出丢失

标签 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());
    }
}

最佳答案

这个答案是关于您的评论,您询问在视频末尾添加文本的问题,例如 youtube 视频。这是一个命令执行,让我知道

ffmpeg -i input.mp4 -i 1.jpg -f lavfi -t 5 -i color=#000000:s=1280x720 -filter_complex "[0][1]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[video];[2]drawtext=text="FINAL_VIDEO_TEST":fontcolor=#FFFFFF:fontsize=50:x=(w-text_w)/2:y=(h-text_h)-145[textOverlay];[video][textOverlay]concat=n=2:v=1:a=0" -preset ultrafast -codec:a copy mvm/testOut.mp4

关于android - 在视频上添加文本和图像后。视频质量的输出丢失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56801711/

相关文章:

android - 从类型 'struct in_addr' 分配给类型 'int' 时的类型不兼容

Android Places API PlaceTypes 不存在?

Android+Arduino蓝牙通讯

android - HandlerThread 阻塞 UI android

android - 具有不同布局的第一个可见项目的 ListView

image - 如何使用ffmpeg从视频中制作平铺图像

windows - 如何从 FFMPEG 生成 SDP 文件

windows-phone-8 - Windows Phone 8 上的视频处理库

FFMPEG 选择特定语言的第一个音频流

ffmpeg - GeForce 是否支持使用 FFmpeg 进行 GPU 加速的视频处理?