Capture a movie frame

Share your advanced PureBasic knowledge/code with the community.
User avatar
Inner
PureBasic Expert
PureBasic Expert
Posts: 714
Joined: Fri Apr 25, 2003 4:47 pm
Location: New Zealand

Post by Inner »

strange that's what I tested it with, worked everytime.
DriakTravo
Enthusiast
Enthusiast
Posts: 346
Joined: Fri Oct 10, 2003 12:42 am
Location: Tampa,FL,USA
Contact:

Post by DriakTravo »

Works fine for me.
techjunkie
Addict
Addict
Posts: 1126
Joined: Wed Oct 15, 2003 12:40 am
Location: Sweden
Contact:

Post by techjunkie »

Works with some codecs, but not all... OS WinXP Pro SP1, GForce3, DirectX 9.0a
Image
(\__/)
(='.'=) This is Bunny. Copy and paste Bunny into your
(")_(") signature to help him gain world domination.
TIGER
User
User
Posts: 81
Joined: Mon Feb 23, 2004 8:33 pm

Post by TIGER »

Hi.

I was the one who asked for AVI capture.

This is exacly what i need BUT
the code give me an Eroor message
(cannot allocate memory)

Maybe there is some kind of library i must instal ?

Or maybe there is an optimuzed version of this code ?

WIN98 128RAM PIII TNT2
PIII450 128RAM TNT2
User avatar
Falko
Enthusiast
Enthusiast
Posts: 271
Joined: Sat Oct 04, 2003 12:57 pm
Location: Germany
Contact:

Post by Falko »

Hi,
works fine under XP but the self source doesn't make an Image on
OS Windows 9x. :(
I have installed Direktx 9c.
dige
Addict
Addict
Posts: 1391
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Post by dige »

Update this part of codes for PB4.x .. thx Fr34k for your help!!

Code: Select all

Structure PB_StructureMovie 
  Movie.IGraphBuilder 
  MediaControl.IMediaControl 
  MediaEvent.IMediaEventEx 
  Window.IVideoWindow 
  Audio.IBasicAudio 
  Video.IBasicVideo 
  MediaSeeking.IMediaSeeking 
  state.l 
EndStructure 

Procedure.l CaptureFrame(MovieNumber, ImageNumber)
  Protected *Movie.PB_StructureMovie, *Video.IBasicVideo, *Window.IVideoWindow
  Protected *ImageData.BITMAPINFOHEADER, DataSize, Parent, Result
  
  *Movie  = IsMovie(MovieNumber)  
  *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
        
        If IsImage( ImageNumber )
          hBmp  = ImageID( ImageNumber )
          
          w = ImageWidth(ImageNumber)
          h = ImageHeight(ImageNumber)
          
          bmi.BITMAPINFO
          bmi\bmiHeader\biSize   = SizeOf(BITMAPINFOHEADER) 
          bmi\bmiHeader\biWidth  = w
          bmi\bmiHeader\biHeight = h 
          bmi\bmiHeader\biPlanes = 1 
          
          bmi\bmiHeader\biBitCount = ImageDepth(ImageNumber) 
          bmi\bmiHeader\biBitCount = 32
          bmi\bmiHeader\biCompression = #BI_RGB 
          
          hdc = StartDrawing(ImageOutput(ImageNumber))
          If hdc
            SetDIBits_( hdc, hBmp, 0, h, *ImageData, @bmi, #DIB_RGB_COLORS) 
            StopDrawing()
          EndIf
        EndIf
      EndIf
      
      FreeMemory(*ImageData)
    EndIf
    
  EndIf   
  
  *Window\get_Owner(@Parent) 
  RedrawWindow_(Parent,0,0,#RDW_INVALIDATE)
  ProcedureReturn Result
EndProcedure
ozzie
Enthusiast
Enthusiast
Posts: 443
Joined: Sun Apr 06, 2008 12:54 pm
Location: Brisbane, Qld, Australia
Contact:

Re: Capture a movie frame

Post by ozzie »

Slight change to the above:

Code: Select all

Structure PB_StructureMovie
  Movie.IGraphBuilder
  MediaControl.IMediaControl
  MediaEvent.IMediaEventEx
  Window.IVideoWindow
  Audio.IBasicAudio
  Video.IBasicVideo
  MediaSeeking.IMediaSeeking
  state.l
EndStructure

Procedure.l CaptureFrame(MovieNumber, ImageNumber)
  Protected *Movie.PB_StructureMovie, *Video.IBasicVideo, *Window.IVideoWindow
  Protected *ImageData.BITMAPINFOHEADER, DataSize, Parent, Result
  Protected hBmp, w, h, hdc
  Protected bmi.BITMAPINFO

  *Movie  = IsMovie(MovieNumber)
  *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

        If IsImage( ImageNumber )
          hBmp  = ImageID( ImageNumber )

          w = ImageWidth(ImageNumber)
          h = ImageHeight(ImageNumber)

          bmi.BITMAPINFO
          bmi\bmiHeader\biSize   = SizeOf(BITMAPINFOHEADER)
          bmi\bmiHeader\biWidth  = w
          bmi\bmiHeader\biHeight = h
          bmi\bmiHeader\biPlanes = 1

          bmi\bmiHeader\biBitCount = ImageDepth(ImageNumber)
          bmi\bmiHeader\biBitCount = 32
          bmi\bmiHeader\biCompression = #BI_RGB

          hdc = StartDrawing(ImageOutput(ImageNumber))
          If hdc
            SetDIBits_( hdc, hBmp, 0, h, *ImageData, @bmi, #DIB_RGB_COLORS)
            StopDrawing()
          EndIf
        EndIf
      EndIf

      FreeMemory(*ImageData)
    EndIf

  EndIf

  *Window\get_Owner(@Parent)
  RedrawWindow_(Parent,0,0,#RDW_INVALIDATE)
  ProcedureReturn Result
EndProcedure
Removed the line

Code: Select all

*Movie  + MovieNumber * SizeOf(PB_StructureMovie)
as per Freak's reply to the posting Detecting CurrentMovie. Also declared variables w, h, etc as I always use EnableExplicit.

Very useful procedure.
Post Reply