Page 1 of 1

Synchronizing two MPEG-4 streams

Posted: 17 Nov 2008 09:50
by rasmus
Hi!

I'm developing an application that should be able to play two different MPEG-4 streams next to each other. In addition, the two streams should be synchronized (i.e. they should both display frame #n at the same time).

I've used wxWidgets and libVLC to create the GUI and play the videos, but my challenge now is the sync. As of now, I use the libvlc_media_player_play() command to first start playing video 1 and then video 2. This causes a slight delay for video 2 compared to video 1, a delay which may vary slightly each time I run the application.

Does anyone know if I would be able to solve this task using libvlc, or does anyone know of any other way to do this (not including libvlc at all)?


Thank you for your help!

Re: Synchronizing two MPEG-4 streams

Posted: 17 Nov 2008 11:18
by Jean-Baptiste Kempf
Well, try latest VLC (or devel 1.0) and try vlc file.mp4 --input-slave file2.mp4.

If that works, then do it with libVLC.

Re: Synchronizing two MPEG-4 streams

Posted: 18 Nov 2008 19:22
by rasmus
Well, try latest VLC (or devel 1.0) and try vlc file.mp4 --input-slave file2.mp4.

If that works, then do it with libVLC.
Thank you for your input, J-B! Your suggestion works, however I'm having some difficulties achieveing the desired look in my application.

I create a new VLC instance and draw the video output at the appropriate position in the GUI with this code:

Code: Select all

myarg0 = "-I"; myarg1 = "dummy"; myarg2 = "--plugin-path=.\\plugins"; myarg4 = "--input-slave=C:\\Users\\Rasmus\\Desktop\\videos\\test_12345.avi"; char *myargs2[6] = {myarg0, myarg1, myarg2, myarg4, NULL}; libvlc_media_t *m1, *m2; VLC_exception_init(&excp1); inst1 = VLC_new(4, myargs2, &excp1); video_panel1 = new wxPanel(this, -1); video_panel1->SetInitialSize(wxSize((this->GetSize().GetWidth())/2, (this->GetSize().GetHeight())/2)); HWND vlc_canvas_hwnd1 = reinterpret_cast<HWND>(video_panel1->GetHWND()); libvlc_drawable_t vlc_canvas1 = reinterpret_cast<libvlc_drawable_t>(vlc_canvas_hwnd1); player1 = VLC_media_player_new(inst1, &excp1); VLC_media_player_set_drawable(player1, vlc_canvas1, &excp1); filename1 = "C:\\Users\\Rasmus\\Desktop\\videos\\test_abcde.avi"; m1 = VLC_media_new(inst1, filename1, &excp1); VLC_media_player_set_media(player1, m1, &excp1); sizer->Add(video_panel1, 0, wxALL|wxEXPAND, 0);
However, when the "--input-slave" option is included in the creation of the VLC instance, both videos (test_abcde.avi and test_12345.avi) are displayed at the same position in the GUI. If I drop the line "VLC_media_player_set_drawable(player1, vlc_canvas1, &excp1);", the videos are not displayed in the GUI, but in two new windows that pop up.


Anyone got any ideas on how to display the videos at two different places in the GUI?

Re: Synchronizing two MPEG-4 streams

Posted: 18 Nov 2008 23:51
by Jean-Baptiste Kempf
no, do something like setoptions
and use :input-slave after filename1.

Re: Synchronizing two MPEG-4 streams

Posted: 20 Nov 2008 20:16
by rasmus
no, do something like setoptions
and use :input-slave after filename1.

Cheers, J-B!

I now have the two video files playing in sync in my GUI!
This did the trick:

Code: Select all

char *myargs3 = "--input-slave=C:\\Users\\Rasmus\\Desktop\\videos\\test_abcde.mp4"; VLC_media_add_option(m1, myargs3, &excp1);

Re: Synchronizing two MPEG-4 streams

Posted: 20 Nov 2008 22:06
by Jean-Baptiste Kempf
Great!