-
-
Notifications
You must be signed in to change notification settings - Fork 796
Pipe Support
MobileFFmpeg
supports executing only ffmpeg
commands, starting another process and redirecting its input/output to use inside ffmpeg
is not possible by default.
If you try to run something like
cat <image path> | -i pipe: -filter:v loop=loop=25*3:size=1 -c:v mpeg4 -r 25 video.mp4
it will fail with the following error
Unable to find a suitable output format for 'cat'
However please note that pipe:
protocol, or reading input from another pipe
is still supported. You can still use the output of another process inside your ffmpeg
command. What you need to do is to create a named pipe
and feed it with your data.
To help you do that a new API method called registerNewFFmpegPipe
is introduced in v4.2.1
. You can create a new pipe with this method and use the pipe as a regular argument in your commands.
In order to do that on Android:
String pipe1 = Config.registerNewFFmpegPipe(mainActivity);
String ffmpegCommand = "-y -i " + pipe1 + " -filter:v loop=loop=25*3:size=1 -c:v mpeg4 -r 25 <output video path>";
FFmpeg.execute(ffmpegCommand, " ");
Runtime.getRuntime().exec(new String[]{"sh", "-c", "cat <image path> > " + 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, thread executing step #3 will wait indefinitely.
It is possible to implement the same example on iOS and tvOS. registerNewFFmpegPipe
method is available inside the MobileFFmpegConfig
class. Steps #1, #2 and #3 can be repeated easily. But pushing data to your pipe is more difficult on iOS and tvOS. Initiating another process is not allowed on these platforms. So you have to push data manually by opening pipe with NSFileHandle
and call writeData
.
ps: All test applications in this repository include a PIPE tab which demonstrates an example scenario similar to the one used in this page.
Copyright (c) 2018-2021 MobileFFmpeg