mayurpitroda96 / easy_audio_trimmer

This is a Flutter package that allows you to easily trim audio files within your Flutter app.
MIT License
11 stars 27 forks source link

FFmpeg process exited with state COMPLETED and rc 1 #14

Open KY-Jung opened 6 months ago

KY-Jung commented 6 months ago

Hi,

I want to trim audio file. When I use easy audio trimmer, it failed with error message like below.

_trimmer.saveTrimmedAudio( startValue: _startValue, endValue: _endValue, audioFileName: 'savetrimmer2', outputFormat: FileFormat.mp3, //outputFormat: 'm4a' as FileFormat, applyAudioEncoding: true, onSave: (outputPath) { setState(() { _progressVisibility = false; }); debugPrint('OUTPUT PATH: $outputPath'); }, );

I/flutter ( 4425): Exists I/flutter ( 4425): Retrieved Trimmer folder I/flutter ( 4425): Start: 0:00:00.000000 & End: 0:00:03.072000 I/flutter ( 4425): /data/user/0/kr.gainsys.imagetalk/app_flutter/Trimmer/ I/flutter ( 4425): FFmpeg process exited with state COMPLETED and rc 1 I/flutter ( 4425): FFmpeg processing failed. I/flutter ( 4425): Couldn't save the audio I/flutter ( 4425): OUTPUT PATH: null

eugenz3rr commented 6 months ago

Hey I found out that this issue is comming from using a file that is not mp3.

ramees-saleem commented 1 month ago

For mobile update Save function inside Trimmer class to this:

Future saveTrimmedAudio({ required double startValue, required double endValue, required Function(String? outputPath) onSave, bool applyAudioEncoding = false, FileFormat? outputFormat, String? ffmpegCommand, String? customAudioFormat, int? fpsGIF, int? scaleGIF, String? audioFolderName, String? audioFileName, StorageDir? storageDir, }) async { final String audioPath = currentAudioFile!.path; final String audioName = basename(audioPath).split('.')[0];

String command = '';

String outputPath;
String formattedDateTime = DateTime.now().millisecondsSinceEpoch.toString();

debugPrint("Formatted: $formattedDateTime");

audioFolderName ??= "Trimmer";

audioFileName ??= "${audioName}_trimmed_$formattedDateTime";
audioFileName = audioFileName.replaceAll(' ', '_');

String path = await _createFolderInAppDocDir(
  audioFolderName,
  storageDir,
).whenComplete(
  () => debugPrint("Retrieved Trimmer folder"),
);

Duration startPoint = Duration(milliseconds: startValue.toInt());
Duration endPoint = Duration(milliseconds: endValue.toInt());

debugPrint("Start: ${startPoint.toString()} & End: ${endPoint.toString()}");

debugPrint(path);

String trimLengthCommand =
    ' -ss ${startPoint.inSeconds} -i "$audioPath" -t ${(endPoint - startPoint).inSeconds}';

command = '$trimLengthCommand ';
// outputPath = '$path$audioFileName.$outputFormatString';
outputPath = '$path$audioFileName.aac';

command += ' -c:a aac "$outputPath"';

// command = "ffmpeg -i $audioPath -ss 60 -to 70 $outputPath";

// Additional debug information
debugPrint("Executing FFmpeg command: $command");

FFmpegKit.executeAsync(command, (session) async {
  final state =
      FFmpegKitConfig.sessionStateToString(await session.getState());
  final returnCode = await session.getReturnCode();
  final output = await session.getOutput();
  final log = await session.getLogsAsString();

  debugPrint("FFmpeg process exited with state $state and rc $returnCode");
  debugPrint("FFmpeg Output: $output");
  debugPrint("FFmpeg Log: $log");

  if (ReturnCode.isSuccess(returnCode)) {
    debugPrint("FFmpeg processing completed successfully.");
    debugPrint('Audio successfully saved');
    onSave(outputPath);
  } else {
    debugPrint("FFmpeg processing failed.");
    debugPrint('Couldn\'t save the audio');
    onSave(null);
  }
});

}