Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (499)
Games in Android Showcase (118)
games submitted by our members
Games in WIP (567)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1] 2
  ignore  |  Print  
  VLCJ in OpenGL / LWJGL  (Read 14412 times)
0 Members and 1 Guest are viewing this topic.
Offline Cero
« Posted 2011-09-28 23:23:56 »

Yeah another thread from me about video playback. I'm just hell bent on getting video playback.

Basically, VLCJ works great - in Swing.
However there are no examples for using it in OpenGL.

Emailed with the creator, Mark Lee, and he said:
Quote
use DirectMediaPlayer and a class that implements RenderCallback - this implementation copies the native video memory to an OpenGL texture
http://vlcj.googlecode.com/svn-history/r679/trunk/vlcj/javadoc/uk/co/caprica/vlcj/player/direct/DirectMediaPlayer.html

I'm not even an OpenGL guy, so this is above my head - can anybody get this working with LWJGL ?

Offline ra4king

JGO Kernel


Medals: 347
Projects: 3
Exp: 5 years


I'm the King!


« Reply #1 - Posted 2011-09-29 02:46:14 »

From the Javadoc, the class that implements RenderCallback should retrieve the frame data from com.sun.jna.Memory.
Also from the Javadoc, if you need the RGB data, use RenderCallbackAdapter instead.

Offline theagentd
« Reply #2 - Posted 2011-09-29 08:44:11 »

You seem to be able to get a ByteBuffer from Memory, so why not directly send that to OpenGL using glTexImage2D or something?
How do you get VLCJ working? Video playback is something I've tried getting to work for a long time too, but I never really got anywhere. Does it require you to install VLC? Any native files?

Myomyomyo.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline gouessej
« Reply #3 - Posted 2011-09-29 09:45:49 »

You seem to be able to get a ByteBuffer from Memory, so why not directly send that to OpenGL using glTexImage2D or something?
How do you get VLCJ working? Video playback is something I've tried getting to work for a long time too, but I never really got anywhere. Does it require you to install VLC? Any native files?
VLCJ has been used with JMonkeyEngine 3 and the LWJGL renderer as you can see in the screenshots. I hope this helps...

Offline princec

JGO Kernel


Medals: 386
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #4 - Posted 2011-09-29 10:09:19 »

I'm still holding out for a pure Java Ogg Theora solution :/

Cas Smiley

Offline gouessej
« Reply #5 - Posted 2011-09-29 10:59:36 »

I'm still holding out for a pure Java Ogg Theora solution :/

Cas Smiley
What about curtado?

Offline princec

JGO Kernel


Medals: 386
Projects: 3
Exp: 16 years


Eh? Who? What? ... Me?


« Reply #6 - Posted 2011-09-29 11:02:10 »

Didn't work properly last time I tried but that was a year ago. I may revisit it.
<edit>Last release was May 2010, so I suspect it's still not quite right.

Cas Smiley

Offline Cero
« Reply #7 - Posted 2011-09-29 11:35:05 »

jME3 has currently no video playback - it's deprecated
http://jmonkeyengine.org/groups/general-2/forum/topic/video-playback-in-jme3/?_wpnonce=84688917db

I got VLCJ to work by setting the jna library path -> System.setProperty("jna.library.path", "vlib");
in vlib I have the vlc dlls and a plugin folder which holds the codecs, and some other commands to specifically look there
1  
new MediaPlayerFactory(new String[] {"--no-video-title-show", "--plugin-path=vlib/plugins"});

and so on. Works on Windows and Linux
Problems are here: cannot use in OpenGL; as is the problem with ALL video solutions
and well... codec shipping legal issues
If you only ship the theora codec it should be fine. However out of every codec in vlc's beautiful codec collection, that one is not stable: http://forum.videolan.org/viewtopic.php?f=14&t=78720&p=313041#p313041

Either I get one of these working,
or program a kind of cutscene system in which I can at least show images and do effects, kinda like a visual novel
or I gotta go to XNA Grin

It's so crazy that there is no easy way in java. Every game has videos normally. Start up, nvidia logo, company logo, intro fmv, then main menu.
And it's just... well it's hard doing in-game cutscenes for everything.
It's like Final Fantasy VII, sure there are in-game scenes with stuff happening, but sometimes you need scenes of WEAPON attacking Junon, or whatever

Offline nsigma
« Reply #8 - Posted 2011-09-29 13:37:54 »

Problems are here: cannot use in OpenGL; as is the problem with ALL video solutions

