skip to Main Content

just extract audio from video

@override
  void initState() {
    // TODO: implement initState
    super.initState();
    getAudio();
  }

  getAudio() async {
    await FFmpegKit.execute(
            "ffmpeg -i D:/Dart and Flutter/Projects/Jmm/firebase_task/assets/videos/flutter.mp4 -q:a 0 -map a D:/Dart and Flutter/Projects/Jmm/firebase_task/assets/videos/flutter_audio.mp3")
        .then((value) async {
      var returnCode = await value.getReturnCode();
      if (ReturnCode.isSuccess(returnCode)) {
        print('succsses');
      } else {
        print('fail');
      }
    });
  }

I have no idea the how to extract an audio from video in flutter

2

Answers


  1. Chosen as BEST ANSWER

    ByteData _video = await rootBundle.load('assets/videos/flutter.mp4');
        var path = await getApplicationDocumentsDirectory();
        var sampleVideo = "${path.path}/sample_video.mp4";
        File _avFile = await File(sampleVideo).create();
        await _avFile.writeAsBytes(_video.buffer.asUint8List());
        var sampleAudio = "${path.path}/sample_audio.mp3";
        File audioFile = await _avFile.copy(sampleAudio);

    I solve my problem with the above code snippet


  2. As per the documentation of the mentioned plugin, you can extract audio by the following way.

    import 'package:ffmpeg_kit_flutter/ffmpeg_kit.dart';
    
     FFmpegKit.execute('-i input.mp4 -q:a 0 -map a output.mp3').then((session) async {
       final returnCode = await session.getReturnCode();
    
       if (ReturnCode.isSuccess(returnCode)) {
    
         // SUCCESS
    
       } else if (ReturnCode.isCancel(returnCode)) {
    
         // CANCEL
    
       } else {
    
         // ERROR
    
       }
     });
    

    or even you can do it with more simple command (in execute) like:

    -i input.mp4 output.mp3

    or whatever FFmpeg command you want to execute.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search