MovieStatus > MovieLength Je comprends pas ...

Sujets variés concernant le développement en PureBasic
Avatar de l’utilisateur
Thyphoon
Messages : 2697
Inscription : mer. 25/août/2004 6:31
Localisation : Eragny
Contact :

MovieStatus > MovieLength Je comprends pas ...

Message par Thyphoon »

Bonjour

je ne comprends rien a MovieStatus() et MovieLength
je cherche a pouvoir avancer et reculer a l'image prêt mais surtout connaitre a quel position en temps je suis rendu...
MovieStatus est sensé renvoyer est le numéro de la trame en cours d'affichage.
MovieLength est sensé renvoyer la longueur de la vidéo en nombre de trames.
mais Movie Status est >MovieLength

quelqu'un a compris comment ça marche ?
comment transformé MovieStatus en temps et MovieLength en temps et comment transformé un temps pour MovieSeek ?

J'essaye de faire un outil qui permet de prendre des photos a partir de film GoPro. Et de façon que la photo ai la bonne heure de création en fonction de la date de debut du film et du temps écoulé dans le film.
Freak a fournit un code pour faire la copie d'ecran.
Voici mon code.
Si quelqu'un a une idée,une explication, je suis preneur. Merci

Code : Tout sélectionner

UseJPEGImageEncoder()
;Source : http://www.forums.purebasic.com/english/viewtopic.php?f=12&t=9384&hilit=MovieSeek&sid=35210c834fc99808364128cad84e2228
;coded by Freak
;Updated by dige
;Updated by ozzie
;
; ---------------------------------------------------------------------
;
; 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())
;
; ---------------------------------------------------------------------

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


; ---------------------------------------------------------------------
; Code example:
; ---------------------------------------------------------------------

#Movie = 0
#Image = 0

#Window = 0
Enumeration
#Gadget_Capture
#Gadget_Play
#Gadget_Frame
#Gadget_Pause
EndEnumeration

