0

I have a feature to listen to audio files, I'm getting audio files in .wav format and takes too long to play audio. When i tried .mp3 file with same audio player its delay decreased.

Is there any way to convert .wav to .mp3 or any other approches?

 FFmpegKit.execute('-i $url output.mp3').then((session) async {
                                                        final returnCode = await session.getReturnCode();

                                                        if (ReturnCode.isSuccess(returnCode)) {
                                                     

                                                          // SUCCESS

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

                                                          // CANCEL

                                                        } else {
                                                       

                                                          // ERROR

                                                        }
                                                      })
Akhil
  • 419
  • 5
  • 15

1 Answers1

0

ffmpeg is a complete, cross-platform solution to record, convert and stream audio and video.

Here is a great package that ports ffmpeg features to flutter

Below is a usage example of the package that converts a input.wav file to an output.mp3 file:

import 'package:ffmpeg_kit_flutter/ffmpeg_kit.dart';

 FFmpegKit.execute('-i input.wav output.mp3').then((session) async {
   final returnCode = await session.getReturnCode();

   if (ReturnCode.isSuccess(returnCode)) {

     // SUCCESS

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

     // CANCEL

   } else {

     // ERROR

   }
 });

You can easily convert between different file formats,

here is a link to the official ffmpeg website if you want to learn more

ezzou
  • 2,348
  • 1
  • 15
  • 16
  • i have tried that but at the time of conversion, it shows "Automatic encoder selection failed for output stream #0:0. Default encoder for format mp3 (codec mp3) is probably disabled. Please choose an encoder manually" – Akhil Sep 19 '22 at 09:05
  • thanks for suggestion, but when i add this to dependency it shows package doesnt exist – Akhil Sep 20 '22 at 05:16
  • 1
    sorry, Here is the package you should import : ffmpeg_kit_flutter_audio: 4.5.1 , with the _audio package at the end, since you want to convert from .wav to .mp3 – ezzou Sep 21 '22 at 13:33
  • yes, i have done like that, but still its doesnt converting," -i assets/audio/wavdemo.wav -c:v assets/output file2.mp3", i have tried by doing the same with asset file but no result shown. – Akhil Sep 26 '22 at 09:15
  • any solutions ? – mamena tech Jun 10 '23 at 12:35