Video Player on Java Swing

593 views
Skip to first unread message

Castillejos Nicolas

unread,
May 18, 2016, 4:16:56 AM5/18/16
to gstreamer-java
Hi,

I'm trying to make a java application that reads a ".m4v" file in a 
JFrame using the SimpleVideoComponent class from the gstreamer examples.
But my problem is that I can only watch the first picture of the video, 
however the sound is working great.

look at my code :

EventQueue.invokeLater(new Runnable() {

             @Override
             public void run() {
                 vc = new SimpleVideoComponent();
                 bin = new PlayBin("VideoPlayer");

                 bin.setInputFile(new File("./test.m4v"));

                 f.add(vc);
                 vc.setPreferredSize(new Dimension(320, 240));

                 bin.setVideoSink(vc.getElement());
                 bin.play();

                 f.pack();
                 f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                 f.setVisible(true);

             }
         });

When i comment this line : bin.setVideoSink(vc.getElement());
the video is playing great in an other frame called "internal frame"
but when I want to play in my own frame inside the SimpleVideoComponent 
it shows only the first picture.

The method newBuffer() in the AppSinkListener of the 
SimpleVideoComponent class is called only once.
And I don't know why...

Do you have an idea to help me resolve this ?

Thank you,

Nicolas

More Informations : I Use GStreamer 1.6.4 on Windows with gstreamer1.x-java binding (https://github.com/gstreamer-java/gst1-java-core)

Neil C Smith

unread,
May 18, 2016, 4:47:32 AM5/18/16
to gstream...@googlegroups.com
Hi Nicolas,

On 18 May 2016 at 09:13, Castillejos Nicolas <djos...@gmail.com> wrote:
> I'm trying to make a java application that reads a ".m4v" file in a
> JFrame using the SimpleVideoComponent class from the gstreamer examples.
> But my problem is that I can only watch the first picture of the video,
> however the sound is working great.

I'm not sure what is causing this, but I haven't done a lot of testing
on Windows yet - anyone else using gst1-java-core on Windows see this?

Can you answer the following -

* Does the example (webcam image in Swing) work OK?
* Does your Pipeline code work with another video file using a
different codec / file format?
* Can you run this in a debugger and check if errors are thrown during
any part of the AppSinkListener? Do the bindings provide sensible
values for width / height during the listener? Is a non-null
ByteBuffer returned?
* Does moving the playbin play() after the frame is made visible make
a difference?

> When i comment this line : bin.setVideoSink(vc.getElement());
> the video is playing great in an other frame called "internal frame"

This will use a native window created by GStreamer rather than bring
the video into your Java code. It's a good start - at least you know
all the GStreamer natives are linking correctly!

Best wishes,

Neil


--
Neil C Smith
Artist : Technologist : Adviser
http://neilcsmith.net

Praxis LIVE - hybrid visual IDE for creative coding - www.praxislive.org
Digital Prisoners - interactive spaces and projections -
www.digitalprisoners.co.uk

Djos Kast

unread,
May 18, 2016, 5:55:29 AM5/18/16
to gstream...@googlegroups.com
I've found the problem , there is a little error in the java binding :

In the class org.freedesktop.gstreamer.elements.AppSink
Int the method connect(final NEW_SAMPLE listener)
the GstCallback have a callback method that returns void,
And I've look the C++ code, this method must returns a FlowReturn
I've made a fast correction :

connect(NEW_SAMPLE.class, listener, new GstCallback() {
@SuppressWarnings("unused")
public FlowReturn callback(AppSink elem) {
listener.newBuffer(elem);
return FlowReturn.OK;
}
});

And now it works great !

Neil C Smith

unread,
May 18, 2016, 6:11:35 AM5/18/16
to gstream...@googlegroups.com
Hi,

On 18 May 2016 at 10:54, Djos Kast <djos...@gmail.com> wrote:
> I've found the problem , there is a little error in the java binding :
>
> In the class org.freedesktop.gstreamer.elements.AppSink
> Int the method connect(final NEW_SAMPLE listener)
> the GstCallback have a callback method that returns void,
> And I've look the C++ code, this method must returns a FlowReturn
> I've made a fast correction :
>
> connect(NEW_SAMPLE.class, listener, new GstCallback() {
> @SuppressWarnings("unused")
> public FlowReturn callback(AppSink elem) {
> listener.newBuffer(elem);
> return FlowReturn.OK;
> }
> });
>
> And now it works great !

hmmm .. looks like you might be right. But also looks like that issue
has been in the GStreamer-Java bindings throughout 0.10 too. And as
FlowReturn.OK is just zero, I think that's what JNA would have
returned to GStreamer anyway. So, I'm none the wiser why this is
fixing your issue and no-one else has had that problem, but I'll look
at integrating it as a fix (unless you want to make a pull request?)

Farkas Levente

unread,
May 18, 2016, 7:38:49 AM5/18/16
to gstream...@googlegroups.com
On 05/18/2016 12:11 PM, Neil C Smith wrote:
> Hi,
>
> On 18 May 2016 at 10:54, Djos Kast <djos...@gmail.com> wrote:
>> I've found the problem , there is a little error in the java binding :
>>
>> In the class org.freedesktop.gstreamer.elements.AppSink
>> Int the method connect(final NEW_SAMPLE listener)
>> the GstCallback have a callback method that returns void,
>> And I've look the C++ code, this method must returns a FlowReturn
>> I've made a fast correction :
>>
>> connect(NEW_SAMPLE.class, listener, new GstCallback() {
>> @SuppressWarnings("unused")
>> public FlowReturn callback(AppSink elem) {
>> listener.newBuffer(elem);
>> return FlowReturn.OK;
>> }
>> });
>>
>> And now it works great !
>
> hmmm .. looks like you might be right. But also looks like that issue
> has been in the GStreamer-Java bindings throughout 0.10 too. And as
> FlowReturn.OK is just zero, I think that's what JNA would have
> returned to GStreamer anyway. So, I'm none the wiser why this is
> fixing your issue and no-one else has had that problem, but I'll look
> at integrating it as a fix (unless you want to make a pull request?)

i push a quick fix for 0.10.

--
Levente "Si vis pacem para bellum!"

Castillejos Nicolas

unread,
May 23, 2016, 5:44:19 AM5/23/16
to gstreamer-java
I've created a pull request for this correction
Reply all
Reply to author
Forward
0 new messages