skip to Main Content

i want to merge an intro.mp4 (located in the assets folder of my project) video with the cameraRecord Output video (let’s say output.mp4)

i tried this (code below) but it gives a bad result (the output video is side by side not sequential ) also it didn’t work with the assets folder i think all the paths should come from the device and not from the project (assets …)

Future<void> mergeRecordWithIntro(String outputPath, String videoPath) async {
emit(MergeVideoLoading());
const String introPath = 'assets/logo.mp4';
const filter =
    " [0:v]scale=480:640,setsar=1[l];[1:v]scale=480:640,setsar=1[r];[l][r]hstack;[0][1]amix -vsync 0 ";

await FFmpegKit.execute(
        '-y -i $videoPath -i $videoPath -filter_complex $filter $outputPath')
        
    .then((value) async {
  final returnCode = await value.getReturnCode();

  if (ReturnCode.isSuccess(returnCode)) {
    GallerySaver.saveVideo(outputPath);
    emit(MergeVideoSucces());
  } else if (ReturnCode.isCancel(returnCode)) {
    emit(MergeVideoError());
  }
});

this is my updates log screen shot using this command :

-y -i $firstVideoPath -i $secondVideoPath -filter_complex "[0:v]scale=480:640[v0];[1:v]scale=480:640[v1];[v0][0:a][v1][1:a]concat=n=2:v=1:a=1[outv][outa]" -map "[outv]" -map "[outa]" $outputPath

2

Answers


  1. Chosen as BEST ANSWER

    this command worked for me the only problem is the output video quality is very low so... !! :

    -y -i $firstVideoPath -i $videoPath -r 24000/1001 -filter_complex "[0:v]scale=1080:1920[v0];[1:v]scale=1080:1920[v1];[v0][0:a][v1][1:a]concat=n=2:v =1:a=1[outv][outa]" -map "[outv]" -map "[outa]" -vsync 2 $outputPath
    

  2. First, save the video in the project’s assets folder to a temporary folder and use the path there.

    final byteData = await rootBundle.load('assets/logo.mp4');
    final file = await File('${Directory.systemTemp.path}${path.replaceAll('assets', '')}').create();
    await file.writeAsBytes(byteData.buffer.asUint8List(byteData.offsetInBytes, byteData.lengthInBytes));
    final firstVideoPath = file.path;
    

    Next, the command to merge videos is concat, so fix it. *If you have a different resolution or codec, you may need to fix it.

    await FFmpegKit.execute('-y -i "concat:$firstVideoPath|$secondVideoPath" -c copy $outputPath')
    

    Finally, use the gal package instead of the gallery_saver, which is already two years out of maintenance.

    await Gal.putVideo($outputPath);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search