FFmpeg.AutoGen
FFmpeg.AutoGen copied to clipboard
New example: a class with an `AssertSuccess` wrapper for FFmpeg commands
A contribution back to the project forged from my use of it.
Use like so –
AssertSuccess(
ffmpeg.avformat_alloc_output_context2(&outputContext, null, null, null),
"Could not allocate output format context"
);
The return code will be parsed and an FFmpegException raised.
EAGAIN will fail on any BSD like system including any OS X or iOS (iOS support is coming). The code is different. you can check ffmpeg.cs
Could you elaborate?
Empirically, it's working in a codebase that’s running on PC & Mac.
e.g. else if (ret == -ffmpeg.EAGAIN) break;
Plus there’s code to handle platform difference here: https://github.com/Ruslan-B/FFmpeg.AutoGen/blob/d2fc566eb5d451a7894a63f5fdd9bf9909402412/FFmpeg.AutoGen/FFmpeg.cs#L55
Correctness after all - it maters - you can check decode example - TryDecodeNextFrame.
Not my invention but you can look to this one https://github.com/Ruslan-B/FFmpeg.AutoGen/pull/218
Besides did you noticed ThrowExceptionIfError?
I like to understand your rationale - if you like we can have a call.
I’m confused about ‘Correctness after all...’ as the use of EAGAIN works in the example I commented above and, I assume, in the example project you refer to. If you are commenting about EAGAIN also being in the list of POSIX errors that AssertSuccess uses, then that is true but also irrelevant in that FFmpeg handles the correct case and AssertSuccess tries the FFmpeg handled error codes first, and then falls back to the POSIX list. The POSIX errors are needed as FFmpeg sometimes returns POSIX error codes beyond the ones it specifically handles, e.g. when some underlying c function fails.
Beyond that, I find the coding style of this more pragmatic than ThrowExceptionIfError, as I get to to associate a descriptive error message at the site of invoking the ffmpeg command, and it also interprets the underlying error FFmpeg returns. Neither of which are handled by the approach in FFmpegHelper.
But at that point we’re talking taste!
Anyway, AssertSuccess developed over time as needed, first with the ERRTAG interpretation and then extended POSIX handling; it was a pragmatic boon to me. It may be to other people, and the PR and/or it being pulled in may help others.
No pressure, it was a contribution meant as thanks for the open-source work.
out of project scope