Skip to content

Optimizing render time: Piping frames to ffmpeg #3

@polarby

Description

@polarby

Piping images to FFmpeg instead of saving each file to source and then feeding it to FFmpeg. See here for more info.

FFmpegKit currently lacks documentation for piping input.
Here is the current approach to pipe input, but it will only show the first piped image in the mp4.

final Directory directory = await getApplicationDocumentsDirectory();
    final pipe = await FFmpegKitConfig.registerNewFFmpegPipe();

    Future<void> pipeFiles() async {
      final imageFile0 = await getImageFileFromAssets("image0.jpeg");
      await FFmpegKitConfig.writeToPipe(imageFile0.path, pipe!);
      final imageFile1 = await getImageFileFromAssets("image1.jpeg");
      await FFmpegKitConfig.writeToPipe(imageFile1.path, pipe);
    }

    final process =  FFmpegKit.executeAsync('-y -framerate 1 -f image2pipe -i $pipe -frames 2 ${directory.path}/out11.mp4',
        (session) async {
      await FFmpegKitConfig.closeFFmpegPipe(pipe!);
    });

    await pipeFiles();

    final file = File('/data/user/0/com.example.example/app_flutter/out11.mp4');

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions