SFML community forums

Help => Graphics => Topic started by: Mina66 on October 12, 2012, 03:07:50 am

Title: VclPlayer and SFML
Post by: Mina66 on October 12, 2012, 03:07:50 am
Hello!
Sorry for bad English.
There is such code, http://wiki.videolan.org/LibVLC_SampleCode_SDL (http://wiki.videolan.org/LibVLC_SampleCode_SDL) the video display on the surface SDL. Is it possible to implement this in SFML?
Title: Re: VclPlayer and SFML
Post by: G. on October 12, 2012, 03:54:19 am
I don't know, but you can take a look at sfeMovie (http://en.sfml-dev.org/forums/index.php?topic=8701.0), it uses FFmpeg to display movies with SFML.
Title: Re: VclPlayer and SFML
Post by: eXpl0it3r on October 12, 2012, 08:36:15 am
You probably could do this, just give the VLC functions the right structs/pointers and let a sf::Texture update() with the pixel array from VLC.
But don't expect anyone to write that for you...

Btw if you hace a question/need help, why do post in the project section instead of the help forums?
Title: Re: VclPlayer and SFML
Post by: Mina66 on October 26, 2012, 07:46:21 am
Thank you, eXpl0it3r for the advice.
Print the video came out, here's the code:
#include <SFML/graphics.hpp>

using namespace sf;

struct ctx
{
    Uint8 *surf;
};

static void *e_lock(void *data, void **p_pixels)
{
    struct ctx *ctx = (struct ctx*)data;
    *p_pixels = ctx;
    return NULL;
}

static void unlock(void *data, void *id, void *const *p_pixels)
{
    struct ctx *ctx = (struct ctx*)data;

    assert(id == NULL);
}

static void display(void *data, void *id)
{
    (void) data;
    assert(id == NULL);
}

void SFML_VLC()
{
    sf::VideoMode VMode(720, 576, 16);
    sf::RenderWindow Window(VMode, "SFML 2", sf::Style::Close);

    libvlc_instance_t *libvlc = NULL;
    libvlc_media_t *m = NULL;
    libvlc_media_player_t *mp = NULL;

    char const *vlc_arg[] =
    {
        "--no-video-title-show"
    };
    int count_arg = sizeof(vlc_arg) / sizeof(*vlc_arg);
    libvlc = libvlc_new(count_arg, vlc_arg);
    char filename[] = "D:\\test 1.avi";
    m = libvlc_media_new_path(libvlc, filename);
    mp = libvlc_media_player_new_from_media(m);
    libvlc_media_release(m);

    Uint8 e_frame[720 * 576 * 4];

    libvlc_video_set_callbacks(mp, e_lock, unlock, display, &e_frame);
    libvlc_video_set_format(mp, "RV32", 720, 576, 720 * 4);
    libvlc_media_player_play(mp);

    Texture texture;
    texture.create(720, 576);
    Sprite sprite;
    sprite.setTexture(texture);

    while(Window.isOpen())
    {
        sf::Event Event;
        while(Window.pollEvent(Event))
        {
            switch(Event.type)
            {
                case sf::Event::Closed:
                    Window.close();
                    break;
                default:
                    break;
            }
        }

        Window.clear();
        texture.update(e_frame);
        Window.draw(sprite);
        Window.display();

    }

    libvlc_media_player_stop(mp);
    libvlc_media_player_release(mp);
    libvlc_release(libvlc);
}

 

but there is one problem, improper display of colors. Blue instead of red, red instead of blue. Screenshots in the attachment. Tell me, how can it then fix.
1 - as shown. 2 - original

[attachment deleted by admin]
Title: Re: VclPlayer and SFML
Post by: Laurent on October 26, 2012, 08:09:22 am
What is the "RV32" format? SFML expects RGBA 32-bits pixels, so you must make the VLC format match.
Title: Re: VclPlayer and SFML
Post by: Mina66 on October 26, 2012, 08:30:28 am
Thank you, Laurent. Understood. It worked.  :)
Title: Re: VclPlayer and SFML
Post by: Laurent on October 26, 2012, 08:39:08 am
You should give the solution, in case someone else has the same problem in the future.
Title: Re: VclPlayer and SFML
Post by: Mina66 on October 26, 2012, 08:54:57 am
You should give the solution, in case someone else has the same problem in the future.

Yes of course, sorry.
Instead of "RV32" libvlc_video_set_format certain functions, substitute "RGBA." The color returned to normal.
Thank you again for your help and for this wonderful library.
Title: Re: VclPlayer and SFML
Post by: Synyster_Coder on May 17, 2013, 01:52:09 pm
Hi, when I use this code and set the chroma format to "RGBA" from "RV32" my color is returned to normal however the alpha flickers, when I look through the frame data the alpha of each pixel is almost always = 255, when using RV32 the alpha is fine but obviously the blue and red are switched. The video I am using is a .mov, any thoughts on why this is or how to fix it?

Thanks, and thanks for SFML it's awesome! :)