Skip to content
This repository was archived by the owner on Jun 23, 2025. It is now read-only.
This repository was archived by the owner on Jun 23, 2025. It is now read-only.

Using FFmpeg without write/read file path? #808

@Mamena2020

Description

@Mamena2020

My primary objective is to record audio and alter its pitch in real-time. The steps I'm currently working on are as follows:

  1. Recording:
    For recording, I'm using this package flutter sound and streaming audio data in pcm16 format (Uint8List).

  2. Auto Pitch:
    To achieve pitch shifting, I'm using this ffmpeg kit. The process involves several steps:

    • Write the audio data to files.
    • execute FFmpeg arguments for applying the desired pitch.
    • Read the output audio data from file.
    • Play output audio player.feedFromStream(outputAudio) using FlutterSoundPlayer from flutter sound
      I have successfully accomplished this, but the real-time pitch shifting experience is not as smooth as I expected. This is likely too much steps used affecting real time performance.

i've try to use ffmpeg using the Dart Process API, but seems not luck.

    
   Future<Uint8List> testAudio({required Uint8List audioData}) async {
    
      final additionalArguments = [
        '-af',
        'volume=1'  // example argument
      ]; 

      final ffmpegProcess = await io.Process.start(
        'ffmpeg',
        [
          '-i', 'pipe:0', // input
          ...additionalArguments,
          '-f', 'wav', 'pipe:1', // output
        ],
        mode: io.ProcessStartMode.detachedWithStdio,
        runInShell: true,
      );
      ffmpegProcess.stdin.add(audioData);
      await ffmpegProcess.stdin.flush();
      await ffmpegProcess.stdin.close();
     
      final bytes = await ffmpegProcess.stdout.toBytes();
      ffmpegProcess.kill();
      return Uint8List.fromList(bytes);
  }

   extension StreamToBytes on Stream<List<int>> {
      Future<List<int>> toBytes() async {
        final chunks = await toList();
        final bytesBuilder = BytesBuilder();
        for (final chunk in chunks) {
          bytesBuilder.add(chunk);
        }
        return bytesBuilder.takeBytes();
      }
    }

How i can filter audio in real-time using ffmpeg and get result in Uint8list? I mean, if using ffmpeg with path to write/read, it too much step to get result in realtime. any solution for this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions