Flutter开发下,使用ffmpeg的视频压缩如何显示任务进度的百分比

请问:我们用Flutter开发一个软件,使用ffmpeg sdk的视频压缩功能,怎么样才能显示视频压缩的百分比的进度?

这个还是要结合你的sdk提供的接口,如果sdk能返回当前压缩进度和压缩大小,自己再画一下UI展示即可。看题主应该是原生代码调用sdk,可以去熟悉一下原生如何和flutter通信将进度发送给UI渲染就可以了

如果你想要在 Flutter 中显示视频压缩进度,你可以使用 Flutter 的 ProgressIndicator widget。
参考:

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  double _progress = 0;

  void _compressVideo() async {
    // Compress the video using ffmpeg.
    // As the video is being compressed, update the _progress variable
    // with the current progress of the compression.
    setState(() {
      _progress = currentProgress;
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              // Show the progress indicator and bind its value
              // to the current progress of the video compression.
              // The indicator will show a value between 0 and 1,
              // so we need to map the _progress value (which can be
              // any value) to a value between 0 and 1.
              ProgressIndicator(
                value: _progress.clamp(0, 1),
              ),
              RaisedButton(
                onPressed: _compressVideo,
                child: Text('Compress Video'),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

在上面的代码中,我们在 _compressVideo 方法中使用 ffmpeg 来压缩视频。当视频被压缩时,我们更新 _progress 变量,表示压缩的当前进度。然后,在 build 方法中,我们使用 ProgressIndicator widget 来显示进度。
有帮助的话采纳一下哦!