bravobit / FFmpeg-Android

FFMpeg/FFprobe compiled for Android
https://bravobit.nl/
MIT License
739 stars 175 forks source link

Added the ability to execute FFmpeg and FFprobe synchronously #44

Open Sub6Resources opened 6 years ago

Sub6Resources commented 6 years ago

This pull request adds the FFcommandExecuteSynchronous class and execute() methods needed to execute FFmpeg/FFprobe synchronously as requested in issue #27.

For example, rather than the asynchronous way of executing FFmpeg:

FFmpeg ffmpeg = FFmpeg.getInstance(context);
ffmpeg.execute(cmd, new ExecuteBinaryResponseHandler() {

    @Override
    public void onStart() {}

    @Override
    public void onProgress(String message) {}

    @Override
    public void onFailure(String message) {}

    @Override
    public void onSuccess(String message) {}

    @Override
    public void onFinish() {}

});

You can now run it synchronously with:

FFmpeg ffmpeg = FFmpeg.getInstance(context);
String result = ffmpeg.execute(cmd);
//Result is all the output of the ffmpeg command.

It is identical for FFprobe.

Most of the code is pulled from the already-existing asynchronous execution code, I just pulled it out of an AsyncTask.

I hope to continue to contribute to this excellent library, and I am willing to make requested changes to this pull request.

Brianvdb commented 6 years ago

Thank you for your pull request.

However, I think we need to abstract the way to execute commands otherwise we would have the same code in four places. If you have any ideas, please let me know.