Sha*_*ari 6 ffmpeg dart flutter
我想获得 flutter 中 ffmpeg 执行的百分比
我有一些代码示例,但我不知道该怎么做
安卓示例:
int start = message.indexOf("time=");
int end = message.indexOf(" bitrate");
if (start != -1 && end != -1) {
String duration = message.substring(start + 5, end);
if (duration != "") {
try {
SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
sdf.setTimeZone(TimeZone.getTimeZone("UTC"));
dialog.setProgress((int)sdf.parse("1970-01-01 " + duration).getTime());
}catch (ParseException e)
{
e.printStackTrace();
}
}
}
Run Code Online (Sandbox Code Playgroud)
颤动代码:
void statisticsCallback(Statistics statistics) {
print("Statistics: executionId: ${statistics.executionId}, time: ${statistics.time}, size: ${statistics.size}, bitrate: ${statistics.bitrate}, speed: ${statistics.speed}, videoFrameNumber: ${statistics.videoFrameNumber}, videoQuality: ${statistics.videoQuality}, videoFps: ${statistics.videoFps}");
}
Run Code Online (Sandbox Code Playgroud)
如何从 statsCallback 方法生成执行进度?
请帮帮我
以下文档:https://pub.dev/packages/flutter_ffmpeg
首先你必须启用StatisticsCallback,这可以放在initState中
@override
void initState() {
super.initState();
final FlutterFFmpegConfig _flutterFFmpegConfig = new FlutterFFmpegConfig();
_flutterFFmpegConfig.enableStatisticsCallback(this.statisticsCallback);
}
Run Code Online (Sandbox Code Playgroud)
然后在你的statisticsCallback函数中,你得到statistics.time并totalDurationFile(以毫秒为单位)计算
void statisticsCallback(Statistics statistics) {
totalProgress = (statistics.time * 100) ~/ totalFileDuration;
print("Statistics: executionId: ${statistics.executionId}, time: ${statistics.time}, size: ${statistics.size}, bitrate: ${statistics.bitrate}, speed: ${statistics.speed}, videoFrameNumber: ${statistics.videoFrameNumber}, videoQuality: ${statistics.videoQuality}, videoFps: ${statistics.videoFps}");
}
Run Code Online (Sandbox Code Playgroud)
更新:https ://pub.dev/packages/ffmpeg_kit_flutter
FFmpegKit.executeAsync(arguments, (session) async {
final returnCode = await session.getReturnCode();
if (ReturnCode.isSuccess(returnCode)) {
/// When sucess
} else if (ReturnCode.isCancel(returnCode)) {
/// When cancel
}
}, (Log log) {},
(Statistics statistics) {
if (statistics == null) {
return;
}
if (statistics.getTime() > 0) {
totalProgress = (statistics.getTime() * 100) ~/ totalVideoDuration;
}
});
Run Code Online (Sandbox Code Playgroud)