我在Android应用中使用FFMpeg Android this link
将视频裁剪为1:1比例,即高度=宽度
以下命令在Android设备上运行良好, Api< 24 但 Api 24失败。我还在下面粘贴了我的日志分析,感谢有人可以帮我解决这个问题。
public static String cropVideo(final Context context, final File file, final BaseCaptureInterface mBaseCaptureListener) {
String croppedUrl = "";
FFmpeg ffmpeg = FFmpeg.getInstance(context.getApplicationContext());
try {
croppedUrl = file.getParent() + "/Cropped_" + file.getName();
String[] cmds = {"-i", file.getAbsolutePath(), "-vf", "crop=out_h=in_w", "-threads", "5", "-preset" ,"ultrafast","-strict","-2",croppedUrl};
ffmpeg.execute(cmds, new ExecuteBinaryResponseHandler() {
@Override
public void onStart() {
Log.d(TAG, "cropVideo:onStart()");
}
@Override
public void onProgress(String message) {
Log.d(TAG, "cropVideo:onProgress(): " + message);
}
@Override
public void onFailure(String message) {
Log.d(TAG, "cropVideo:onFailure(): " + message);
Toast.makeText(context, "Failed to Crop the video", Toast.LENGTH_SHORT).show();
}
@Override
public void onSuccess(String message) {
file.delete();
mBaseCaptureListener.videoCropStatus(true);
Log.d(TAG, "cropVideo:onSuccess(): " + message);
}
@Override
public void onFinish() {
Log.d(TAG, "cropVideo:onFinish()");
}
});
} catch (FFmpegCommandAlreadyRunningException e) {
Log.d(TAG, "cropVideo:error: " + e);
}
return croppedUrl;
}
观察:下面是onProgress()在裁剪期间的通过和失败日志的比较。在失败日志中,帧初始值为0,然后突然跳转到2392,大小也会按比例增加。而在Pass日志中,框架和尺寸的增加非常平滑。 我想知道我的命令字符串[]是否需要一些更改。如果您有任何建议,请告诉我。
传递日志:
Press [q] to stop, [?] for help
frame= 0 fps=0.0 q=0.0 size= 0kB time=00:00:01.00 bitrate= 0.4kbits/s speed=1.97x
frame= 18 fps= 18 q=0.0 size= 0kB time=00:00:01.34 bitrate= 0.3kbits/s dup=9 drop=0 speed=1.33x
frame= 26 fps= 17 q=0.0 size= 0kB time=00:00:02.00 bitrate= 0.2kbits/s dup=13 drop=0 speed=1.33x
frame= 48 fps= 18 q=0.0 size= 0kB time=00:00:02.00 bitrate= 0.2kbits/s dup=24 drop=0 speed=0.744x
frame= 48 fps= 15 q=0.0 size= 0kB time=00:00:02.60 bitrate= 0.1kbits/s dup=24 drop=0 speed=0.814x
frame= 58 fps= 15 q=29.0 size= 25kB time=00:00:03.00 bitrate= 68.1kbits/s dup=29 drop=0 speed=0.802x
frame= 62 fps= 14 q=29.0 size= 45kB time=00:00:03.00 bitrate= 122.6kbits/s dup=31 drop=0 speed=0.679x
frame= 68 fps= 14 q=29.0 size= 68kB time=00:00:03.00 bitrate= 184.3kbits/s dup=34 drop=0 speed=0.608x
frame= 74 fps= 13 q=29.0 size= 96kB time=00:00:03.00 bitrate= 262.1kbits/s dup=37 drop=0 speed=0.534x
frame= 79 fps= 13 q=29.0 size= 119kB time=00:00:03.00 bitrate= 324.3kbits/s dup=39 drop=0 speed=0.482x
frame= 81 fps= 12 q=29.0 size= 131kB time=00:00:03.20 bitrate= 335.2kbits/s dup=40 drop=0 speed=0.475x
frame= 81 fps= 11 q=29.0 size= 131kB time=00:00:03.98 bitrate= 268.9kbits/s dup=40 drop=0 speed=0.551x
frame= 92 fps= 12 q=29.0 size= 197kB time=00:00:04.01 bitrate= 402.0kbits/s dup=45 drop=0 speed=0.516x
frame= 96 fps= 11 q=29.0 size= 222kB time=00:00:04.01 bitrate= 452.9kbits/s dup=47 drop=0 speed=0.479x
frame= 101 fps= 11 q=29.0 size= 245kB time=00:00:04.01 bitrate= 499.8kbits/s dup=49 drop=0 speed=0.44x
frame= 105 fps= 11 q=29.0 size= 268kB time=00:00:04.01 bitrate= 546.6kbits/s dup=51 drop=0 speed=0.414x
frame= 112 fps= 11 q=29.0 size= 310kB time=00:00:04.09 bitrate= 620.0kbits/s dup=54 drop=0 speed= 0.4x
frame= 115 fps= 10 q=29.0 size= 326kB time=00:00:04.09 bitrate= 652.1kbits/s dup=55 drop=0 speed=0.374x
frame= 119 fps= 10 q=29.0 size= 355kB time=00:00:04.09 bitrate= 710.8kbits/s dup=57 drop=0 speed=0.355x
frame= 119 fps=7.1 q=-1.0 Lsize= 671kB time=00:00:04.13 bitrate=1327.9kbits/s dup=57 drop=0 speed=0.245x
video:604kB audio:62kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.717086%
[libx264 @ 0xb5b08800] frame I:1 Avg QP:23.35 size: 24768
Fail Logs:
Stream #0:1 -> #0:1 (aac (native) -> aac (native))
Press [q] to stop, [?] for help
frame= 0 fps=0.0 q=0.0 size= 0kB time=00:00:00.81 bitrate= 0.5kbits/s speed=1.61x
frame= 0 fps=0.0 q=0.0 size= 0kB time=00:00:01.57 bitrate= 0.2kbits/s speed=1.56x
frame= 0 fps=0.0 q=0.0 size= 0kB time=00:00:02.30 bitrate= 0.2kbits/s speed=1.51x
frame= 0 fps=0.0 q=0.0 size= 0kB time=00:00:03.22 bitrate= 0.1kbits/s speed=1.58x
frame= 0 fps=0.0 q=0.0 size= 0kB time=00:00:04.13 bitrate= 0.1kbits/s speed=1.63x
frame= 0 fps=0.0 q=0.0 size= 0kB time=00:00:04.90 bitrate= 0.1kbits/s speed=1.61x
frame= 0 fps=0.0 q=0.0 size= 0kB time=00:00:05.82 bitrate= 0.1kbits/s speed=1.64x
frame= 2392 fps=111 q=22.0 size= 1059kB time=00:01:19.61 bitrate= 109.0kbits/s dup=2389 drop=0 speed=3.68x
frame= 2416 fps=109 q=27.0 size= 1059kB time=00:01:20.41 bitrate= 107.9kbits/s dup=2390 drop=0 speed=3.63x
frame= 2438 fps=108 q=27.0 size= 1059kB time=00:01:21.14 bitrate= 106.9kbits/s dup=2390 drop=0 speed=3.58x
frame= 2462 fps=106 q=26.0 size= 1060kB time=00:01:21.94 bitrate= 105.9kbits/s dup=2393 drop=0 speed=3.54x
frame= 2484 fps=105 q=25.0 size= 1060kB time=00:01:22.68 bitrate= 105.0kbits/s dup=2395 drop=0 speed= 3.5x
frame= 2506 fps=104 q=24.0 size= 1060kB time=00:01:23.41 bitrate= 104.1kbits/s dup=2397 drop=0 speed=3.45x
frame= 2530 fps=103 q=26.0 size= 1060kB time=00:01:24.21 bitrate= 103.1kbits/s dup=2397 drop=0 speed=3.41x
frame= 2554 fps=101 q=25.0 size= 1061kB time=00:01:25.01 bitrate= 102.2kbits/s dup=2399 drop=0 speed=3.38x
frame= 2577 fps=100 q=26.0 size= 1167kB time=00:01:25.78 bitrate= 111.4kbits/s dup=2399 drop=0 speed=3.34x
frame= 2588 fps= 99 q=-1.0 Lsize= 4707kB time=00:01:26.35 bitrate= 446.6kbits/s dup=2399 drop=0 speed=3.32x
video:4590kB audio:101kB subtitle:0kB other streams:0kB global headers:0kB muxing overhead: 0.346620%