Huh?  Why?

You seem to be able to get a ByteBuffer from Memory, so why not directly send that to OpenGL using glTexImage2D or something?

That would seem about the way to do it.  Don't use the RenderCallbackAdaptor, as you don't want to copy the data into Java unnecessarily.  Just beware that the ByteBuffer returned from JNA's Pointer class is not a copy, and therefore is the same memory that VLC is going to keep writing into - don't do anything daft with it!  Smiley

Also, speaking of legal issues, I assume you're aware that VLC and VLCJ are GPL?  If you need a more liberal solution it might be worth looking at the GStreamer-Java bindings - they're LGPL.  You could also look at the code in the GSVideo library for Processing which uses GStreamer-Java and ships with the precompiled native libs for Windows and Mac, and also has some code somewhere to directly update an OpenGL texture from the video stream.

Best wishes, Neil

Praxis LIVE - open-source intermedia toolkit and live interactive visual editor
Digital Prisoners - interactive spaces and projections
Offline theagentd
« Reply #9 - Posted 2011-09-29 13:50:38 »

I'll try it out when I get time. I'm so busy gaming right now. >_>

So because VLCJ is GPL, I'd have to release my entire game under GPL too?
This GStreamer binding (no idea what GStreamer is), can you also get access to frame memory like in VLCJ? Avoiding copying millions of pixels 24 times per second is pretty important...

Myomyomyo.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline nsigma
« Reply #10 - Posted 2011-09-29 14:22:01 »

So because VLCJ is GPL, I'd have to release my entire game under GPL too?
Yes!  IANAL blah de blah Grin
This GStreamer binding (no idea what GStreamer is), can you also get access to frame memory like in VLCJ? Avoiding copying millions of pixels 24 times per second is pretty important...

hmmmm...  Tongue

The binding is JNA based like VLCJ, and has been around a bit longer.  And yes, you can get direct memory access to the pixels in the same way.

Praxis LIVE - open-source intermedia toolkit and live interactive visual editor
Digital Prisoners - interactive spaces and projections
Offline Cero
« Reply #11 - Posted 2011-09-29 14:42:51 »

Problems are here: cannot use in OpenGL; as is the problem with ALL video solutions

Huh?  Why?
Because they are all for Swing/AWT and I am not an OpenGL programmer.

looking at the GStreamer-Java bindings - they're LGPL.  You could also look at the code in the GSVideo library for Processing which uses GStreamer-Java and ships with the precompiled native libs for Windows and Mac, and also has some code somewhere to directly update an OpenGL texture from the video stream.
GStreamer is the only I haven't looked into as thoroughly yet. As it seems to be similar to VLC.
And yeah I know there is a processing thing - running on 3 OS'... getting the code from that just seems like a nightmare, crawling through processing source code...

So because VLCJ is GPL, I'd have to release my entire game under GPL too?
Yes, Mark Lee told me too. Not THAT much of a problem.

Offline nsigma
« Reply #12 - Posted 2011-09-29 15:10:26 »

Because they are all for Swing/AWT and I am not an OpenGL programmer.

As far as I'm aware, both GStreamer-Java and VLCJ started off rendering into whatever the native video component provided by the library is.  After that, direct pixel access was provided through JNA pointers which has allowed rendering into Swing / AWT / BufferedImage or whatever.  You can do what you want with that pixel data, though.

btw - this is all interesting timing as I'm working on the OpenGL renderer for Praxis, and that already uses GStreamer-Java for video playback, so I'm currently looking into the best ways of getting the data directly into OpenGL.

GStreamer is the only I haven't looked into as thoroughly yet. As it seems to be similar to VLC.
And yeah I know there is a processing thing - running on 3 OS'... getting the code from that just seems like a nightmare, crawling through processing source code...

You don't need to look through all the Processing code!!!  GSVideo just has a few classes that deal with loading the native GStreamer libs on various platform that might be useful.

Praxis LIVE - open-source intermedia toolkit and live interactive visual editor
Digital Prisoners - interactive spaces and projections
Offline Cero
« Reply #13 - Posted 2011-09-29 15:33:16 »

You don't need to look through all the Processing code!!!  GSVideo just has a few classes that deal with loading the native GStreamer libs on various platform that might be useful.

Libs written for Processing import and use Processing classes like PImage, so its not portable to non-processing without effort.

Looking into some gStreamer & LWJGL stuff right now.

Offline nsigma
« Reply #14 - Posted 2011-09-29 15:46:11 »

