From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id EA7354A8F9 for ; Tue, 23 Apr 2024 09:38:38 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 43A8868D3A7; Tue, 23 Apr 2024 12:38:35 +0300 (EEST) Received: from alt2.a-painless.mh.aa.net.uk (alt2.a-painless.mh.aa.net.uk [81.187.30.51]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id C868968D135 for ; Tue, 23 Apr 2024 12:38:28 +0300 (EEST) Received: from d.3.9.4.0.0.0.f.2.9.6.2.6.5.d.6.0.5.8.0.9.1.8.0.0.b.8.0.1.0.0.2.ip6.arpa ([2001:8b0:819:850:6d56:2692:f000:493d] helo=andrews-2024-laptop.sayers) by painless-a.thn.aa.net.uk with smtp (Exim 4.96) (envelope-from ) id 1rzCbc-00CZ36-24 for ffmpeg-devel@ffmpeg.org; Tue, 23 Apr 2024 10:38:28 +0100 Date: Tue, 23 Apr 2024 10:38:21 +0100 From: Andrew Sayers To: FFmpeg development discussions and patches Message-ID: References: <20240417135832.GJ6420@pb2> <20240423002051.GG6420@pb2> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Subject: Re: [FFmpeg-devel] [RFC] 5 year plan & Inovation X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: On Tue, Apr 23, 2024 at 10:02:58AM +0200, Lynne wrote: > Apr 23, 2024, 09:47 by ffmpeg-devel@pileofstuff.org: > > > On Tue, Apr 23, 2024 at 02:20:51AM +0200, Michael Niedermayer wrote: > > > >> On Thu, Apr 18, 2024 at 10:46:35AM +0200, Stefano Sabatini wrote: > >> > On date Wednesday 2024-04-17 15:58:32 +0200, Michael Niedermayer wrote: > >> > > Hi all > >> > > > >> > > The pace of inovation in FFmpeg has been slowing down. > >> > > Most work is concentarted nowadays on code refactoring, and adding > >> > > support for new codecs and formats. > >> > > > >> > > Should we > >> > > * make a list of longer term goals > >> > > * vote on them > >> > > * and then together work towards implementing them > >> > > ? > >> > > > >> > > (The idea here is to increase the success of larger efforts > >> > > than adding codecs and refactoring code) > >> > > It would then also not be possible for individuals to object > >> > > to a previously agreed goal. > >> > > And it would add ideas for which we can try to get funding/grants for > >> > > > >> > > (larger scale changes need consensus first that we as a whole want > >> > > them before we would be able to ask for funding/grants for them) > >> > > > >> > > Some ideas and why they would help FFmpeg: > >> > > > >> > [...] > >> > > * client side / in browser support > >> > > (expand towards webapps, webpages using ffmpeg client side in the browser) > >> > > bring in more users and developers, and it will be costly for us > >> > > if we let others take this area as its important and significant > >> > > >> > There are already several projects on github, the most prominent one: > >> > https://github.com/ffmpegwasm/ffmpeg.wasm/ > >> > > >> > In general it would be useful to provide libav* bindings to other > >> > languages, for example: > >> > https://github.com/PyAV-Org/PyAV > >> > https://github.com/zmwangx/rust-ffmpeg > >> > > >> > Not sure these should be really moved to FFmpeg though. > >> > >> From a user PoV it would be nice if there was a official > >> python, rust and wasm binding > >> > >> It also would draw in more developers and users to FFmpeg. > >> test coverage might also improve > >> > >> I think the 2 questions are. > >> 1. is there a binding for some language that wants to become the official > >> FFmpeg binding for that language ? > >> 2. does the FFmpeg community want that too ? > >> > >> thx > >> > > > > I've thought about this a lot while trying to learn FFmpeg. > > IMHO there are two big hurdles to good other-language bindings: > > > > First, FFmpeg's interface is full of C idioms that are unintuitive to > > programmers from other languages. For example, Stefano Sabatini is > > patiently explaining to me in anoher thread how contexts are a central > > concept in FFmpeg's design. Even where I understood the code on a > > mechanical level, I had drastically underestimated their importance > > because I didn't have a mental model to understand them. Binding > > FFmpeg functionality in another language is only half the problem - > > the interface needs to be explained in terms they can understand, > > or rewritten in terms they already know. > > > > Second, the interface is full of special cases that make translation > > to other languages burdensome. For example, C errors are based on > > returning a value and requiring the caller to check it explicitly; > > whereas most other languages throw an error and allow the caller to > > catch it or not. A translator needs to convert every one of those, > > but FFmpeg functions don't have a standard mechanism to signal the > > correct behaviour for a given function. Even the documentation isn't > > reliably helpful, sometimes saying a variant of "returns an AVERROR", > > sometimes "returns a negative number", and sometimes it just > > returns an int and expects the reader to dig through the source. > > That eats up a huge amount of programmer time, and has to be done for > > every language that wants a binding. > > > > Solving those problems would make it far more practical for translators > > to make bindings in other languages, and for new people to learn FFmpeg > > even in C. For example, creating an `enum AVERROR` and rewriting > > functions to return it would make the code easier to read and drastically > > cut translator time. > > > > We always return a negative number for error. This is going to be a lot of detail for a specific example, but I think it illuminates the general point... Signalling an error with "a negative number" vs. "an AVERROR" is all-but synonymous in C - in both cases, you just do `if ( ret < 0 ) return ret;`. But the equivalent idiom in most languages involves throwing different data types. For example, a Python programmer would likely expect the former to throw an "Exception", but the latter to throw some library-specific "AVErrorException" type. A function that "returns a negative number on error" might return `-1` in all cases, or a random number that resembled an AVERROR in the case you happened to test, or the former in some versions but the latter in others. Erring towards throwing `Exception` causes people to avoid the binding because it obfuscates information they need in their use case, while erring towards `AVErrorException` causes people to avoid the binding because it generates misleading error messages. But let's assume the documentation never says "returns a negative number" when it means "returns an AVERROR", or says "AVERROR" when it means "...except in this one specal case where it returns -1". What does a binding author do with e.g. `avformat_network_init()`, which returns an `int` but doesn't say whether that `int` even indicates an error? Their choice is to either pick one of the exceptions or ignore the return code altogether, then wait for angry users to tell them they got it wrong. And given that FFmpeg has opted not to guarantee a specific meaning, any choice will need to be revisited when new versions come out. Again, this is just a small example (and I've submitted a patch for the specific avformat_network_init() issue[0]). But there are plenty of abandoned FFmpeg bindings out there, and I suspect it's because of issues like this generating extra work to write and even more work to maintain. Solving these issues in FFmpeg would be at most as much work as solving them in a single binding, and would also make it easier for new people to learn the C interface. [0] https://ffmpeg.org/pipermail/ffmpeg-devel/2024-April/325991.html _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".