Skip to content
This repository has been archived by the owner on Oct 7, 2021. It is now read-only.

Pipe Support

Taner Sener edited this page Jul 4, 2019 · 6 revisions

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.

Android

In order to do that on Android:

1. Create a new pipe

String pipe1 = Config.registerNewFFmpegPipe(mainActivity);

2. Build your command using pipe

String ffmpegCommand = "-y -i " + pipe1 + " -filter:v loop=loop=25*3:size=1 -c:v mpeg4 -r 25 <output video path>";

3. Execute your command.

FFmpeg.execute(ffmpegCommand, " ");

4. Push some data to your pipe by starting another process like

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.

iOS / tvOS

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.

Clone this wiki locally