Я использую 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());
}
}