create a thumbnail from a video using libvlc

Share your advanced PureBasic knowledge/code with the community.
User avatar
CELTIC88
Enthusiast
Enthusiast
Posts: 154
Joined: Thu Sep 17, 2015 3:39 pm

create a thumbnail from a video using libvlc

Post by CELTIC88 »

Holla everyone ;)

Code: Select all

path_media$ = "path to video.mp4"
If FileSize(path_media$) < 1
	MessageRequester("error", "video not exist...")
	End
EndIf
path_libvlc$ = "C:\Program Files\VideoLAN\VLC\libvlc.dll"
If FileSize(path_libvlc$) < 1
	MessageRequester("error", "libvlc.dll Not exist...")
	End
EndIf
path_current_dir$ = GetCurrentDirectory()
SetCurrentDirectory(GetPathPart(path_libvlc$))
OpenLibrary(0,GetFilePart(path_libvlc$))
SetCurrentDirectory(path_current_dir$)

Global Semaphore = CreateSemaphore()

ProcedureC	libvlc_video_lock_cb( *opaque,  *planes.integer)
	*planes\i = *opaque
EndProcedure
ProcedureC 	libvlc_video_unlock_cb( *opaque,  *picture,  *planes.integer)
EndProcedure
ProcedureC 	libvlc_video_display_cb( *opaque,  *picture)
	SignalSemaphore(Semaphore)
EndProcedure

imagewidth = 800
imageheight = 600
sizepixel = 4
imagepitch = imagewidth * sizepixel
*imagepixels = AllocateMemory(imagewidth * imageheight * sizepixel )
CreateImage(0 , imagewidth, imageheight, sizepixel * 8)
Dim arg(4):arg(0) = UTF8("-vvv"):arg(1) = UTF8("--no-audio"):arg(2) = UTF8("--no-xlib")
libvlc = CallCFunction(0,"libvlc_new",3,@arg())
libvlc_media = CallCFunction(0,"libvlc_media_new_path",libvlc,UTF8(path_media$))
libvlc_media_player = CallCFunction(0,"libvlc_media_player_new_from_media",libvlc_media)
CallCFunction(0,"libvlc_media_release",libvlc_media)
CallCFunction(0,"libvlc_video_set_format",libvlc_media_player,UTF8("RV32"), imagewidth, imageheight, imagepitch)
CallCFunction(0,"libvlc_video_set_callbacks",libvlc_media_player, @libvlc_video_lock_cb(),
              @libvlc_video_unlock_cb(), @libvlc_video_display_cb() ,  *imagepixels)
CallCFunction(0,"libvlc_media_player_play",libvlc_media_player)

WaitSemaphore(Semaphore)

StartDrawing(ImageOutput(0))	
pixel2 = imagewidth*imageheight
pixel = 0
dbuff = DrawingBuffer()
For i = 1 To imageheight
	pixel2 - imagewidth
	CopyMemory(*imagepixels+(pixel2*sizepixel),dbuff+(pixel*sizepixel),imagewidth*sizepixel)
	pixel  + imagewidth
Next
StopDrawing()
SaveImage(0,"image.bmp")

CallCFunction(0,"libvlc_media_player_stop",libvlc_media_player)
CallCFunction(0,"libvlc_media_player_release",libvlc_media_player)
CallCFunction(0,"libvlc_release",libvlc)

interested in Cybersecurity..
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: create a thumbnail from a video using libvlc

Post by Kwai chang caine »

Hallo :mrgreen: CELTIC !!!

Too happy to read you, since this too much long time :D
I believed you are dead :lol:
All your mad great ideas missed me :wink:

I have tested your code with 3 avi movies and it return a black image :|
Perhaps my videos are not MP4, or perhaps it's because my VLC is a portable version :oops:

But thanks for sharing, and come back to see us 8)
ImageThe happiness is a road...
Not a destination
User avatar
CELTIC88
Enthusiast
Enthusiast
Posts: 154
Joined: Thu Sep 17, 2015 3:39 pm

Re: create a thumbnail from a video using libvlc

Post by CELTIC88 »

Kwai chang caine wrote: Sat Aug 07, 2021 2:42 pm Hallo :mrgreen: CELTIC !!!

Too happy to read you, since this too much long time :D
I believed you are dead :lol:
All your mad great ideas missed me :wink:

I have tested your code with 3 avi movies and it return a black image :|
Perhaps my videos are not MP4, or perhaps it's because my VLC is a portable version :oops:

But thanks for sharing, and come back to see us 8)
:D :D hello master kcc
tkt je suis toujours vivant :twisted: :twisted:


try to change movie time by inserting this line

Code: Select all

ppos.q = 1000*15 ;movie time
CallCFunction(0,"libvlc_media_player_set_time",libvlc_media_player,ppos,1)
after

Code: Select all

CallCFunction(0,"libvlc_media_player_play",libvlc_media_player)
interested in Cybersecurity..
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5342
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: create a thumbnail from a video using libvlc

Post by Kwai chang caine »

Nothing better my good friend :wink:

"Noir c'est nooooooooir...il n'y a plus d'espooooooir !!!" :mrgreen:

Image
ImageThe happiness is a road...
Not a destination
Post Reply