ffmpeg套件颤音视频压缩机

发布于 2025-01-22 21:41:34 字数 896 浏览 3 评论 0原文

我没有FFMPEG的经验。因此,很抱歉,如果我在错误的地方问错误的问题。 我正在尝试制作视频压缩机,我将依赖性完全添加到:ffmpeg_kit_flutter_flutter_flutter_gl_gpl: ^4.5.1 我编写的代码就像:

compress(path) {
  FFmpegKit.executeAsync("-i $path -c:a copy -c:v libx264 -s 848x360 output.mp4", (session) async {
  final returnCode = await session.getReturnCode();
 if (ReturnCode.isSuccess(returnCode)){

     print("işlem başarılı");
  // SUCCESS

 } else if (ReturnCode.isCancel(returnCode)) {

  print("iptal edildi");
 // CANCEL

 } else {

   print("hata oluştu");
   print(await session.getFailStackTrace());
   // ERROR

 }
});

}

,然后我称此方法为:

asset.originFile.then((fle) {
       var path = fle!.path;
       compress(path);
       }
);

它总是出于某种原因返回错误条件。和session.getFailStackTrace()为null。

我的第一个问题是您认为这里有什么错?

其次,在这种情况下,如何检测错误是什么?

提前致谢 :)

I am not experienced with ffmpeg. So I'm sorry if I'm asking the wrong question in the wrong place.
i am trying to make a video compressor, i add the dependency exactly like : ffmpeg_kit_flutter_full_gpl: ^4.5.1
and The code I wrote is like:

compress(path) {
  FFmpegKit.executeAsync("-i $path -c:a copy -c:v libx264 -s 848x360 output.mp4", (session) async {
  final returnCode = await session.getReturnCode();
 if (ReturnCode.isSuccess(returnCode)){

     print("işlem başarılı");
  // SUCCESS

 } else if (ReturnCode.isCancel(returnCode)) {

  print("iptal edildi");
 // CANCEL

 } else {

   print("hata oluştu");
   print(await session.getFailStackTrace());
   // ERROR

 }
});

}

and im calling this method like:

asset.originFile.then((fle) {
       var path = fle!.path;
       compress(path);
       }
);

it always returns error condition for some reason. and session.getFailStackTrace() is null.

My first question is what do you think is wrong here?

And secondly how can I detect what the error is in such cases?

thanks in advance :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

夏了南城 2025-01-29 21:41:34

最后,在@kesh的建议下,我使用了此代码来查看错误。

FFmpegKitConfig.enableLogCallback((log) {
 final message = log.getMessage();
 print(message);
});

正如我所知道的那样,如果您的视频名称包含空间或特殊字符,则FFMPEG套件会出现错误。 文件生成随机名称,并将其重命名

因此,我为输入文件和输出

ffmpeg_kit_flutter_full_gpl: ^4.5.1

我生成的新名称类似:

asset.originFile.then((fle) {
                              const _chars = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890';
                              Random _rnd = Random();
                              String getRandomString(int length) => String.fromCharCodes(Iterable.generate(
                              length, (_) => _chars.codeUnitAt(_rnd.nextInt(_chars.length))));
                              String newName = getRandomString(15);
                              String newInput = getRandomString(16);
                              var outputPath = fle!.path.toString().split('/');

                              outputPath.remove(outputPath[(outputPath.length)-1]);

                              var out = outputPath.join('/');
                              String output = out + "/" + newName + ".mp4";
                              String inputPath = out + "/" + newInput + ".mp4";

                              fle.rename(inputPath);
                              
                              compress(inputPath, output);
                                                                  
                                                              }

我的压缩功能是:

compress(path, output) {
                                   FFmpegKit.executeAsync("-y -i $path -vcodec libx264 -crf 22 $output", (Session session) async {
                                     final returnCode = await session.getReturnCode();
                                     if (ReturnCode.isSuccess(returnCode)){
                                       print("işlem başarılı");
                                       File lastVid = File(output);
                                       //SUCCESS
                                     } else if (ReturnCode.isCancel(returnCode)) {
                                            print("iptal edildi");
                                            // CANCEL

                                          } else {
                                            print("hata oluştu");
                                            FFmpegKitConfig.enableLogCallback((log) {
                                              final message = log.getMessage();
                                              print(message);
                                            });
                                            // ERROR

                                          }
                                   });
                                }

At the end, with advice of @kesh , i used this code for see the error;

FFmpegKitConfig.enableLogCallback((log) {
 final message = log.getMessage();
 print(message);
});

And as i figure out, if your videos name contains space or special character, FFmpeg kit gives error. So, i generate random names for input file and output file and rename them..

And if any body needs a ffmpeg video compressor, i'm leaving the code:

my depency at pubspec.yaml ;

ffmpeg_kit_flutter_full_gpl: ^4.5.1

and im generating new name like:

asset.originFile.then((fle) {
                              const _chars = 'AaBbCcDdEeFfGgHhIiJjKkLlMmNnOoPpQqRrSsTtUuVvWwXxYyZz1234567890';
                              Random _rnd = Random();
                              String getRandomString(int length) => String.fromCharCodes(Iterable.generate(
                              length, (_) => _chars.codeUnitAt(_rnd.nextInt(_chars.length))));
                              String newName = getRandomString(15);
                              String newInput = getRandomString(16);
                              var outputPath = fle!.path.toString().split('/');

                              outputPath.remove(outputPath[(outputPath.length)-1]);

                              var out = outputPath.join('/');
                              String output = out + "/" + newName + ".mp4";
                              String inputPath = out + "/" + newInput + ".mp4";

                              fle.rename(inputPath);
                              
                              compress(inputPath, output);
                                                                  
                                                              }

and my compress function is:

compress(path, output) {
                                   FFmpegKit.executeAsync("-y -i $path -vcodec libx264 -crf 22 $output", (Session session) async {
                                     final returnCode = await session.getReturnCode();
                                     if (ReturnCode.isSuccess(returnCode)){
                                       print("işlem başarılı");
                                       File lastVid = File(output);
                                       //SUCCESS
                                     } else if (ReturnCode.isCancel(returnCode)) {
                                            print("iptal edildi");
                                            // CANCEL

                                          } else {
                                            print("hata oluştu");
                                            FFmpegKitConfig.enableLogCallback((log) {
                                              final message = log.getMessage();
                                              print(message);
                                            });
                                            // ERROR

                                          }
                                   });
                                }
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文