skip to Main Content

I want to Add words like headsup game in video when video is shared to someone these words also add to the video I wrote these methods for this purpose but these did not work for me. I am using flutter_ffmpeg: ^0.4.2 package,for video editing , can anyone help me to build that methods that I may successful to achieve my desired results??????

2

Answers


  1. Chosen as BEST ANSWER
    Future<void> processRecordedVideo(String recordingPath) async {
        final overlayTextOptions = {
          'enable': '1',
          'fontfile': 'OpenSans-Bold.ttf', // Replace with your font file path
          'fontsize': '36',
          'text': 'Your Overlay Text Here', // Replace with the text to be 
      displayed
          'x': '10',
          'y': '10', // Adjust x and y coordinates for text position
          'fontcolor': 'white',
          'shadowcolor': 'black',
          'shadowx': '2',
          'shadowy': '2',
        };
    
        final overlayFilter =
            'drawtext=${overlayTextOptions.entries.map((e) => 
      '${e.key}=${e.value}').join(':')}';
    
        // Specify the destination directory where you want to save the processed 
       video
        const destinationDirectory = "/storage/emulated/0/desi_charades/";
        final outputVideoPath =
            '$destinationDirectory${DateTime.now().millisecondsSinceEpoch}.mp4';
    
        final arguments = [
          '-i', recordingPath,
          '-vf', overlayFilter,
          '-c:v', 'libx264', // Video codec
          '-preset', 'ultrafast', // Encoding preset
          '-c:a', 'copy', // Keep original audio
          '-y', // Overwrite existing output file
          outputVideoPath, // Output video path
        ];
    
        await flutterFFmpeg.executeWithArguments(arguments);
    
        // Save the processed video to the destination directory
        await saveVideoToGallery(outputVideoPath);
      }
    Future<void> saveVideoToGallery(String p) async {
        try {
          final originalVideoFile = File(p);
          if (!originalVideoFile.existsSync()) {
            throw const FileSystemException('Source file does not exist.');
          }
    
          const absoluteFolderPath = "/storage/emulated/0/desi_charades/";
          await Directory(absoluteFolderPath).create(recursive: true);
    
          final filename =
              "${deck!.title}_${DateTime.now().millisecondsSinceEpoch}.mp4";
          final destinationPath = "$absoluteFolderPath$filename";
    
          await originalVideoFile.copy(destinationPath);
          savedPathOfVideo.value = destinationPath;
    
          Logger().e(savedPathOfVideo.value);
        } catch (e) {
          print('Error saving enter code here video: $e');
        }
      }
    

    these method is written


  2. final arguments = [
    ‘-y’, // Overwrite existing files
    ‘-i’, // Input file
    inputVideoPath,
    ‘drawtext=fontfile=Montserrat-Regular.ttf: text="Pak"’,
    outputVideoPath, // Output file
    ];
    I when i pass the ‘drawtext=fontfile=Montserrat-Regular.ttf: text="Pak"’ then exitcode=1 comes while without using ‘drawtext=fontfile=Montserrat-Regular.ttf: text="Pak"’ result comes exitcode=0 , as I already talked that i want to add text over the video, for this purpose ‘drawtext=fontfile=Montserrat-Regular.ttf: text="Pak"’ is mandatory , can anyone help me

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