-
Notifications
You must be signed in to change notification settings - Fork 9
Pipe Support
FFmpegKit
supports executing ffmpeg
and ffprobe
commands only, starting another process and redirecting its input/output to use inside ffmpeg
or ffprobe
is not possible.
If you try to run the following command in one of the execute()
methods,
cat <image path> | -i pipe: video.mp4
it will fail with the following error.
Unable to find a suitable output format for 'cat'
However pipe:
protocol, or reading input from another pipe
is still supported. You can still use the output of another process inside your ffmpeg
and ffprobe
commands. What you need to do is create a named pipe
and feed it with the command output.
FFmpegKit
has a registerNewFFmpegPipe
method on FFmpegKitConfig
class to help you create new pipes. You can use it to create a new pipe use it as input or output in your commands.
In order to do that on Android:
String pipe1 = FFmpegKitConfig.registerNewFFmpegPipe(mainActivity);
String ffmpegCommand = "-i " + pipe1 + " -r 25 <output video path>";
FFmpegKit.execute(ffmpegCommand);
Runtime.getRuntime().exec(new String[]{"sh", "-c", "cat <image path> > " + pipe1});
FFmpegKitConfig.closeFFmpegPipe(pipe1);
Please note that ffmpeg
will block the execution of your command in step #3 until some data is available in your pipe. So, if you don't have a step #4, the thread that executes step #3 will wait indefinitely.
It is possible to implement the same example on iOS
, macOS
and tvOS
. Objective C
API also has a registerNewFFmpegPipe
method on the FFmpegKitConfig
class. Steps #1, #2 and #3 can be repeated easily. However pushing data to your pipe is more difficult on Apple platforms. Initiating another process is not allowed on them. Therefore, you have to push the data manually by opening the pipe using the NSFileHandle
class and calling its writeData
method.
In addition to standard pipe
methods (registerNewFFmpegPipe
and closeFFmpegPipe
) available in all APIs, FFmpegKit
plugins on Flutter
and React Native
have another pipe
related method named writeToPipe
to easily send data to pipes. It is implemented on FFmpegKitConfig
class. You can use it instead of step #4 in the example.
PS: All test applications in the FFmpegKit Test repository include a PIPE tab, which demonstrates an example scenario similar to the one used in this page.
Copyright (c) 2021-2022 FFmpegKit
- Status
- Versions
- Changelog
- Project Layout
- Using
- Building
- External Libraries
- Patents
- License