Dart // Flutter - 如何连接图像和音频以呈现静态视频

Dart // Flutter - How to connect image and audio to render a static video

我正在尝试将音频文件连接到静态图像并将其呈现为仅包含静态图像和音频播放的视频,我查看了几个 pub 库,例如 this

但是我在找的时候没有找到任何关于如何实现的文档,有没有简单的方法可以做到这一点?如果不能,是否可以在不编写平台特定内容的情况下使用 dart?

这就是我最后做的,我希望它能帮助到别人, 在我的例子中,我需要将图像连接到音频文件以创建可以与 share_plus 插件共享的视频

你真的没有 ffmpeg 的替代品,但你可以设置它,这样使用起来还不错:

将此添加到您的 pubspec.yaml 依赖项 ffmpeg_kit_flutter_min_gpl: ^4.5.0-LTS

导入要渲染视频的文件中的那些:

import 'package:ffmpeg_kit_flutter_min_gpl/return_code.dart';
import 'package:ffmpeg_kit_flutter_min_gpl/ffmpeg_kit.dart';

然后是渲染本身:

 await FFmpegKit.executeAsync(
                          '-y -i $screenshotPath -i $filePath -c:v libx264 -tune stillimage -c:a aac -b:a 192k -pix_fmt yuv420p ${applicationDocumentDirectory.path}/new.mp4',
                          (session) async {
                        final state = await session.getState();

                        final returnCode = await session.getReturnCode();

                        String output = await session.getOutput();
                        print(output);

                        if (ReturnCode.isSuccess(returnCode)) {
                          // SUCCESS
                          await Share.shareFiles(
                            ['${applicationDocumentDirectory.path}/new.mp4'],
                          );
                        } else if (ReturnCode.isCancel(returnCode)) {
                          // CANCEL

                        } else {
                          // ERROR

                        }
                      });