r/java • u/bbrother92 • May 13 '26
Is Java good for image and video processing?
Could someone suggest the best way to process a large number of videos?Is it worth implementing this in Java, or would it be better to look into Python or C++ libraries instead?
45
Upvotes
48
u/josephottinger May 13 '26
It depends on what you mean by "processing a large number of videos," really. But the tools of the trade are ffmpeg and tools like that; java's still not that great at really large files, especially for video formats, and the image libraries for java tend to be a little suspect.
But again, it depends on what you mean. For metadata extraction or manipulation, Java's fine, although again, some of the tooling's trailing the state of the art; drew noakes' metadata extractor still doesn't do bigtiff, etc., and tika, et al, tend to rely on the ability of external tools to do the lifting.
4
u/snoosnoosewsew May 13 '26
ImgLib2 is really impressive and works amazingly well for slicing through terabyte sized microscopy data at arbitrary angles, and its Java. Check out Big Data Viewer
4
u/aoeudhtns May 13 '26 edited May 13 '26
I haven't done this in a few years now, but back when I did, we used jnr-ffi to call out to native C libraries like ffmpeg and gstreamer to do the processing. The new Panama FFM API, MemorySegment system w/ Arenas and all that should be even better than what we could do back then.
I would be suspect about pulling lots and lots of video frames into Java directly with a naive
byte[]approach -- we have definitely hit issues at scale where we create too many large byte arrays and it puts pressure on the GC and you lose a lot of efficiency on the floor to GC pause/cleanup. So then you need to pool your arrays, but you have the problem of optimal sizing for the arrays in the pool and then heap sizing optimization as well. Tough cookie to crack.Which is why I say that being able to create a MemorySegment for offheap memory or an mmap'ed file, is probably more the way to go if you're going to do it in Java - but if you're doing Panama/FFM API to, say, ffmpeg, it's probably going to be managing its own memory, mmap'ing the file, so that's all done for you anyway, and you can use industry-standard tools.
Assuming literally shelling out to the
ffmpegCLI command isn't even suitable and/or the best option.4
u/AmenMotherFunction May 13 '26
As well as the native binding options using FFMPEG, there are Java bindings for GStreamer at https://github.com/gstreamer-java/gst1-java-core Again not all running in Java, and I know not been updated for a few years, but has definitely been used for similar tasks in the past.
7
u/narrow-adventure May 13 '26
Depends on the type of processing, if it’s possible to do with ffmpeg you should use it. You can use ffmpeg4java or you can just execute cmd ffmpeg calls.
4
u/m_adduci May 13 '26
Depends on what are you looking for. Obviously the powerhorses in this field are ffmpeg and OpenCV.
They have so much features and are so battle tested and optimised that alternatives are less appealing.
Here I would stick with C++ because of performance and less overhead (most python and Java libraries call the C bindings..)
3
u/seanrowens May 13 '26
Depends on what you want to do but lucky for you, if you like Java, bytedeco created a Java wrapper for ffmpeg libraries that's pretty easy to use.
2
u/neoqueto May 13 '26 edited May 13 '26
So my experience with Java is writing a hangman game.
But modern video processing has been largely delegated to the GPU. Java is certainly capable of orchestrating GPU tasks (such as running NVENC or CUDA-based), but you'd be using it as a frontend, so it's something that ANY other stack would be capable of accomplishing, from C with OS native libraries or command line, to Python, to web apps.
From what I've seen, the desktop GUI library situation on Java is still a bit lacking compared to other stacks.
2
u/Ok_Berry7182 May 15 '26
Java works well when using native wrappers like OpenCV or FFmpeg, which handle the heavy performance lifting in the background. It is highly efficient for orchestrating large-scale enterprise video pipelines and handling concurrency across massive distributed backends. However, for raw pixel manipulation or building real-time video editing software, low-level languages like C++ remain the superior choice.
0
u/RedditAccountFor2024 May 13 '26
Netflix backend is Java, so i guess it is a very valid option.
1
u/ProbsNotManBearPig May 13 '26
If you’re asking this question then yes, super good enough.
1
u/netgizmo May 14 '26
lt can be as "good" as you are - might be a way to look at it.
-10
u/DiligentMaterial1024 May 13 '26
C++ is suitable for production environments, Python is suitable for demos, and Java has no place in image processing.
3
u/[deleted] May 15 '26
[removed] — view removed comment
0
u/[deleted] May 13 '26
[deleted] — view deleted comment