Welcome! Please see the About page for a little more info on how this works.

0 votes
in Java Interop by

Hi, I have a problem trying to call a C library using JNA (on a windows platform, using vscode).

I grabbed a copy of the ffmpeg shared libraries from: https://www.gyan.dev/ffmpeg/builds/
specifically: https://www.gyan.dev/ffmpeg/builds/ffmpeg-release-full-shared.7z

I took the contents of the bin sub-directory and put it in the 'lib' directory of my clojure project. I also added this directory to my path and could happily call the ffmpeg app.

Here is the contents of my deps.edn:

{:deps
 {net.java.dev.jna/jna   {:mvn/version "5.6.0"}}
 :paths ["src" "lib"]
 }

And here is the code:

 (ns jnatest)

(import (com.sun.jna  Native Pointer))

(gen-interface
 :name jna.lib_avformat
 :extends [com.sun.jna.Library]
 :methods [[avformat_alloc_context [] Pointer]])

(def avformat
  (Native/loadLibrary "avformat-58" jna.lib_avformat))

On the the call to Native/loadLibrary I get the error:

; Execution error (UnsatisfiedLinkError) at com.sun.jna.Native/open (Native.java:-2).
; %1 is not a valid Win32 application.

I initially started with the techascent jna implementation, https://clojars.org/techascent/tech.jna, and had similiar issues, so I went back to basics.

I'm guessing it's something wrong with the libraries, but before I start recompiling all the ffmpeg libraries I thought I'd ask if there might be something simple to try.

Any hints appreciated.

3 Answers

0 votes
by

It's probably not something wrong with the library, but rather how it's being called. Unfortunately, I don't know enough about native stuff to suggest how to debug. Maybe you could try to get it working with Java without Clojure first.

0 votes
by

I can't comment on the use of native libs, but if a wrapper works for your needs, I've successfully used https://github.com/a-schild/jave2 in a Clojure project to drive the ffmpeg executable.

by
There are other options for wrapping the ffmpeg exe directly from clojure, so it doesn't help me really, but thanks for the hint. I may end up going for one of those, but I thought I'd try accessing the libs directly. An alternative would be to use the org.byte.deco ffmpeg wrappers, but I wanted to reduce the number of dependencies.
0 votes
by
...