If InitMovie()
  FileName$ = OpenFileRequester("Choose Movie","","Movie Files|*.mpg;*.avi;*.mpeg|All Files|*.*", 0)
  date.i=GetFileDate(FileName$, #PB_Date_Created)
  If LoadMovie(#Movie, FileName$)
  Debug MovieInfo(#Movie, 0)
    Width = MovieWidth(#Movie)
    Height = MovieHeight(#Movie)
  
    CreateImage(#Image, Width , Height)

    If OpenWindow(#Window, 0, 0, 800 , 600, "Frame Capture", #PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_Invisible)
    
        ButtonGadget(#Gadget_Play, 0, 0, 100, 25, "play")
        ButtonGadget(#Gadget_Pause, 100, 0, 100, 25, "pause")
        StringGadget(#Gadget_Frame, 200,0,100,25,"")
        ButtonGadget(#Gadget_Capture, 300, 0, 100, 25, "Capture")
        ResizeMovie(#Movie,0,50,WindowWidth(#Window) ,Height*WindowWidth(#Window)/Width)
        PlayMovie(#Movie, WindowID(#Window))
        time=ElapsedMilliseconds()
        SmartWindowRefresh(#Window,  #True)
        AddWindowTimer(#Window,0,1000)
        HideWindow(#Window, 0)
        
        Repeat
          Event = WindowEvent()
          If Event = #PB_Event_Timer
            Debug "movie "+Str(MovieStatus(#Movie)/1000)+" "+Str(MovieLength(#Movie))
            Debug "time "+Str(ElapsedMilliseconds()-time)
          EndIf 
          If Event = #PB_Event_Gadget 
            
            Select EventGadget()
              Case #Gadget_Capture
                  resume.b=#False
                  If MovieStatus(#Movie)>0
                  SetGadgetText(#Gadget_Frame,Str(MovieStatus(#Movie)))
                  pos.l=MovieStatus(#Movie)
                  PauseMovie(#Movie)
                  resume.b=#True
                EndIf 
                 If MovieStatus(#Movie)=-1
                   CaptureFrame(#Movie, #Image)
                   newDate=AddDate(date,#PB_Date_Second,pos)
                   name.s=FormatDate("%yyyy-%mm-%dd %hhh%iim%sss",newDate)+" "+GetFilePart(FileName$,#PB_FileSystem_NoExtension)+".jpg"
                   SaveImage(#Image,name,#PB_ImagePlugin_JPEG)
                   SetFileDate(name,#PB_Date_Created,newDate)
                EndIf
                If resume=#True
                  ResumeMovie(#Movie)
                EndIf 
                Case #Gadget_Pause
                  If MovieStatus(#Movie)>0
                   pos.l=MovieStatus(#Movie) ;renvoie la position dans le film en seconde
                  SetGadgetText(#Gadget_Frame,Str(MovieStatus(#Movie)))
                  PauseMovie(#Movie)
                  EndIf 
                Case #Gadget_Play
                  If MovieStatus(#Movie)<=0
                    MovieSeek(#Movie,ValD(GetGadgetText(#Gadget_Frame)))
                    ResumeMovie(#Movie)
                  EndIf 
                Case #Gadget_Frame
                  If MovieStatus(#Movie)<=0
                  MovieSeek(#Movie,ValD(GetGadgetText(#Gadget_Frame)))
                  ResumeMovie(#Movie)
                  PauseMovie(#Movie)
                  EndIf 
                EndSelect
          EndIf
          
          If Event = 0
            Delay(1)
          EndIf
          
        Until event = #PB_Event_CloseWindow

    EndIf        
    
  EndIf
  
EndIf

End
Avatar de l’utilisateur
Thyphoon
Messages : 2697
Inscription : mer. 25/août/2004 6:31
Localisation : Eragny
Contact :

Re: MovieStatus > MovieLength Je comprends pas ...

Message par Thyphoon »

Thyphoon a écrit :Bonjour

je ne comprends rien a MovieStatus() et MovieLength() :oops:
je cherche a pouvoir avancer et reculer a l'image prêt mais surtout connaitre a quel position dans le temps je suis rendu...
MovieStatus est sensé renvoyer le numéro de la trame en cours d'affichage.
MovieLength est sensé renvoyer la longueur de la vidéo en nombre de trames.
mais Movie Status est > MovieLength 8O

quelqu'un a compris comment ça marche ?
comment transformé MovieStatus en temps et MovieLength en temps et comment transformé un temps pour MovieSeek ?

J'essaye de faire un outil qui permet de prendre des photos a partir de film GoPro. Et de façon que la photo ait la bonne heure de création en fonction de la date de début du film et le temps ecoulé.
Freak a fournit un code pour faire la copie d’écran.
Voici mon code.
Si quelqu'un a une idée,une explication, je suis preneur. Merci

Code : Tout sélectionner

UseJPEGImageEncoder()
;Source : http://www.forums.purebasic.com/english/viewtopic.php?f=12&t=9384&hilit=MovieSeek&sid=35210c834fc99808364128cad84e2228
;coded by Freak
;Updated by dige
;Updated by ozzie
;
; ---------------------------------------------------------------------
;
; 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())
;
; ---------------------------------------------------------------------

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


; ---------------------------------------------------------------------
; Code example:
; ---------------------------------------------------------------------

#Movie = 0
#Image = 0

#Window = 0
Enumeration
#Gadget_Capture
#Gadget_Play
#Gadget_Frame
#Gadget_Pause
EndEnumeration

If InitMovie()
  FileName$ = OpenFileRequester("Choose Movie","","Movie Files|*.mpg;*.avi;*.mpeg|All Files|*.*", 0)
  date.i=GetFileDate(FileName$, #PB_Date_Created)
  If LoadMovie(#Movie, FileName$)
  Debug MovieInfo(#Movie, 0)
    Width = MovieWidth(#Movie)
    Height = MovieHeight(#Movie)
  
    CreateImage(#Image, Width , Height)

    If OpenWindow(#Window, 0, 0, 800 , 600, "Frame Capture", #PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_Invisible)
    
        ButtonGadget(#Gadget_Play, 0, 0, 100, 25, "play")
        ButtonGadget(#Gadget_Pause, 100, 0, 100, 25, "pause")
        StringGadget(#Gadget_Frame, 200,0,100,25,"")
        ButtonGadget(#Gadget_Capture, 300, 0, 100, 25, "Capture")
        ResizeMovie(#Movie,0,50,WindowWidth(#Window) ,Height*WindowWidth(#Window)/Width)
        PlayMovie(#Movie, WindowID(#Window))
        time=ElapsedMilliseconds()
        SmartWindowRefresh(#Window,  #True)
        AddWindowTimer(#Window,0,1000)
        HideWindow(#Window, 0)
        
        Repeat
          Event = WindowEvent()
          If Event = #PB_Event_Timer
            Debug "movie "+Str(MovieStatus(#Movie)/1000)+" "+Str(MovieLength(#Movie))
            Debug "time "+Str(ElapsedMilliseconds()-time)
          EndIf 
          If Event = #PB_Event_Gadget 
            
            Select EventGadget()
              Case #Gadget_Capture
                  resume.b=#False
                  If MovieStatus(#Movie)>0
                  SetGadgetText(#Gadget_Frame,Str(MovieStatus(#Movie)))
                  pos.l=MovieStatus(#Movie)
                  PauseMovie(#Movie)
                  resume.b=#True
                EndIf 
                 If MovieStatus(#Movie)=-1
                   CaptureFrame(#Movie, #Image)
                   newDate=AddDate(date,#PB_Date_Second,pos)
                   name.s=FormatDate("%yyyy-%mm-%dd %hhh%iim%sss",newDate)+" "+GetFilePart(FileName$,#PB_FileSystem_NoExtension)+".jpg"
                   SaveImage(#Image,name,#PB_ImagePlugin_JPEG)
                   SetFileDate(name,#PB_Date_Created,newDate)
                EndIf
                If resume=#True
                  ResumeMovie(#Movie)
                EndIf 
                Case #Gadget_Pause
                  If MovieStatus(#Movie)>0
                   pos.l=MovieStatus(#Movie) ;renvoie la position dans le film en seconde
                  SetGadgetText(#Gadget_Frame,Str(MovieStatus(#Movie)))
                  PauseMovie(#Movie)
                  EndIf 
                Case #Gadget_Play
                  If MovieStatus(#Movie)<=0
                    MovieSeek(#Movie,ValD(GetGadgetText(#Gadget_Frame)))
                    ResumeMovie(#Movie)
                  EndIf 
                Case #Gadget_Frame
                  If MovieStatus(#Movie)<=0
                  MovieSeek(#Movie,ValD(GetGadgetText(#Gadget_Frame)))
                  ResumeMovie(#Movie)
                  PauseMovie(#Movie)
                  EndIf 
                EndSelect
          EndIf
          
          If Event = 0
            Delay(1)
          EndIf
          
        Until event = #PB_Event_CloseWindow

    EndIf        
    
  EndIf
  
EndIf

End
Avatar de l’utilisateur
Ar-S
Messages : 9476
Inscription : dim. 09/oct./2005 16:51
Contact :

Re: MovieStatus > MovieLength Je comprends pas ...

Message par Ar-S »

MovieStatus(#Video) ne renvoie que l'état de ta vidéo si > 0 alors ça t'indique ne nombre de frame ou tu te trouves.
A toi de faire ta conversion en temps si tu le souhaites.

Pour te déplacer dans ton film, tu utilises MovieSeek(#TAVIDEO, NumDeFrame)
il est à executer APRES le lancement du film

Pour ta conversion en temps. J'ai testé et ça a marché.

Si tu as du 24ips,
MovieStatus(#Video)/24 sera logiquement = NbrSecondes

Donc si tu veux déplacer ton film à 10min, tu fais MovieSeek(#TAVIDEO, 600*24)

Code : Tout sélectionner

If InitMovie() = 0
  MessageRequester("Error", "Can't initialize movie playback !", 0) 
  End
EndIf

MovieName$ = OpenFileRequester("Choose the movie to play", "", "Movie files|*.avi;*.mpg|All Files|*.*", 0)
If MovieName$
  If LoadMovie(0, MovieName$)

    OpenWindow(0, 100, 150, MovieWidth(0), MovieHeight(0), "PureBasic - Movie")
    PlayMovie(0, WindowID(0))
    MovieSeek(0,600*24) ; j'avance de 10min
    Debug "Frame de départ : "+ MovieStatus(0)
    Repeat

    Until WaitWindowEvent() = #PB_Event_CloseWindow
    Debug "Frame à la sortie : "+ MovieStatus(0)
  Else
    MessageRequester("Error", "Can't load the movie...", 0)
  EndIf
EndIf 
~~~~Règles du forum ~~~~
⋅.˳˳.⋅ॱ˙˙ॱ⋅.˳Ar-S ˳.⋅ॱ˙˙ॱ⋅.˳˳.⋅
W11x64 PB 6.x
Section HORS SUJET : ICI
LDV MULTIMEDIA : Dépannage informatique & mes Logiciels PB
UPLOAD D'IMAGES : Uploader des images de vos logiciels
Avatar de l’utilisateur
Thyphoon
Messages : 2697
Inscription : mer. 25/août/2004 6:31
Localisation : Eragny
Contact :

Re: MovieStatus > MovieLength Je comprends pas ...

Message par Thyphoon »

Ar-S a écrit : Si tu as du 24ips,
MovieStatus(#Video)/24 sera logiquement = NbrSecondes

Donc si tu veux déplacer ton film à 10min, tu fais MovieSeek(#TAVIDEO, 600*24)
Merci de t'être bien penché sur mon problème :D . Tu me dis bien ce que j'avais compris au départ ... :? ... mais pourquoi avec mon film j'ai des chiffres aussi aberrant ... :cry:
au bout de 992 millisecondes movieStatus=6760209 MovieLength=7825
au bout de 2604 millisecondes movieStatus=22850209 MovieLength=7825
au bout de 2995 millisecondes movieStatus=26760209 MovieLength=7825
au bout de 3994 millisecondes movieStatus=36803751 MovieLength=7825
Or au bout de 4 secondes je devrais être a la trame 4*24 on est d'accord ?
Avatar de l’utilisateur
Ar-S
Messages : 9476
Inscription : dim. 09/oct./2005 16:51
Contact :

Re: MovieStatus > MovieLength Je comprends pas ...

Message par Ar-S »

Tu as déjà un Str(MovieStatus(#Movie)/1000)
Ton /1000 ne serait pas problématique
Ensuite lorsqu'on fait une pause, le statutmovie passe à -1
C'est vrai que c'est con vu qu'il sert aussi à nous orienter dans le film via movieseek()..
je fais des tests..
~~~~Règles du forum ~~~~
⋅.˳˳.⋅ॱ˙˙ॱ⋅.˳Ar-S ˳.⋅ॱ˙˙ॱ⋅.˳˳.⋅
W11x64 PB 6.x
Section HORS SUJET : ICI
LDV MULTIMEDIA : Dépannage informatique & mes Logiciels PB
UPLOAD D'IMAGES : Uploader des images de vos logiciels
Avatar de l’utilisateur
Ar-S
Messages : 9476
Inscription : dim. 09/oct./2005 16:51
Contact :

Re: MovieStatus > MovieLength Je comprends pas ...

Message par Ar-S »

Voilà,
Sans timer, avec un seul bouton Play/Pause, essaye dans ton code en remplaçant ta partie Case #Gadget_Play
un autre soucis venait du fait que tu reprenais la valeur de MovieStatus(#Movie) alors que celle ci passait à -1, du coup ça chamboulait tout.

Code : Tout sélectionner

                           Case #Gadget_Play
                
                  pos.l=MovieStatus(#Movie) ;renvoie la position dans le film en FRAME
                  If MovieStatus(#Movie)=-1;: La vidéo est en pause.
                    Debug "PLAY"
                    SetGadgetText(#Gadget_Play,"Pause")
                    ResumeMovie(#Movie)
                    pos.l=MovieStatus(#Movie) ;renvoie la position dans le film en FRAME
                    Debug "movie "+Str(pos)+"/"+Str(MovieLength(#Movie))
                    Debug "time : "+Str(pos/24) +"s"
                  Else
                    Debug "PAUSE"
                    Debug "movie "+Str(pos)+"/"+Str(MovieLength(#Movie))
                    Debug "time : "+Str(pos/24) +"s"
                    SetGadgetText(#Gadget_Play,"Play")
                    PauseMovie(#Movie)
                    SetGadgetText(#Gadget_Frame,Str(pos))
                    
                  EndIf
~~~~Règles du forum ~~~~
⋅.˳˳.⋅ॱ˙˙ॱ⋅.˳Ar-S ˳.⋅ॱ˙˙ॱ⋅.˳˳.⋅
W11x64 PB 6.x
Section HORS SUJET : ICI
LDV MULTIMEDIA : Dépannage informatique & mes Logiciels PB
UPLOAD D'IMAGES : Uploader des images de vos logiciels
Avatar de l’utilisateur
Thyphoon
Messages : 2697
Inscription : mer. 25/août/2004 6:31
Localisation : Eragny
Contact :

Re: MovieStatus > MovieLength Je comprends pas ...

Message par Thyphoon »

Merci beaucoup ! Mais je m'arrache vraiment les cheveux... toujours le même problème
Crois tu que tu pourrais essayer avec le même film que moi ? Tout mes films sont en MP4 h264 (j'ai du utiliser un pac de codec pour que ce soit lisible avec purebasic)
https://drive.google.com/file/d/0Bxy0hL ... sp=sharing

revoici le code corrigé

Code : Tout sélectionner

UseJPEGImageEncoder()
;Source : http://www.forums.purebasic.com/english/viewtopic.php?f=12&t=9384&hilit=MovieSeek&sid=35210c834fc99808364128cad84e2228
;coded by Freak
;Updated by dige
;Updated by ozzie
;
; ---------------------------------------------------------------------
;
; 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())
;
; ---------------------------------------------------------------------

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


; ---------------------------------------------------------------------
; Code example:
; ---------------------------------------------------------------------

#Movie = 0
#Image = 0

#Window = 0
Enumeration
  #Gadget_Capture
  #Gadget_PlayPause
  #Gadget_Frame
  
EndEnumeration

If InitMovie()
  FileName$ = OpenFileRequester("Choose Movie","","*.*", 0)
  date.i=GetFileDate(FileName$, #PB_Date_Created)
  If LoadMovie(#Movie, FileName$)
    Debug MovieInfo(#Movie, 0)
    Width = MovieWidth(#Movie)
    Height = MovieHeight(#Movie)
    
    CreateImage(#Image, Width , Height)
    
    If OpenWindow(#Window, 0, 0, 800 , 600, "Frame Capture", #PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_Invisible)
      
      ButtonGadget(#Gadget_PlayPause, 0, 0, 100, 25, "Pause")
      StringGadget(#Gadget_Frame, 200,0,100,25,"")
      ButtonGadget(#Gadget_Capture, 300, 0, 100, 25, "Capture")
      ResizeMovie(#Movie,0,50,WindowWidth(#Window) ,Height*WindowWidth(#Window)/Width)
      PlayMovie(#Movie, WindowID(#Window))
      time=ElapsedMilliseconds()
      SmartWindowRefresh(#Window,  #True)
      AddWindowTimer(#Window,0,1000)
      HideWindow(#Window, 0)
      
      Repeat
        Event = WindowEvent()
        If Event = #PB_Event_Timer
         ; Debug "movie "+Str(MovieStatus(#Movie))+" "+Str(MovieLength(#Movie))
         ; Debug "time "+Str(ElapsedMilliseconds()-time)
        EndIf 
        If Event = #PB_Event_Gadget 
          
          Select EventGadget()
            Case #Gadget_Capture
              resume.b=#False
              If MovieStatus(#Movie)>0 ;if film playing
                SetGadgetText(#Gadget_Frame,Str(MovieStatus(#Movie)))
                pos.l=MovieStatus(#Movie)
                PauseMovie(#Movie)
                resume.b=#True
              EndIf 
              If MovieStatus(#Movie)=-1;if film is paused
                CaptureFrame(#Movie, #Image)
                newDate=AddDate(date,#PB_Date_Second,pos)
                name.s=FormatDate("%yyyy-%mm-%dd %hhh%iim%sss",newDate)+" "+GetFilePart(FileName$,#PB_FileSystem_NoExtension)+".jpg"
                SaveImage(#Image,name,#PB_ImagePlugin_JPEG)
                SetFileDate(name,#PB_Date_Created,newDate)
              EndIf
              If resume=#True
                ResumeMovie(#Movie)
              EndIf 
            Case #Gadget_PlayPause
              
              
              Select MovieStatus(#Movie)
                Case -1 ; Video Paused
                  Debug "PLAY"
                  SetGadgetText(#Gadget_PlayPause,"Pause")
                  ResumeMovie(#Movie)
                  pos.l=MovieStatus(#Movie)
                  Debug "movie "+Str(pos)+"/"+Str(MovieLength(#Movie))
                  Debug "time : "+Str(pos/MovieInfo(#Movie,0)/1000) +"sec" ;d'apres la doc MovieInfo Renvoie le nombre de trames par seconde (*1000).
                Case 0 ; Video Stoped
                  PlayMovie(#Movie, WindowID(#Window))
                Default ;Video Playing
                  pos.l=MovieStatus(#Movie) ;renvoie la position dans le film en FRAME
                  Debug "PAUSE"
                  Debug "movie "+Str(pos)+"/"+Str(MovieLength(#Movie))
                  Debug "time : "+Str(pos/MovieInfo(#Movie,0)/1000) +"sec" ;d'apres la doc MovieInfo Renvoie le nombre de trames par seconde (*1000).
                  SetGadgetText(#Gadget_PlayPause,"Play")
                  PauseMovie(#Movie)
                  SetGadgetText(#Gadget_Frame,Str(pos))
              EndSelect
            Case #Gadget_Frame
              If MovieStatus(#Movie)<=0
                MovieSeek(#Movie,ValD(GetGadgetText(#Gadget_Frame)))
                ResumeMovie(#Movie)
                PauseMovie(#Movie)
              EndIf 
          EndSelect
        EndIf
        
        If Event = 0
          Delay(1)
        EndIf
        
      Until event = #PB_Event_CloseWindow
      
    EndIf        
    
  EndIf
  
EndIf

End
moi j'ai ça dans le debuger des que je met en pause
24
PAUSE
movie 51102709/5400
time : 2129s
EDIT: j'ai découvert un truc MovieStatus(#Movie)/10000000 = le temps en seconde ... mais pourquoi 10000000 est pareille pour toute les vidéo ???? ou bien est ce du a un debit de la vidéo ou a autre je sais pas pour l'instant ...
Avatar de l’utilisateur
Ar-S
Messages : 9476
Inscription : dim. 09/oct./2005 16:51
Contact :

Re: MovieStatus > MovieLength Je comprends pas ...

Message par Ar-S »

Ne voulant pas mettre de codec sur mon portable (taf je suis en formation 2j), J'ai testé avec mon code en convertissant ta vidéo en avi.
Déjà elle est en 25fps pour info (la tienne aussi), je pense que l'encodage mp4 est peut-être problématique car comme tu vas le voir je n'ai pas de soucis.

J'ai ajouté une constante #FPS = 25 en début de code, c'est plus pratique pour le reste.

- Tu lances le films
- Tu fais pause
- Tu fais play, il repart bien à 16s comme demandé.

Code : Tout sélectionner

UseJPEGImageEncoder()
;Source : http://www.forums.purebasic.com/english/viewtopic.php?f=12&t=9384&hilit=MovieSeek&sid=35210c834fc99808364128cad84e2228
;coded by Freak
;Updated by dige
;Updated by ozzie
;Modifié par Ar-S 
; ---------------------------------------------------------------------
;
; 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())
;
; ---------------------------------------------------------------------

#FPS = 25

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


; ---------------------------------------------------------------------
; Code example:
; ---------------------------------------------------------------------

#Movie = 0
#Image = 0

#Window = 0
Enumeration
#Gadget_Capture
#Gadget_Play
#Gadget_Frame
#Gadget_Pause
EndEnumeration

If InitMovie()
  FileName$ = OpenFileRequester("Choose Movie","","Movie Files|*.mpg;*.avi;*.mpeg|All Files|*.*", 0)
  date.i=GetFileDate(FileName$, #PB_Date_Created)
  If LoadMovie(#Movie, FileName$)
  
    Width = MovieWidth(#Movie)
    Height = MovieHeight(#Movie)
 
    CreateImage(#Image, Width , Height)

    If OpenWindow(#Window, 0, 0, 800 , 600, "Frame Capture", #PB_Window_SystemMenu|#PB_Window_ScreenCentered|#PB_Window_Invisible)
   
      ButtonGadget(#Gadget_Play, 0, 0, 100, 25, "Pause")
      
        StringGadget(#Gadget_Frame, 200,0,100,25,"")
        ButtonGadget(#Gadget_Capture, 300, 0, 100, 25, "Capture")
        ResizeMovie(#Movie,0,50,WindowWidth(#Window) ,Height*WindowWidth(#Window)/Width)
        PlayMovie(#Movie, WindowID(#Window))
        Debug "/// test THYPHOON ///"
        Debug "durée en sec : " + Str(MovieStatus(#Movie)/10000000) + " : NON"
        Debug "MovieInfo(#Movie, 0) renvoie " + MovieInfo(#Movie, 0) + " c'est nimp"
        Debug " /// Fin Test ///"
        SmartWindowRefresh(#Window,  #True)
        HideWindow(#Window, 0)
       
        Repeat
          Event = WindowEvent()

          If Event = #PB_Event_Gadget
           
            Select EventGadget()
              Case #Gadget_Capture
                  resume.b=#False
                  If MovieStatus(#Movie)>0
                  SetGadgetText(#Gadget_Frame,Str(MovieStatus(#Movie)))
                  pos.l=MovieStatus(#Movie)
                  PauseMovie(#Movie)
                  resume.b=#True
                EndIf
                 If MovieStatus(#Movie)=-1
                   CaptureFrame(#Movie, #Image)
                   newDate=AddDate(date,#PB_Date_Second,pos)
                   name.s=FormatDate("%yyyy-%mm-%dd %hhh%iim%sss",newDate)+" "+GetFilePart(FileName$,#PB_FileSystem_NoExtension)+".jpg"
                   SaveImage(#Image,name,#PB_ImagePlugin_JPEG)
                   SetFileDate(name,#PB_Date_Created,newDate)
                EndIf
                If resume=#True
                  ResumeMovie(#Movie)

                EndIf
                
              Case #Gadget_Play
                
                  
                  pos.l=MovieStatus(#Movie) ;renvoie la position dans le film en FRAME
                  If MovieStatus(#Movie)=-1;: La vidéo est en pause.
                    Debug "PLAY à 16sec"
                    MovieSeek(#Movie,16*#FPS)
                    SetGadgetText(#Gadget_Play,"Pause")
                    ResumeMovie(#Movie)
                    pos.l=MovieStatus(#Movie) ;renvoie la position dans le film en FRAME
                    Debug "movie "+Str(pos)+"/"+Str(MovieLength(#Movie))
                    Debug "time : "+Str(pos/#FPS) +"s"
                  Else
                    Debug "PAUSE"
                    Debug "movie "+Str(pos)+"/"+Str(MovieLength(#Movie))
                    Debug "time : "+Str(pos/#FPS) +"s"
                    SetGadgetText(#Gadget_Play,"Play")
                    PauseMovie(#Movie)
                    SetGadgetText(#Gadget_Frame,Str(pos))
                    
                  EndIf
                  
                  
                  
                  
                
                Case #Gadget_Frame
;                   If MovieStatus(#Movie)<=0
;                   MovieSeek(#Movie,ValD(GetGadgetText(#Gadget_Frame)))
;                   ResumeMovie(#Movie)
;                   PauseMovie(#Movie)
;                   EndIf
                EndSelect
          EndIf
         

         
        Until event = #PB_Event_CloseWindow

    EndIf       
   
  EndIf
 
EndIf

End
J'ai cependant testé les commandes selon tes dires précédents, ça ne fonctionne pas du tout

Code : Tout sélectionner

        Debug "/// test THYPHOON ///"
        Debug "durée en sec : " + Str(MovieStatus(#Movie)/10000000) + " : NON"
        Debug "MovieInfo(#Movie, 0) renvoie " + MovieInfo(#Movie, 0) + " c'est nimp"
        Debug " /// Fin Test ///"
~~~~Règles du forum ~~~~
⋅.˳˳.⋅ॱ˙˙ॱ⋅.˳Ar-S ˳.⋅ॱ˙˙ॱ⋅.˳˳.⋅
W11x64 PB 6.x
Section HORS SUJET : ICI
LDV MULTIMEDIA : Dépannage informatique & mes Logiciels PB
UPLOAD D'IMAGES : Uploader des images de vos logiciels
Avatar de l’utilisateur
Thyphoon
Messages : 2697
Inscription : mer. 25/août/2004 6:31
Localisation : Eragny
Contact :

Re: MovieStatus > MovieLength Je comprends pas ...

Message par Thyphoon »

Merci beaucoup pour le temps que tu passes... il semble qu'en fonction du codec purebasic ne renvoie pas la même chose. :(
est ce un bug de purebasic ? avec ton code moi mes vidéos repartent depuis le debut voilà ce que donne le debugger
/// test THYPHOON ///
durée en sec : 0 : NON
MovieInfo(#Movie, 0) renvoie 24 c'est nimp
/// Fin Test ///
PAUSE
movie 16193126/2525
time : 647725s
PLAY à 16sec
movie 400/2525
time : 16s
PAUSE
movie 14652709/2525
time : 586108s
PLAY à 16sec
movie 400/2525
time : 16s
PAUSE
movie 12568959/2525
time : 502758s
chez moi la durée en seconde d'une vidéo=MovieLenght(#Movie)/MovieInfo(#Movie,0)
mais MovieStatus() renvoie n'importe quoi en fonction des vidéos sur mes videos de GoPro je te confirme que
si je fais MovieStatus()/10000000 j'obtient le temps ecoulé en seconde depuis le debut de la vidéo
le but est de faire un outil qui puisse prendre une vidéo sans trop se poser de question.
Répondre