Page 1 of 1
Converting a video to individual images.
Posted: Mon Dec 11, 2023 11:24 am
by matalog
I am planning on using Purebasic to load a frame of video, maybe alter it, and then save it as an image, then continue for all of the frames of a video.
Any ideas if there are any Movie or Image tools that will allow me to load a frame of a movie as an image - Or will it require understanding the encoding method and using the raw bytes of the video file to load the image to screen?
Re: Converting a video to individual images.
Posted: Mon Dec 11, 2023 12:41 pm
by infratec
Re: Converting a video to individual images.
Posted: Mon Dec 11, 2023 12:44 pm
by BarryG
Or: LoadMovie() -> PlayMovie -> MovieSeek() -> PauseMovie() -> Save image of window.
Re: Converting a video to individual images.
Posted: Mon Dec 11, 2023 1:18 pm
by Saboteur
BarryG wrote: Mon Dec 11, 2023 12:44 pm
Or: LoadMovie() -> PlayMovie -> MovieSeek() -> PauseMovie() -> Save image of window.
Last time I tried that, the video was an overlay and the frame cannot be saved. Is working that in all platforms?
Re: Converting a video to individual images.
Posted: Mon Dec 11, 2023 6:27 pm
by matalog
Great ideas. Thanks.
I'll be able to get at least one of those to work.
Re: Converting a video to individual images.
Posted: Tue Dec 12, 2023 10:55 am
by BarryG
Saboteur wrote: Mon Dec 11, 2023 1:18 pmLast time I tried that, the video was an overlay and the frame cannot be saved. Is working that in all platforms?
This works for Windows, but I don't know how to make it cross-platform as I don't have Mac/Linux.
Run this, and after 3 seconds the current frame is saved as a PNG image and app quits.
Adapt to your needs (as Rashad says) with MovieSeek(), PauseMovie(), proper error-checking, etc.
Code: Select all
UsePNGImageEncoder()
Procedure SaveWindowImage(hWnd,file$)
GetWindowRect_(hWnd,@win.RECT)
w=win\right-win\left
h=win\bottom-win\top
hBitmap=CreateImage(#PB_Any,w,h)
If hBitmap
hDC=StartDrawing(ImageOutput(hBitmap))
If hDC
SelectObject_(hDC,hBitmap)
If BitBlt_(hDC,0,0,w,h,GetDC_(0),win\left,win\top,#SRCCOPY)
f=SaveImage(hBitmap,file$,#PB_ImagePlugin_PNG)
EndIf
StopDrawing()
FreeImage(hBitmap)
EndIf
EndIf
EndProcedure
If OpenWindow(0,0,0,640,480,"test",#PB_Window_ScreenCentered|#PB_Window_SystemMenu)
ig=ImageGadget(0,0,0,640,480,0)
InitMovie()
LoadMovie(0,"D:\Movie.avi")
ResizeMovie(0,0,0,640,480)
PlayMovie(0,ig)
AddWindowTimer(0,0,3000)
Repeat
ev=WaitWindowEvent()
If ev=#PB_Event_Timer
RemoveWindowTimer(0,0)
PauseMovie(0)
SaveWindowImage(ig,"D:\MovieImage.png")
End
EndIf
Until ev=#PB_Event_CloseWindow
EndIf
Re: Converting a video to individual images.
Posted: Thu Dec 14, 2023 7:29 am
by IceSoft