Converting a video to individual images.

Just starting out? Need help? Post your questions and find answers here.
User avatar
matalog
Enthusiast
Enthusiast
Posts: 301
Joined: Tue Sep 05, 2017 10:07 am

Converting a video to individual images.

Post 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?
infratec
Always Here
Always Here
Posts: 7575
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Converting a video to individual images.

Post by infratec »

Use ffmpeg to extact the image: (RunProgram())

https://www.bannerbear.com/blog/how-to- ... ng-ffmpeg/
BarryG
Addict
Addict
Posts: 4121
Joined: Thu Apr 18, 2019 8:17 am

Re: Converting a video to individual images.

Post by BarryG »

Or: LoadMovie() -> PlayMovie -> MovieSeek() -> PauseMovie() -> Save image of window.
Saboteur
Enthusiast
Enthusiast
Posts: 272
Joined: Fri Apr 25, 2003 7:09 pm
Location: (Madrid) Spain
Contact:

Re: Converting a video to individual images.

Post 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?
[:: PB Registered ::]

Win10 Intel core i5-3330 8GB RAM Nvidia GTX 1050Ti
User avatar
matalog
Enthusiast
Enthusiast
Posts: 301
Joined: Tue Sep 05, 2017 10:07 am

Re: Converting a video to individual images.

Post by matalog »

Great ideas. Thanks.

I'll be able to get at least one of those to work.
BarryG
Addict
Addict
Posts: 4121
Joined: Thu Apr 18, 2019 8:17 am

Re: Converting a video to individual images.

Post 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
User avatar
IceSoft
Addict
Addict
Posts: 1682
Joined: Thu Jun 24, 2004 8:51 am
Location: Germany

Re: Converting a video to individual images.

Post by IceSoft »

Belive! C++ version of Puzzle of Mystralia
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
Post Reply