convertFile method
Convert a sound file to a new format.
inputFile
is the file path of the file you want to convertinputCodec
is the actual file formatoutputFile
is the path of the file you want to createoutputCodec
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 {
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 flutterSoundHelper.executeFFmpegWithArguments([
'-loglevel',
'error',
'-y',
'-i',
inputFile,
'-c:a',
'copy',
outputFile,
]); // remux OGG to CAF
} else {
rc = await flutterSoundHelper.executeFFmpegWithArguments([
'-loglevel',
'error',
'-y',
'-i',
inputFile,
outputFile,
]);
}
return (rc == 0);
}