Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

how to catch ffmpeg exception? #232

Open
ChengHoHang opened this issue May 14, 2021 · 3 comments
Open

how to catch ffmpeg exception? #232

ChengHoHang opened this issue May 14, 2021 · 3 comments
Labels

Comments

@ChengHoHang
Copy link

ChengHoHang commented May 14, 2021

as title. I try to catch exception from ffmpeg outputstream, not FFcommon.throwOnError 's exceptions,they are difference,right?

for example, I exec the command "ffmpeg -i xxx.mp4 yyy.mp4",FFcommon.throwOnError only throws message "ffmpeg returned non-zero exit status"

but the ffmpeg outputstream return the full error message such as "xxx No such file or directory", this message is what i need

can i get ffmpeg outputstream in some way? thanks

@ChengHoHang
Copy link
Author

@bramp @ziodave please give some help~~

@ChengHoHang
Copy link
Author

ok.. My project needs to record the error log from ffmpeg log,let me show my thought

my way is create a class that extends FFmpeg and overwrite its run() method,and use a ThreadLocal(FFmpegLogHolder) to save the log,the reason i use threadLocal is that CustomizeFFmpeg is set as a Singleton Bean

@Slf4j
public class CustomizeFFmpeg extends FFmpeg {

    final RunProcessFunction runFunc;

    private String path;

    public CustomizeFFmpeg(String path) throws IOException {
        this(path, new RunProcessFunction());
        this.path = path;
    }

    public CustomizeFFmpeg(String path, RunProcessFunction runFunc) throws IOException {
        super(path, runFunc);
        this.runFunc = runFunc;
    }

    @Override
    public void run(List<String> args) throws IOException {
        if (!isFFmpeg()) {
            throw new IllegalArgumentException(
                    "This binary '" + super.getPath() + "' is not a supported version of ffmpeg");
        }
        checkNotNull(args);

        Process p = runFunc.run(path(args));

        assert (p != null);
        StringBuilder logStringBuilder = new StringBuilder();
        try {
            // CharStreams.copy(wrapInReader(p), System.out);

            CharStreams.copy(wrapInReader(p), logStringBuilder);
            log.info(logStringBuilder.toString());

            throwOnError(p);

        } catch (Exception e) {
            // only catch exception,use threadLocal record
            FFmpegLogHolder.setLog(path + " " + String.join(" ", args).concat("\n").concat(logStringBuilder.toString()).concat("\n"));
            throw e;
        } finally {
            p.destroy();
        }
    }

    public String getFfmpegLog() {
        String log = FFmpegLogHolder.getLog();
        FFmpegLogHolder.clear();
        return log;
    }
}

this way seems a little silly.... is there any api to get errorLog efficiently and elegantly?

@barnettj
Copy link

There are two PRs to handle accessing standard out for ffmpeg/ffprobe:

#214
#225

No movement though...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants