First test of libVLC include files.
-
- Posts: 64
- Joined: Jul 15, 2009 12:41
Re: First test of libVLC include files.
Can someone expand this sample to play the video in a WINDOW created with CreateWindowEx() and a message loop. Thanks in advanced.
Re: First test of libVLC include files.
Small example window.bi + vlc.bi (window version, without image buffer and etc.)geminis4941 wrote:Can someone expand this sample to play the video in a WINDOW created with CreateWindowEx() and a message loop. Thanks in advanced.
Code: Select all
#Include Once "vlc\vlc.bi"
#Include Once "windows.bi"
Dim msg As MSG
Dim As WNDCLASSEX wc
Dim As String NameClass="MyClass"
Dim As HINSTANCE Hinst=GetModuleHandle(0)
Declare Function wndproc(hwnd As HWND, msg As UInteger,wparam As WPARAM, lparam As LPARAM) As Integer
With wc
.cbSize=SizeOf(WNDCLASSEX)
.style=CS_HREDRAW Or CS_VREDRAW
.lpfnWndProc=@wndproc
.hInstance=Hinst
.hIcon=LoadIcon(0,IDI_QUESTION)
.hCursor=LoadCursor(0,IDC_HELP)
.hbrBackground=Cast(HBRUSH,COLOR_WINDOWFRAME)
.lpszClassName=StrPtr(NameClass)
.hIconSm=.hIcon
End With
If RegisterClassEx(@wc)=0 Then
? "Register error, press any key"
Sleep
End
EndIf
CreateWindowEx(0,NameClass,"Window 1",_
WS_VISIBLE Or WS_OVERLAPPEDWINDOW,100,100,300,300,0,0,Hinst,0)
While GetMessage(@msg,0,0,0)
TranslateMessage(@msg)
DispatchMessage(@msg)
Wend
Function wndproc(hwnd As HWND, msg As UInteger,_
wparam As WPARAM, lparam As LPARAM) As Integer
Select Case msg
Case WM_DESTROY
PostQuitMessage(0)
Case WM_CREATE '' create pleer after create parent window
Dim As String sPath
sPath = "C:\1.mp4" '' video file path (utf-8?)
Dim p_li As libvlc_instance_t Ptr
Dim p_mi As libvlc_media_player_t Ptr
Dim p_md As libvlc_media_t Ptr
Dim As ZString Ptr vlc_argv(0 To ...) = {@"--no-video-title-show"} '' command line vlc
p_li = libvlc_new(UBound(vlc_argv)+1, @vlc_argv(0))
p_md = libvlc_media_new_path(p_li,sPath)
p_mi = libvlc_media_player_new_from_media( p_md )
libvlc_media_release(p_md)
libvlc_media_player_play( p_mi)
libvlc_media_player_set_hwnd(p_mi, hwnd) '' set parent window
End Select
Return DefWindowProc(hwnd,msg,wparam,lparam)
End Function
-
- Posts: 862
- Joined: May 05, 2015 5:35
- Location: Germany
Re: First test of libVLC include files.
Alternatively, you can create the VLC instance outside of wndproc and then link it to the window. And maybe additionally you'll have to set a path to libvlc's plugin directory:
Code: Select all
#Include Once "vlc\vlc.bi"
#Include Once "windows.bi"
Dim msg As MSG
Dim As WNDCLASSEX wc
Dim As String NameClass="MyClass"
Dim As HINSTANCE Hinst=GetModuleHandle(0)
Declare Function wndproc(hwnd As HWND, msg As UInteger,wparam As WPARAM, lparam As LPARAM) As Integer
SetEnviron ("VLC_PLUGIN_PATH=e:\vlc-2_2_1\plugins") 'replace with your plugin path
With wc
.cbSize=SizeOf(WNDCLASSEX)
.style=CS_HREDRAW Or CS_VREDRAW
.lpfnWndProc=@wndproc
.hInstance=Hinst
.hIcon=LoadIcon(0,IDI_QUESTION)
.hCursor=LoadCursor(0,IDC_HELP)
.hbrBackground=Cast(HBRUSH,COLOR_WINDOWFRAME)
.lpszClassName=StrPtr(NameClass)
.hIconSm=.hIcon
End With
If RegisterClassEx(@wc)=0 Then
? "Register error, press any key"
Sleep
End
EndIf
CreateWindowEx(0,NameClass,"Window 1",_
WS_VISIBLE Or WS_OVERLAPPEDWINDOW,100,100,300,300,0,0,Hinst,0)
Dim As HWND hwnd = FindWindow(0, "Window 1") 'get window handle
Dim As String sPath
sPath = "C:\1.mp4" '' video file path (utf-8?)
Dim p_li As libvlc_instance_t Ptr
Dim p_mi As libvlc_media_player_t Ptr
Dim p_md As libvlc_media_t Ptr
Dim As ZString Ptr vlc_argv(0 To ...) = {@"--no-video-title-show"} '' command line vlc
p_li = libvlc_new(UBound(vlc_argv)+1, @vlc_argv(0))
p_md = libvlc_media_new_path(p_li,sPath)
p_mi = libvlc_media_player_new_from_media( p_md )
libvlc_media_release(p_md)
libvlc_media_player_play( p_mi)
libvlc_media_player_set_hwnd(p_mi, hwnd) '' set parent window
While GetMessage(@msg,0,0,0)
TranslateMessage(@msg)
DispatchMessage(@msg)
Wend
Function wndproc(hwnd As HWND, msg As UInteger,_
wparam As WPARAM, lparam As LPARAM) As Integer
Select Case msg
Case WM_DESTROY
PostQuitMessage(0)
End Select
Return DefWindowProc(hwnd,msg,wparam,lparam)
End Function
-
- Posts: 7
- Joined: Sep 18, 2018 19:46
Re: First test of libVLC include files.
hello,WQ1980 wrote:Hi!
My simple code (libvlc.dll, libvlccore.dll and folder "plugins" from VLC folder -> code folder):
[
i'm trying again freebasic after some years, I used it with happiness some years ago to get away trouble at job doing some intelligent batch, barcode scanner and more. I love freebasic.
I'm trying libvlc because I am looking for a way to reproduce a videoclip in new window wich should only contain the clip, the ability to resize maintaining the correct aspect radio and without any control. I'm trying the examples above and i tried to copy ibvlc.dll, libvlccore.dll and folder "plugins" (the linux equivalent because i am on a linux system); i tried to put the files both in the source code folder and both inside include/freebasic/vlc but cannot compile this is the error:
ld: impossibile trovare -lvlc
linking failed: 'ld' terminated with exit code 1
any tip? thanks in advice
Re: First test of libVLC include files.
The linker complains about being unable to find the library ("-l" stands for library) named "vlc". There should be a file "libvlc.a" or "vlc.so" or "libvlc.so" or similar. To make things simple just put it in the same folder as your source code. Also make sure the the library file is the correct one (e.g. 32 bit if you are using 32 bit freebasic).gcdevelops wrote:ld: impossibile trovare -lvlc
linking failed: 'ld' terminated with exit code 1
Re: First test of libVLC include files.
Got the same error on Ubuntu 64-bit with FBC 64-bit (not even going to try 32-bit in this case).
Linker error went away by creating the highlighted sym-link below.
/usr/lib$ ls -l libvlc*
lrwxrwxrwx 1 root root 19 Aug 11 2017 libvlccore.so.8 -> libvlccore.so.8.0.0
-rw-r--r-- 1 root root 1044808 Aug 11 2017 libvlccore.so.8.0.0
lrwxrwxrwx 1 root root 15 Sep 18 22:40 libvlc.so -> libvlc.so.5.5.0
lrwxrwxrwx 1 root root 15 Aug 11 2017 libvlc.so.5 -> libvlc.so.5.5.0
-rw-r--r-- 1 root root 130128 Aug 11 2017 libvlc.so.5.5.0
I cannot check if it actually works. I do not have the media files.
Linker error went away by creating the highlighted sym-link below.
/usr/lib$ ls -l libvlc*
lrwxrwxrwx 1 root root 19 Aug 11 2017 libvlccore.so.8 -> libvlccore.so.8.0.0
-rw-r--r-- 1 root root 1044808 Aug 11 2017 libvlccore.so.8.0.0
lrwxrwxrwx 1 root root 15 Sep 18 22:40 libvlc.so -> libvlc.so.5.5.0
lrwxrwxrwx 1 root root 15 Aug 11 2017 libvlc.so.5 -> libvlc.so.5.5.0
-rw-r--r-- 1 root root 130128 Aug 11 2017 libvlc.so.5.5.0
I cannot check if it actually works. I do not have the media files.
Last edited by badidea on Sep 18, 2018 20:58, edited 1 time in total.
-
- Posts: 7
- Joined: Sep 18, 2018 19:46
Re: First test of libVLC include files.
thanks for the prompt (almost istant) reply!gcdevelops wrote:[
ld: impossibile trovare -lvlc
linking failed: 'ld' terminated with exit code 1
any tip? thanks in advice
well, I solved simply installing libvlc-dev as described there https://wiki.videolan.org/LibVLC_Tutorial/
so if using ubuntu 18.04 like me just use this command:
sudo apt install libvlc-dev
after that I can compile the first example wich works perfectly for my needs.
ps: copying vlc libs/files isn't needed; almost on my machine
Re: First test of libVLC include files.
It shouldn't on Linux, because libraries are typically installed globally (system-wide) there. That's different on Windows where most applications are shipped with all their dependencies included.gcdevelops wrote:ps: copying vlc libs/files isn't needed; almost on my machine
-
- Posts: 7
- Joined: Sep 18, 2018 19:46
Re: First test of libVLC include files.
I have some problems when playing more then one media.
I'working in a program who must play some clip in a random way, so I made a sub to do this... after lot of try it stop's working from the second clip... surely i am doing something wrong with libvlc, maybe I have to put some command after the first clip finish, but on the videolan documentation i havn't find nothing... here is some logs:
./libvlc-example4
wait on start ...
libva info: VA-API version 1.1.0
libva info: va_getDriverName() returns 0
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/i965_drv_video.so
libva info: Found init function __vaDriverInit_1_1
libva info: va_openDriver() returns 0
[00007f5eb80344a0] avcodec decoder: Using Intel i965 driver for Intel(R) Haswell Mobile - 2.1.0 for hardware decoding
size: 654 x 374 length: 36
playing ...
sleep press any key ---> AFTER THIS THE SECOND CLIP SHOULD START
[h264 @ 0x7f5eb8077720] get_buffer() failed
[h264 @ 0x7f5eb8077720] thread_get_buffer() failed
[h264 @ 0x7f5eb8077720] decode_slice_header error
[h264 @ 0x7f5eb8077720] no frame!
[h264 @ 0x7f5eb8086ec0] get_buffer() failed
[h264 @ 0x7f5eb8086ec0] thread_get_buffer() failed
[h264 @ 0x7f5eb8086ec0] decode_slice_header error
[h264 @ 0x7f5eb8086ec0] no frame!
Errore di segmentazione (core dump creato)
here is my code:
I'working in a program who must play some clip in a random way, so I made a sub to do this... after lot of try it stop's working from the second clip... surely i am doing something wrong with libvlc, maybe I have to put some command after the first clip finish, but on the videolan documentation i havn't find nothing... here is some logs:
./libvlc-example4
wait on start ...
libva info: VA-API version 1.1.0
libva info: va_getDriverName() returns 0
libva info: Trying to open /usr/lib/x86_64-linux-gnu/dri/i965_drv_video.so
libva info: Found init function __vaDriverInit_1_1
libva info: va_openDriver() returns 0
[00007f5eb80344a0] avcodec decoder: Using Intel i965 driver for Intel(R) Haswell Mobile - 2.1.0 for hardware decoding
size: 654 x 374 length: 36
playing ...
sleep press any key ---> AFTER THIS THE SECOND CLIP SHOULD START
[h264 @ 0x7f5eb8077720] get_buffer() failed
[h264 @ 0x7f5eb8077720] thread_get_buffer() failed
[h264 @ 0x7f5eb8077720] decode_slice_header error
[h264 @ 0x7f5eb8077720] no frame!
[h264 @ 0x7f5eb8086ec0] get_buffer() failed
[h264 @ 0x7f5eb8086ec0] thread_get_buffer() failed
[h264 @ 0x7f5eb8086ec0] decode_slice_header error
[h264 @ 0x7f5eb8086ec0] no frame!
Errore di segmentazione (core dump creato)
here is my code:
Code: Select all
from: simplest libVLC example
' https://sourceforge.net/projects/simplestlibvlcexample/
#include once "vlc/vlc.bi"
' I tested flc, mp4, avi, xvid ...
dim shared TEST as string
sub play
'chdir exepath()
var instance = libvlc_new (0, NULL)
var media = libvlc_media_new_path (instance,TEST)
var player = libvlc_media_player_new_from_media (media)
libvlc_media_release(media)
libvlc_media_player_play(player)
dim as long w,h,l,timeout=2000 ' 2 seconds
print "wait on start ..."
while w=0 andalso h=0 andalso l=0 andalso timeout>=0
w = libvlc_video_get_width(player)
h = libvlc_video_get_height(player)
l = libvlc_media_player_get_length(player)
sleep 100 : timeout-=100
wend
if timeout<0 then
libvlc_media_player_release(player)
libvlc_release(instance)
?:?:?
print "play back not started !"
print "error log: in console ?"
beep:sleep:end
end if
print "size: " & w & " x " & h & " length: " & l\1000
print "playing ..."
print "sleep press any key"
sleep
libvlc_media_player_stop(player)
libvlc_media_release(media)
libvlc_media_player_release(player)
libvlc_release(instance)
end sub
TEST = "./video.mkv"
play
TEST = "./video2.mkv"
play
-
- Posts: 7
- Joined: Sep 18, 2018 19:46
Re: First test of libVLC include files.
i have made a code that can play more then one media in sequence as i need... i post an example.... it work like a charm on windows, but on linux again plays perfectly only the first clip and starting from the second the clip is not reproduced and the console says:
sleep press any key
[00007fef08036d20] cache_read stream error: cannot pre fill buffer
[00007fef080349a0] mjpeg demux error: cannot peek
any tip?
here is the code
sleep press any key
[00007fef08036d20] cache_read stream error: cannot pre fill buffer
[00007fef080349a0] mjpeg demux error: cannot peek
any tip?
here is the code
Code: Select all
#include once "vlc/vlc.bi"
dim shared TEST as string
dim shared instance as integer
dim shared player as integer
instance = libvlc_new (0, NULL)
player = libvlc_media_player_new (instance)
chdir exepath()
sub play
var media = libvlc_media_new_path (instance,TEST)
media = libvlc_media_new_path (instance,TEST)
libvlc_media_player_set_media(player,media)
libvlc_media_player_play(player)
dim as long w,h,l,timeout=2000 ' 2 seconds print "wait on start ..."
while w=0 andalso h=0 andalso l=0 andalso timeout>=0
w = libvlc_video_get_width(player)
h = libvlc_video_get_height(player)
l = libvlc_media_player_get_length(player)
sleep 100 : timeout-=100
wend
if timeout<0 then
libvlc_media_player_release(player)
libvlc_release(instance)
?:?:?
print "play back not started !"
print "error log: in console ?"
beep:sleep:end
end if
print "size: " & w & " x " & h & " length: " & l\1000
print "playing ..."
print "sleep press any key"
sleep
libvlc_media_player_pause(player)
end sub
TEST = "./prova1.avi"
play
TEST = "./prova2.avi"
play
TEST = "./prova3.avi"
play
TEST = "./prova4.avi"
play
sleep
Re: First test of libVLC include files.
The compiler is outputting a lot of warnings here. Seems you are using integers were pointers to certain vlc_types are expected.
The other examples posted above look different. Have a look at those. I get the same behaviour here (linux) with your code.
The other examples posted above look different. Have a look at those. I get the same behaviour here (linux) with your code.
-
- Posts: 7
- Joined: Sep 18, 2018 19:46
Re: First test of libVLC include files.
following your advice i restarted from the examples above, now I have some other warning during compilation but seems not important (imho of course).
but like before, the code works like a charm on windows, meanwhile on linux plays only the first clip of the cascade, the others don't start, this time without any error.
but like before, the code works like a charm on windows, meanwhile on linux plays only the first clip of the cascade, the others don't start, this time without any error.
Code: Select all
' from: simplest libVLC example
' https://sourceforge.net/projects/simplestlibvlcexample/
#include once "vlc/vlc.bi"
' I tested flc, mp4, avi, xvid ...
dim shared TEST as string
dim shared firstplay as string
firstplay="y"
chdir exepath()
sub play
if firstplay="n" then
goto notfirstplay
end if
var instance = libvlc_new (0, NULL)
firstplay="n"
var media = libvlc_media_new_path (instance,TEST)
var player = libvlc_media_player_new (instance)
'libvlc_media_release(media)
notfirstplay:
libvlc_media_player_set_media(player,media)
libvlc_media_player_play(player)
dim as long w,h,l,timeout=2000 ' 2 seconds
print "wait on start ..."
while w=0 andalso h=0 andalso l=0 andalso timeout>=0
w = libvlc_video_get_width(player)
h = libvlc_video_get_height(player)
l = libvlc_media_player_get_length(player)
sleep 100 : timeout-=100
wend
if timeout<0 then
libvlc_media_player_release(player)
libvlc_release(instance)
?:?:?
print "play back not started !"
print "error log: in console ?"
beep:sleep:end
end if
print "size: " & w & " x " & h & " length: " & l\1000
print "playing ..."
print "sleep press any key"
sleep
end sub
TEST = "./prova1.avi"
play
TEST = "./prova1.avi"
play
TEST = "./prova1.avi"
play
TEST = "./prova1.avi"
play
'libvlc_media_player_stop(player)
'libvlc_media_player_release(player)
'libvlc_release(instance)
Re: First test of libVLC include files.
Can you try this?
It restarts the same avi after 3 seconds. Could not find more small avi files on my pc.
Seems to work here, but no previous experience with libvlc myself
It restarts the same avi after 3 seconds. Could not find more small avi files on my pc.
Code: Select all
' from: simplest libVLC example
' https://sourceforge.net/projects/simplestlibvlcexample/
' https://wiki.videolan.org/LibVLC_Tutorial/
#include once "vlc/vlc.bi"
function play(fileName as string, pInstance as libvlc_instance_t ptr, pPlayer as libvlc_media_player_t ptr) as integer
var pMedia = libvlc_media_new_path (pInstance, fileName) 'libvlc_media_t ptr
libvlc_media_player_set_media(pPlayer, pMedia)
libvlc_media_player_play(pPlayer)
dim as long w, h, l, timeout = 5000 'ms
print "wait on start ..."
while w = 0 andalso h = 0 andalso l = 0 andalso timeout >= 0
w = libvlc_video_get_width(pPlayer)
h = libvlc_video_get_height(pPlayer)
l = libvlc_media_player_get_length(pPlayer)
sleep 100 : timeout -= 100
wend
if timeout < 0 then
print "Error: play back not started !"
return -1
end if
print "size: " & w & " x " & h & " length: " & l \ 1000
print "playing 3 seconds ..."
sleep 3000, 1
libvlc_media_player_stop(pPlayer)
'sleep
return 0
end function
'using pXxx for pointers
var pInstance = libvlc_new(0, NULL) 'libvlc_instance_t ptr
var pPlayer = libvlc_media_player_new(pInstance) 'libvlc_media_player_t ptr
var mediaFileName = "./P1020155.avi"
while inkey$ <> chr(27)
if play(mediaFileName, pInstance, pPlayer) < 0 then exit while
sleep 500, 1 'short pause (optinal)
wend
libvlc_media_player_release(pPlayer)
libvlc_release(pInstance)
print "END of program"
'chdir exepath() 'Not needed?
'libvlc_media_player_stop(player)
'libvlc_media_player_release(player)
'libvlc_release(instance)
'libvlc_media_release(media)
Re: First test of libVLC include files.
This one waits for the AVI to end, before starting a new one.
It does close and open again a new window for each play. Is that a problem?
Edit: Small update, easier to end the program <ESC>
Code: Select all
' from: simplest libVLC example
' https://sourceforge.net/projects/simplestlibvlcexample/
' https://wiki.videolan.org/LibVLC_Tutorial/
' https://www.videolan.org/developers/vlc-branch/doc/doxygen/html/group__libvlc.html
' https://www.videolan.org/developers/vlc/doc/doxygen/html/group__libvlc__media__player.html
#include once "vlc/vlc.bi"
function play(fileName as string, pInstance as libvlc_instance_t ptr, pPlayer as libvlc_media_player_t ptr) as integer
var pMedia = libvlc_media_new_path (pInstance, fileName) 'libvlc_media_t ptr
libvlc_media_player_set_media(pPlayer, pMedia)
libvlc_media_player_play(pPlayer)
dim as long w, h, l, timeout = 5000 'ms
print "wait on start ..."
while w = 0 andalso h = 0 andalso l = 0 andalso timeout >= 0
w = libvlc_video_get_width(pPlayer)
h = libvlc_video_get_height(pPlayer)
l = libvlc_media_player_get_length(pPlayer)
sleep 100 : timeout -= 100
wend
if timeout < 0 then
print "Error: play back not started !"
return -1
end if
print "size: " & w & " x " & h & " length: " & l \ 1000
while libvlc_media_get_state(pMedia) <> libvlc_ended
if inkey$ = chr(27) then return -1
sleep 100, 1
wend
libvlc_media_player_stop(pPlayer)
'sleep
return 0
end function
'using pXxx for pointers
var pInstance = libvlc_new(0, NULL) 'libvlc_instance_t ptr
var pPlayer = libvlc_media_player_new(pInstance) 'libvlc_media_player_t ptr
var mediaFileName = "./P1020155.avi"
while inkey$ <> chr(27)
if play(mediaFileName, pInstance, pPlayer) < 0 then exit while
sleep 500, 1 'short pause (optional)
wend
libvlc_media_player_release(pPlayer)
libvlc_release(pInstance)
print "END of program"
'chdir exepath() 'Not needed?
'libvlc_media_player_stop(player)
'libvlc_media_player_release(player)
'libvlc_release(instance)
'libvlc_media_release(media)
Edit: Small update, easier to end the program <ESC>
Last edited by badidea on Sep 30, 2018 21:33, edited 1 time in total.
-
- Posts: 7
- Joined: Sep 18, 2018 19:46
Re: First test of libVLC include files.
this code seems to work well also on linux thx!badidea wrote:This one waits for the AVI to end, before starting a new one.It does close and open again a new window for each play. Is that a problem?Code: Select all
' from: simplest libVLC example ' https://sourceforge.net/projects/simplestlibvlcexample/ ' https://wiki.videolan.org/LibVLC_Tutorial/ ' https://www.videolan.org/developers/vlc/doc/doxygen/html/group__libvlc__media__player.html #include once "vlc/vlc.bi" function play(fileName as string, pInstance as libvlc_instance_t ptr, pPlayer as libvlc_media_player_t ptr) as integer var pMedia = libvlc_media_new_path (pInstance, fileName) 'libvlc_media_t ptr libvlc_media_player_set_media(pPlayer, pMedia) libvlc_media_player_play(pPlayer) dim as long w, h, l, timeout = 5000 'ms print "wait on start ..." while w = 0 andalso h = 0 andalso l = 0 andalso timeout >= 0 w = libvlc_video_get_width(pPlayer) h = libvlc_video_get_height(pPlayer) l = libvlc_media_player_get_length(pPlayer) sleep 100 : timeout -= 100 wend if timeout < 0 then print "Error: play back not started !" return -1 end if print "size: " & w & " x " & h & " length: " & l \ 1000 while libvlc_media_get_state(pMedia) <> libvlc_ended sleep 100, 1 wend libvlc_media_player_stop(pPlayer) 'sleep return 0 end function 'using pXxx for pointers var pInstance = libvlc_new(0, NULL) 'libvlc_instance_t ptr var pPlayer = libvlc_media_player_new(pInstance) 'libvlc_media_player_t ptr var mediaFileName = "./P1020155.avi" while inkey$ <> chr(27) if play(mediaFileName, pInstance, pPlayer) < 0 then exit while sleep 500, 1 'short pause (optional) wend libvlc_media_player_release(pPlayer) libvlc_release(pInstance) print "END of program" 'chdir exepath() 'Not needed? 'libvlc_media_player_stop(player) 'libvlc_media_player_release(player) 'libvlc_release(instance) 'libvlc_media_release(media)
also my code close and open the window, the problem was that on linux only the first clip where played, while on windows plays all the clips with no problems. absolutely same code, same fb version. Maybe some of the compiler warnings that my version has genereted some problem on the linux side.
Last edited by gcdevelops on Sep 30, 2018 21:39, edited 1 time in total.