You don't need to look through all the Processing code!!!  GSVideo just has a few classes that deal with loading the native GStreamer libs on various platform that might be useful.

Libs written for Processing import and use Processing classes like PImage, so its not portable to non-processing without effort.

Yes, sorry, should have been clearer.  There's stuff that may be useful, but you'll have to hack it out!  See how you get on with GStreamer-Java by itself first - the GSVideo stuff is only really useful if you want to ship the native libs yourself, and that's doable without it.

I've used this binding quite a lot, so I can try and answer any questions you have about it.  Maybe post them in a "GStreamer-Java in OpenGL / LWJGL" thread!  Smiley

Praxis LIVE - open-source intermedia toolkit and live interactive visual editor
Digital Prisoners - interactive spaces and projections
Offline Cero
« Reply #15 - Posted 2011-10-17 21:57:21 »

The maker of vlcj wrote me an email today

he wrote this, using jme3:  http://code.google.com/p/vlcj/wiki/JMonkeyEngineExample

Offline theagentd
« Reply #16 - Posted 2011-10-18 09:55:28 »

RenderCallback: That looks ridiculously easy! No need for a 16-bit RGBA texture though... xD

Myomyomyo.
Offline Cero
« Reply #17 - Posted 2012-02-29 00:41:18 »

So, I'm painfully close in getting it to work.

See the link in my above post for reference (RenderCallback in VLCJ with display(Memory))

Source:  http://www.java-gaming.org/index.php?action=pastebin&hex=33ad12326

almost there. Maybe I'm doing something incredibly stupid here with the buffers. But I'm not an OpenGL programmer =D

Getting:
Quote
Exception in thread "main" java.lang.IllegalArgumentException: Number of remaining buffer elements is 2785280, must be at least 6291456. Because at most 6291456 elements can be returned, a buffer with at least 6291456 elements is required, regardless of actual returned element count

To bottom line this: Once it works, video playback works.
You can ship VLC, just like a private JRE, including all natives for windows, linux and mac, just like with the lwjgl dlls.

Then there is only license problems, with java library and codecs.
To solve them: only include theora & vorbis codec
Make your code GPL, or at least that part that uses/communicates with VLCJ, still have to know which one

Offline Riven
« League of Dukes »

JGO Overlord


Medals: 801
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #18 - Posted 2012-02-29 00:47:59 »

The problem is that you shove a 1280x554 raster into a texture with the dimensions 2048x1024. It won't fit.

You either have to pad a lot of pixels, or use non-POT textures. I think the latter will be the best option.


Quote
To bottom line this: Once it works, video playback works.
I don't think you're as near as you think you are. The 'buf' variable is never really filled with data, so you'd be rendering a black screen, although even that wouldn't work, as you never actually create a texture, you simply call GL11.glBindTexture(GL11.GL_TEXTURE_2D, 1); where '1' should be the handle that glGenTextures provided. This will result in a crash.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline Cero
« Reply #19 - Posted 2012-02-29 00:52:36 »

The problem is that you shove a 1280x554 raster into a texture with the dimensions 2048x1024. It won't fit.

You either have to pad a lot of pixels, or use non-POT textures. I think the latter will be the best option.

Further, you never actually create a texture, you simply call GL11.glBindTexture(GL11.GL_TEXTURE_2D, 1); where '1' should be the handle that glGenTextures provided.

I removed the get2Fold parts.
no error.
however no picture, the texture is white - this happens when you bind something thats not there usually

GL11.glBindTexture(GL11.GL_TEXTURE_2D, 1);

0, 1, 2, nothing works

so not sure what the problem is

Offline Riven
« League of Dukes »

JGO Overlord


Medals: 801
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #20 - Posted 2012-02-29 00:54:41 »

I updated my previous post. You're not really connecting any parts in the code you provided: you create a buffer and never fill it, pushing it into the texture every frame and expecting a video will play when you draw it. You have misconceptions about OpenGL and I advice you to work on that first. Try to load your own (non-POT) texture, then you'll see that glGenTextures() is not optional, and how there are many more calls to OpenGL required to set this up properly.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline Cero
« Reply #21 - Posted 2012-02-29 01:05:35 »

Quote
buffer not being filled

right here
1  
buf = memory.getByteBuffer(0, 1280 * 544 * 4);


display(Memory) is getting called and memory filled by VLCJ itself

like here  http://code.google.com/p/vlcj/wiki/JMonkeyEngineExample

