-
-
Notifications
You must be signed in to change notification settings - Fork 414
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
Labels
Comments
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? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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
The text was updated successfully, but these errors were encountered: