; German forum: http://www.purebasic.fr/german/archive/viewtopic.php?t=3609&highlight= ; Author: Freak (updated for PB 4.00 by Andre) ; Date: 02. February 2004 ; OS: Windows ; Demo: No ; Save a frame of a movie to an image ; Speichert ein Video-Frame als Image (Bild-Datei) ; --------------------------------------------------------------------- ; ; CaptureFrame(#Movie, #Image, #Memory) ; ; Copies the current frame of the #Movie to the #Image. ; The movie must pe paused when calling this, otherwise it will fail. ; The #Image should be the same size as the movie (MovieWidth(), MovieHeight()) ; You must provide an unused memory bank number for temporary storage. ; ; --------------------------------------------------------------------- Structure PB_StructureMovie Movie.l ; IGraphBuilder DirectShow pointer MediaControl.l ; IMediaControl DirectShow pointer MediaEvent.l ; IMediaEventEx DirectShow pointer Window.l ; IVideoWindow DirectShow pointer Audio.l ; IBasicAudio DirectShow pointer Video.l ; IBasicVideo DirectShow pointer MediaSeeking.l ; IMediaSeeking DirectShow pointer State.l ; State of the movie EndStructure Procedure.l CaptureFrame(MovieNumber, ImageNumber) Protected *Movie.PB_StructureMovie, *Video.IBasicVideo, *Window.IVideoWindow Protected *ImageData.BITMAPINFOHEADER, DataSize, Parent, Result !extrn _PB_Movie_ObjectsArea !mov eax, [_PB_Movie_ObjectsArea] !mov [esp+12], eax *Movie + MovieNumber * SizeOf(PB_StructureMovie) *Window = *Movie\Window *Video = *Movie\Video Result = 0 If *Video\GetCurrentImage(@DataSize, 0) = #S_OK *ImageData = AllocateMemory(DataSize) If *ImageData If *Video\GetCurrentImage(@DataSize, *ImageData) = #S_OK Result = SetDIBits_(0, ImageID(ImageNumber), 0, *ImageData\biHeight, *ImageData+*ImageData\biSize, *ImageData, #DIB_RGB_COLORS) EndIf FreeMemory(*ImageData) EndIf EndIf *Window\get_Owner(@Parent) RedrawWindow_(Parent,0,0,#RDW_INVALIDATE) ProcedureReturn Result EndProcedure ; --------------------------------------------------------------------- ; Code example: ; --------------------------------------------------------------------- #Movie = 0 #Image = 0 #Window = 0 #Gadget_Capture = 0 #Gadget_Image = 1 If InitMovie() FileName$ = OpenFileRequester("Choose Movie","","Movie Files|*.mpg;*.avi;*.mpeg|All Files|*.*", 0) If LoadMovie(#Movie, FileName$) Width = MovieWidth(#Movie) Height = MovieHeight(#Movie) CreateImage(#Image, Width , Height) If OpenWindow(#Window, 0, 0, Width , Height*2 + 35, "Frame Capture", #PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_Invisible) If CreateGadgetList(WindowID(#Window)) ButtonGadget(#Gadget_Capture, (Width -100)/2, Height+5, 100, 25, "Capture Frame") ImageGadget(#Gadget_Image, 0, Height+35, Width, Height, ImageID(#Image)) PlayMovie(#Movie, WindowID(#Window)) HideWindow(#Window, 0) Repeat Event = WindowEvent() If Event = #PB_Event_Gadget And EventGadget() = #Gadget_Capture PauseMovie(#Movie) CaptureFrame(#Movie, #Image) SetGadgetState(#Gadget_Image, ImageID(#Image)) ResumeMovie(#Movie) EndIf If Event = 0 Delay(1) EndIf Until Event = #PB_Event_CloseWindow EndIf EndIf EndIf EndIf End ; IDE Options = PureBasic v4.02 (Windows - x86) ; Folding = -