Offline Riven
« League of Dukes »

JGO Overlord


Medals: 801
Projects: 4
Exp: 16 years


Hand over your head.


« Reply #22 - Posted 2012-02-29 01:09:56 »

Hm, okay, how are the buffer blits synced? You never request a new frame, and without any request, it must be running on another thread, which will cause lots of tearing as the buffer can be modified during upload.

Hi, appreciate more people! Σ ♥ = ¾
Learn how to award medals... and work your way up the social rankings
Offline Cero
« Reply #23 - Posted 2012-02-29 01:21:02 »

glGenTextures() is not optional
yeah glGenTextures, ok, doing this, now. No change though.
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
IntBuffer tmp = createIntBuffer(1); 
GL11.glGenTextures(tmp);
glTextureID = tmp.get(0);

public IntBuffer createIntBuffer(int size)
{
      ByteBuffer temp = ByteBuffer.allocateDirect(4 * size);
      temp.order(ByteOrder.nativeOrder());

      return temp.asIntBuffer();
}

GL11.glBindTexture(GL11.GL_TEXTURE_2D, glTextureID);


Hm, okay, how are the buffer blits synced? You never request a new frame, and without any request, it must be running on another thread, which will cause lots of tearing as the buffer can be modified during upload.
Yeah no idea. Looking at the JME example it says "Synchronisation might be required..."
I assumed frames were requested by time automatically, because there aren't any calls in the JME example for this.
But yeah tearing and sync... well first I need it to display anything.

Offline Cero
« Reply #24 - Posted 2012-02-29 05:05:33 »

I uploaded an eclipse project, so people who wanna help can actually try.
http://www.mediafire.com/?m3eloau579blx13

This project contains everything you need, but only works on windows (only has the vlc dlls).
You dont need VLC installed or anything like that. A Video to test with is also contained.

TO run the LWJGL class just use the vm parameter "-Djava.library.path=lib" (if my configurations dont show up)

Offline ra4king

JGO Kernel


Medals: 347
Projects: 3
Exp: 5 years


I'm the King!


« Reply #25 - Posted 2012-02-29 05:12:02 »

You can also use
1  
2  
3  
4  
5  
public static void main(String[] args) {
    System.setProperty("org.lwjgl.librarypath",System.getProperty("user.dir") + "/relative/path/to/root/of/natives/");
   
    ....
}


This is a not well known LWJGL hidden switch that lets you bypass the -Djava.library.path option.

Offline davedes
« Reply #26 - Posted 2012-02-29 05:46:15 »

Ugh... can't seem to get this on my MacOSX. Keeps giving me "[0x100150020] main libvlc error: No plugins found! Check your VLC installation." even though I am using the proper VLC_PLUGIN_PATH variable for my VLC version... Huh

Offline Cero
« Reply #27 - Posted 2012-02-29 05:55:29 »

Ugh... can't seem to get this on my MacOSX. Keeps giving me "[0x100150020] main libvlc error: No plugins found! Check your VLC installation." even though I am using the proper VLC_PLUGIN_PATH variable for my VLC version... Huh

Just read. I told you, only windows.
Adding the Linux .so files would be best I could do
No access to a mac anyway

Offline davedes
« Reply #28 - Posted 2012-02-29 05:58:37 »

Nah, I've been trying to get it working using the JARs from the VLCJ/JNA website -- not your eclipse package. After some tweaking I got it to link with my VLC libraries (vlclib/vlccore) but I've hit a roadblock with the plugins problem.

Offline Cero
« Reply #29 - Posted 2012-02-29 06:15:37 »

I dont even know what "VLC_PLUGIN_PATH" is =D
I just set the JNA lib path in my source, to a local vlc copy

they want you to install it like normal, then link to it using this global variable and shit
but I just copied a private copy of what we need here

Pages: [1] 2
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Pippogeek (39 views)
2014-09-24 16:13:29

Pippogeek (30 views)
2014-09-24 16:12:22

Pippogeek (19 views)
2014-09-24 16:12:06

Grunnt (44 views)
2014-09-23 14:38:19

radar3301 (25 views)
2014-09-21 23:33:17

BurntPizza (62 views)
2014-09-21 02:42:18

BurntPizza (32 views)
2014-09-21 01:30:30

moogie (39 views)
2014-09-21 00:26:15

UprightPath (50 views)
2014-09-20 20:14:06

BurntPizza (54 views)
2014-09-19 03:14:18
List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!