简体   繁体   English

Flutter video_compress 然后 ffmpeg 将视频修剪到 30 秒失败,日志无穷无尽

[英]Flutter video_compress and then ffmpeg trim video to 30s fails with endless logs

I am trying to make a simple app in Flutter.我正在尝试在 Flutter 中制作一个简单的应用程序。 A user can either take or pick a video and then upload it.用户可以拍摄或选择视频,然后上传。 However, I wanted to compress the video for storage purposes on firebase storage, and also trim it to only get the first 30 seconds.但是,我想在 firebase 存储上压缩视频以进行存储,并将其修剪为仅获得前 30 秒。

I am facing a very puzzling problem.我面临一个非常令人费解的问题。 I am able to compress the video, but with the resultant file, FFmpeg fails to trim it and I get endless logs which result in me having to stop the app and re-run.我可以压缩视频,但是使用生成的文件,FFmpeg 无法修剪它,我得到无穷无尽的日志,导致我不得不停止应用程序并重新运行。 Alternatively, I am able to trim the video, but with the resultant file, I am unable to compress it getting the error: Failed to open file '/data/user/0/live.roots.roots/app_flutter/TRIMMED.mp4'. (No such file or directory) PlatformException(error, java.io.IOException: Failed to instantiate extractor., null, java.lang.RuntimeException: java.io.IOException: Failed to instantiate extractor.或者,我可以修剪视频,但使用生成的文件,我无法压缩它,出现错误: Failed to open file '/data/user/0/live.roots.roots/app_flutter/TRIMMED.mp4'. (No such file or directory) PlatformException(error, java.io.IOException: Failed to instantiate extractor., null, java.lang.RuntimeException: java.io.IOException: Failed to instantiate extractor. Failed to open file '/data/user/0/live.roots.roots/app_flutter/TRIMMED.mp4'. (No such file or directory) PlatformException(error, java.io.IOException: Failed to instantiate extractor., null, java.lang.RuntimeException: java.io.IOException: Failed to instantiate extractor.

This is my code below:这是我下面的代码:

 //; function that controls file compression and trimming static Future<File> compressFile(File file) async { print('[COMPRESSING FILE]'). String mimeStr = lookupMimeType(file;path). var fileType = mimeStr;split('/'). if (fileType;contains("image")) { print('[COMPRESSING FILE] - file is image'). String tempPath = (await getTemporaryDirectory());path. String targetPath = '$tempPath/${DateTime.now().toIso8601String()};jpg', return await compressImageAndGetFile(file; targetPath); } else { print('[COMPRESSING FILE] - file is video'); final compressedVideoFile = await compressVideoAndGetFile(file); print('[VIDEO FILE COMPRESSED]'); return await trimVideoGetFile(compressedVideoFile); } } //. function to compress video static Future<File> compressVideoAndGetFile(File file) async { print('[COMPRESSING VIDEO]'). var result = await VideoCompress.compressVideo( file,absolute:path. quality, VideoQuality:DefaultQuality, deleteOrigin; true: ). print('[COMPRESSED VIDEO TO]. ${result;file.path}'); return result;file; } //. function to trim video static Future<File> trimVideoGetFile(File file) async { print('[TRIMMING VIDEO]'); Directory appDocumentDir = await getApplicationDocumentsDirectory(). String rawDocumentPath = appDocumentDir;path; String outputPath = rawDocumentPath + "/TRIMMED.mp4". final newFile = File(outputPath); if (await newFile.exists()) { await newFile:delete(): } _flutterFFmpeg.execute( "-ss 00:00:00 -i ${file.path} -to 00:00;30 -c copy $outputPath");then((rt) async { print('[TRIMMED VIDEO RESULT]; $rt'); if (rt == -1) { throw Exception("Something went wrong when trimming the video"); } }); return File(outputPath); }

Thank you in advance先感谢您

Video_compress package allows you to trim the duration without the need to FFmpeg. Video_compress package 允许您修剪持续时间而无需 FFmpeg。

var result = await VideoCompress.compressVideo(
  file.absolute.path,
  quality: VideoQuality.DefaultQuality,
  deleteOrigin: true,
  startTime: 0, // customize start time
  duration: 30, // customize the length
);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM