1

I've been trying to merge videos using a flutter ffmpeg package, but for some reason it doesn't work. Here is my current approach.

  Future<String> mergeVideos(List<String> paths) async {
    final appDir = await getApplicationDocumentsDirectory();
    String rawDocumentPath = appDir.path;
    final outputPath = '$rawDocumentPath/output.mp4';
    String videos = '';
    for (int i = 0; i < paths.length; i++) {
      videos = videos + ' -i ${videoFragmentsPaths[i]}';
    }

    String commandToExecute =
        '-y $videos -filter_complex \'[0:0][1:0]concat=n=2:v=1:a=0[out]\' -map \'[out]\' $outputPath';

    final ffmpegSession = await FFmpegKit.execute(commandToExecute);
    final returnCode = await ffmpegSession.getReturnCode();
    if (ReturnCode.isSuccess(returnCode)) {
      // SUCCESS
      print('success');
    } else if (ReturnCode.isCancel(returnCode)) {
      // CANCEL
      print('cancel');
    } else {
      // ERROR
      print('error');
    }
    print(File(outputPath).lengthSync());
    return outputPath;
  }
  • You should **print** that `videos` variable before doing `String commandToExecute =` to make sure it looks okay. Change `paths.length` to a **1** or **2** for quick testing. – VC.One Feb 19 '22 at 10:20
  • I previously did that, but removed it later because the command was always good each time i ran it – Ifeanyi Nwachi Feb 19 '22 at 13:12
  • Did you have to use flutter? If you can just use ffmpeg directly, you may try the suggestions from the post: https://stackoverflow.com/questions/7333232/how-to-concatenate-two-mp4-files-using-ffmpeg/11175851#11175851 The answer posted by Ellie Tam there worked for me perfectly (except I needed to make a small change). But some other suggestions there may also work for you. – Shiping Dec 31 '22 at 12:31

0 Answers0