libVLC api: seek, filters, etc
Posted: 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.
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.