Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: VclPlayer and SFML  (Read 5881 times)

0 Members and 1 Guest are viewing this topic.

Mina66

  • Newbie
  • *
  • Posts: 29
    • View Profile
    • Email
VclPlayer and SFML
« on: October 12, 2012, 03:07:50 am »
Hello!
Sorry for bad English.
There is such code, http://wiki.videolan.org/LibVLC_SampleCode_SDL the video display on the surface SDL. Is it possible to implement this in SFML?

G.

  • Hero Member
  • *****
  • Posts: 1593
    • View Profile
Re: VclPlayer and SFML
« Reply #1 on: October 12, 2012, 03:54:19 am »
I don't know, but you can take a look at sfeMovie, it uses FFmpeg to display movies with SFML.
« Last Edit: October 12, 2012, 03:55:52 am by G. »

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11032
    • View Profile
    • development blog
    • Email
Re: VclPlayer and SFML
« Reply #2 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?
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Mina66

  • Newbie
  • *
  • Posts: 29
    • View Profile
    • Email
Re: VclPlayer and SFML
« Reply #3 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]
« Last Edit: October 26, 2012, 07:56:16 am by Mina66 »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: VclPlayer and SFML
« Reply #4 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.
Laurent Gomila - SFML developer

Mina66

  • Newbie
  • *
  • Posts: 29
    • View Profile
    • Email
Re: VclPlayer and SFML
« Reply #5 on: October 26, 2012, 08:30:28 am »
Thank you, Laurent. Understood. It worked.  :)

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: VclPlayer and SFML
« Reply #6 on: October 26, 2012, 08:39:08 am »
You should give the solution, in case someone else has the same problem in the future.
Laurent Gomila - SFML developer

Mina66

  • Newbie
  • *
  • Posts: 29
    • View Profile
    • Email
Re: VclPlayer and SFML
« Reply #7 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.

Synyster_Coder

  • Newbie
  • *
  • Posts: 20
    • View Profile
    • Email
Re: VclPlayer and SFML
« Reply #8 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! :)