convertFile method

Future<bool> convertFile(
  1. String? inputFile,
  2. Codec? inputCodec,
  3. String outputFile,
  4. Codec outputCodec,
)

Convert a sound file to a new format.

  • inputFile is the file path of the file you want to convert
  • inputCodec is the actual file format
  • outputFile is the path of the file you want to create
  • outputCodec is the new file format

Be careful : outfile and outputCodec must be compatible. The output file extension must be a correct file extension for the new format.

Note : this verb uses FFmpeg and is not available int the LITE flavor of Flutter Sound.

Implementation

Future<bool> convertFile(String? inputFile, Codec? inputCodec,
    String outputFile, Codec outputCodec) async {
  if (!isFFmpegAvailable()) return false;
  int? rc = 0;
  inputFile = await _getPath(inputFile);
  outputFile = await _getPath(outputFile);
  if (inputCodec == Codec.opusOGG &&
      outputCodec == Codec.opusCAF) // Do not need to re-encode. Just remux
  {
    rc = await FlutterFFmpeg().executeWithArguments([
      '-loglevel',
      'error',
      '-y',
      '-i',
      inputFile,
      '-c:a',
      'copy',
      outputFile,
    ]); // remux OGG to CAF
  } else {
    rc = await FlutterFFmpeg().executeWithArguments([
      '-loglevel',
      'error',
      '-y',
      '-i',
      inputFile,
      outputFile,
    ]);
  }
  return (rc == 0);
}