libVLC api: seek, filters, etc

This forum is about all development around libVLC.
umod.47
New Cone
New Cone
Posts: 4
Joined: 03 Mar 2018 16:02

libVLC api: seek, filters, etc

Postby umod.47 » 03 Mar 2018 17:35

Hello.
I used to embed video in a Qt/C++ application using LibVLC (more precisely - libVLC-Qt), and it works brilliantely as long as I just need to open video and play it.
I've donated some money tho the project because it has saved me a ton of my time.

Now I'm using libVLC in a C++ project which involves some advanced video manipulations like zooming, seeking video files and playing them simultaneously or playing a video fragment in a loop. I had to switch to pure libVLC with no additional libraries for a more advanced control. I have the following problems I can't solve with existing libVLC API documentation:

1) libVLC has some video filters, one of them is a crop filter, that can be used as a way to zoom video. However, I can't enable any filter using libVLC api. The only thing I managed to do is to render video into a memory buffer (QImage), apply some zoom on my own and put this image on the window. But this process is around 2 times slower (uses twice as much CPU), which is critical on something like 1080p videos and slow computers.
Is there a way to enable crop filter using libVLC and manipulate its parameters "on the fly"? (I.e., how many pixels to crop from each side). This way I can use libvlc_media_player_set_hwnd() to output video.
VLC player has video filters that can be enabled, configured and disabled "on the fly".
I've found libvlc_video_set_crop_geometry() api, but I can't figure out how it is supposed to work.

2) I can't say exactly when the video is ready to play. I mean, I can't tell when I can call libvlc_media_player_play() so that player starts to play immediately. As long as I've tested, the video is ready to play if it has just been paused. This is a big issue when I want to rewind video using libvlc_media_player_set_time() and then start playing it (loop play).
No event callbacks can help me. No events happen when the video actually becomes ready.
Some polling to libvlc_media_player_get_time() can be done, as long as actual video position is changed a little when the video is prepared compleyely, but I don't think this is a stable method.
The function libvlc_media_player_will_play() won't help me as well.
I can't even say the video is ready when I render it into image. The fact that the image is ready after libvlc_media_player_set_time() doesn't mean that the video will actually play, because some addition processing is done in the backgtound, and the second frame is some (unpredictable) ms away.
I have to let user decide when to start playing video after rewind. The video is ready to play around a second after rewind, and this is visible through the image actually displayed, but no events happen, and I don't know what to poll.
Moreover, I won't get any video prepared unless I call libvlc_media_player_play(). Looks like the video is actually processed after this call.
Is there a way to "force" libVLC to prepare video to be played and to say when it is completely ready (rewinded, loaded, etc)?

3) Is there a way to switch rendering method (on the window or in the image) "on the fly" without re-creating vlc_media_player?
As long as I was unable to zoom video using VLC filters, I had to make 2 different widgets: the one that works quick but can't zoom (libvlc_media_player_set_hwnd()) and the one that renders video into image, so thai I can zoom it, but it's twice as slow (libvlc_video_set_callbacks() and libvlc_video_set_format_callbacks()). When the user switches to zoomable video or back, I have to delete the existing widget and make a new one, then seek it to the time where the previous one has stopped, and start playing the video. This is a slow process that takes some seconds and makes the screen blink.
Can I avoid it?

4) I'm creating libVLC instance and vlc player for each video widget. Is it correct, or I should change to one instance per whole application and one player per widget?

Thanks.

mangokm40
Cone that earned his stripes
Cone that earned his stripes
Posts: 130
Joined: 20 May 2010 20:00

Re: libVLC api: seek, filters, etc

Postby mangokm40 » 07 Mar 2018 20:50

Does the function "libvlc_video_set_scale()" not do the "zoom" that you need?

I don't think Crop is the same as zoom. I use "libvlc_video_set_crop_geometry()" as shown in these examples:
libvlc_video_set_crop_geometry(vlcPlayer, "128+0+0+0"); // crop 128 pixels left
libvlc_video_set_crop_geometry(vlcPlayer, "0+0+128+0"); // crop 128 pixels right
libvlc_video_set_crop_geometry(vlcPlayer, "0+72+0+0"); // crop 72 pixels top
libvlc_video_set_crop_geometry(vlcPlayer, "0+0+0+72"); // crop 72 pixels bottom

umod.47
New Cone
New Cone
Posts: 4
Joined: 03 Mar 2018 16:02

Re: libVLC api: seek, filters, etc

Postby umod.47 » 08 Mar 2018 14:48

Great! Crop geometry is exactly what is needed! With proper handling this is almost the same as zoom.
Looks like API description is really missing the format of crop string.

Now I have to come through the fact that Qt widget that is use to display the video (libvlc_media_player_set_hwnd) doesn't receive any mouse events.
I've tried this:

Code: Select all

libvlc_video_set_mouse_input(libvlcMediaPlayer,false);
But it only hides the mouse. Still, no Qt events that I can catch.
Just as described here: https://stackoverflow.com/questions/293 ... t-on-win64

Is there some kinda callback with mouse events, for example?

umod.47
New Cone
New Cone
Posts: 4
Joined: 03 Mar 2018 16:02

Re: libVLC api: seek, filters, etc

Postby umod.47 » 21 Mar 2018 21:07

OK, now for a low level API...
I need to add a waveform graph to the application to display it and scroll it as the video plays (imagine something like Audacity with video player added).
VLC has audio callback, which I can use to catch audio and play it, but it won't send me waveform data for a part of video that has not been played yet.

I was able to extract waveform for the whole file using FFMpeg libraries, but there are reasons to avoid FFMpeg: the video player is a primary target, FFMpeg requires a lot of code to make video player work, and I don't think that carrying two big libraries in one project is a god idea.

Is there a low level API in VLC, that can do the same: demux the file and decode audio information from it?
I guess, there is something inside libVLCCore, but it's not documented :(

P.S. Still, mouse and keyboard events are suppressed for a Qt widget if it is used as a target for libvlc_media_player_set_hwnd. Is there a way to catch mouse events in this case? Some callback in VLC or just disabling event handling in VLC completely?

P.P.S. Most of the questions of the first post are still not answered, and I couldn't figure them out myself :(

Thanks.


Return to “Development around libVLC”

Who is online

Users browsing this forum: No registered users and 12 guests