bmp2avi

Vous débutez et vous avez besoin d'aide ? N'hésitez pas à poser vos questions
Mesa
Messages : 1126
Inscription : mer. 14/sept./2011 16:59

bmp2avi

Message par Mesa »

J'ai trouvé ce code dans le forum mais la video avi sans compression et sans son (wav) que je fabrique avec des bmp a des couleurs inversée entre autre choses.

ça fait pareil chez vous ?

Code : Tout sélectionner

;/ Nico le 02/06/05
;/ Création d'un avi avec de l'audio

#streamtypeAUDIO = $73647561
#streamtypeVIDEO = $73646976
#ICMF_CHOOSE_KEYFRAME=1
#ICMF_CHOOSE_DATARATE=2
#AVIERR_OK=0
#AVIIF_KEYFRAME=$10
#Lib = 0

Structure bitmap24
  bmiHeader.BITMAPINFOHEADER
EndStructure

Structure msvc
  a.b
  b.b
  c.b
  d.b
EndStructure

Structure AVISTREAMINFO
  fccType.l
  fccHandler.msvc
  dwFlags.l
  dwCaps.l
  wPriority.w
  wLanguage.w
  dwScale.l
  dwRate.l
  dwStart.l
  dwLength.l
  dwInitialFrames.l
  dwSuggestedBufferSize.l
  dwQuality.l
  dwSampleSize.l
  rcFrame.RECT 
  dwEditCount.l
  dwFormatChangeCount.l
  szName.b[64]
EndStructure

Structure AVICOMPRESSOPTIONS
  fccType.l
  fccHandler.l
  dwKeyFrameEvery.l
  dwQuality.l
  dwBytesPerSecond.l
  dwFlags.l
  *lpFormat.l
  cbFormat.l
  *lpParms.l
  cbParms.l
  dwInterleaveEvery.l
EndStructure

; Structure WAVEFORMATEX
;   wFormatTag.w
;   nChannels.w
;   nSamplesPerSec.l
;   nAvgBytesPerSec.l
;   nBlockAlign.w
;   wBitsPerSample.w
;   cbSize.w
; EndStructure

NewList bitmap.s()
NewList memoire.l()


;/ Procédure traduite en Pure Basic
;/ d'un code écrit en c++ par son auteur Chiew Heng Wah.

Procedure AddWAV(strFileWAV.s, pfile.l)
  pfileWav.IAVIFILE
  siWav.AVISTREAMINFO
  psWav.IAVISTREAM 
  psAvi.l
  fmtWav.WAVEFORMATEX
  If CallFunction( #Lib, "AVIFileOpen",@pfileWav, @strFileWAV, #OF_READ, #Null)=0
    If CallFunction( #Lib, "AVIFileGetStream",pfileWav, @psWav, #streamtypeAUDIO, 0)=0
      If CallFunction( #Lib, "AVIStreamInfo",psWav, @siWav, SizeOf(AVISTREAMINFO))=0
        If CallFunction( #Lib, "AVIStreamReadFormat",psWav, 0, #Null, @lFmtSize) =0
          If lFmtSize
            If  CallFunction( #Lib, "AVIStreamReadFormat",psWav, 0, @fmtWav, @lFmtSize)=0
              lStreamLength = CallFunction( #Lib, "AVIStreamLength",psWav)
              If lStreamLength
                lpbData = AllocateMemory(lStreamLength)
                If CallFunction( #Lib, "AVIStreamRead",psWav, 0, lStreamLength, lpbData, lStreamLength, #Null, #Null)=0
                  If CallFunction( #Lib, "AVIFileCreateStream",pfile, @psAvi, @siWav)=0
                    If CallFunction( #Lib, "AVIStreamSetFormat",psAvi, 0, @fmtWav, lFmtSize)=0
                      If CallFunction( #Lib, "AVIStreamWrite",psAvi, 0, lStreamLength, lpbData, lStreamLength, #AVIIF_KEYFRAME, #Null, #Null)=0
                        val.b=1
                      EndIf
                    EndIf
                    CallFunction( #Lib, "AVIStreamRelease",psAvi)
                  EndIf
                EndIf
                FreeMemory(lpbData)
              EndIf
            EndIf
          EndIf
        EndIf
      EndIf   
      CallFunction( #Lib, "AVIStreamRelease",psWav)
    EndIf
    CallFunction( #Lib, "AVIFileRelease",pfileWav)
  EndIf
  ProcedureReturn val
EndProcedure 

Fichier.s = OpenFileRequester("Sélection multiple des Fichiers Bitmaps", "", "Fichiers BMP|*.bmp", 0, #PB_Requester_MultiSelection)
If Fichier
  Debug  Fichier
  AddElement(bitmap())
  bitmap()= Fichier
  Repeat
    Fichier = NextSelectedFileName()
    If Fichier
      AddElement(bitmap())
      bitmap()= Fichier
      Debug Fichier
    EndIf
  Until Fichier = ""
EndIf

ForEach bitmap()
  If ReadFile(0, bitmap())
    FileSeek(0,SizeOf(BITMAPFILEHEADER))
    bmi.bitmap24
    ReadData(0,@bmi, SizeOf(bitmap24))
    If  bmi\bmiHeader\biWidth
      If  bmi\bmiHeader\biHeight
        If  bmi\bmiHeader\biBitCount
          If  bmi\bmiHeader\bisizeimage=0
            bmi\bmiHeader\bisizeimage=Lof(0)-54
          EndIf
            FileSeek(0,1078)
            AddElement(memoire())
            memoire() =GlobalAlloc_(#GMEM_FIXED|#GMEM_ZEROINIT, bmi\bmiHeader\bisizeimage)
            ReadData(0,memoire(), bmi\bmiHeader\bisizeimage)
        EndIf
      EndIf
    EndIf
    CloseFile(0)
  EndIf
Next
 
If OpenLibrary  ( #Lib , "AVIFIL32.DLL")
  CallFunction ( #Lib,  "AVIFileInit" )
  avifile.s = SaveFileRequester ( "Nom du fichier Avi à enregistrer", "", "Video|*.avi", 0 )
  If GetExtensionPart(avifile)=""
    avifile=avifile+".avi"
  EndIf
  Debug avifile
 
  If CallFunction( #Lib, "AVIFileOpen", @pAVIFile.IAVIFILE, @avifile, (#OF_WRITE | #OF_CREATE), 0 )=0
    strhdr.AVISTREAMINFO
    strhdr\fccType                = #streamtypeVIDEO
    strhdr\fccHandler\a             = $6D
    strhdr\fccHandler\b             = $73
    strhdr\fccHandler\c             = $76
    strhdr\fccHandler\d             = $63 
    strhdr\dwScale                = 1 ;Nb de frames/secondes
    strhdr\dwRate                 = 4 ;( 1 à 30)
    strhdr\dwSuggestedBufferSize  = bmi\bmiHeader\biSize
   
    If SetRect_(@strhdr\rcFrame, 0, 0, bmi\bmiHeader\biWidth, bmi\bmiHeader\biHeight) <>0
      If CallFunction( #Lib, "AVIFileCreateStream", pAVIFile, @pAVIStream, @strhdr) =0
        opts.AVICOMPRESSOPTIONS
        Dim aopts(0)
        aopts(0)=@opts
       
        If CallFunction( #Lib, "AVISaveOptions", 0, #ICMF_CHOOSE_KEYFRAME | #ICMF_CHOOSE_DATARATE, 1, @pAVIStream, @aopts(0)) =1
          If CallFunction( #Lib, "AVIMakeCompressedStream", @pAVICompressed, pAVIStream, aopts(0), 0)=#AVIERR_OK
            If CallFunction( #Lib, "AVIStreamSetFormat", pAVICompressed, 0, @bmi, SizeOf(bitmap24)) =0
              ForEach memoire()
                If memoire()
                  If CallFunction( #Lib, "AVIStreamWrite", pAVICompressed, index, 1,  memoire() , bmi\bmiHeader\bisizeimage, #AVIIF_KEYFRAME, 0,0) =0
                    index=index+1
                  EndIf 
                EndIf
              Next
        EndIf
        CallFunction( #Lib, "AVIStreamRelease", pAVICompressed)
      EndIf
      EndIf
      CallFunction( #Lib, "AVIStreamRelease", pAVIStream )
    EndIf
    ;------------------------ Inclure le son -----------------------------------------   
   

    strFileWAV2.s = OpenFileRequester("Sélection d'un Fichier Audio", "", "Fichiers Wav|*.wav", 0)
   
    If AddWAV(strFileWAV2, pAVIFile)
      a$="Le fichier avi créé contient un fichier audio."
    Else
      a$="Le fichier audio n'a pu être créé."
    EndIf
   
    ;----------------------------------------
      EndIf
    CallFunction( #Lib, "AVIFileRelease", pAVIFile)
  EndIf
  CallFunction( #Lib, "AVIFileExit" )
  CloseLibrary( #Lib )
 
  ForEach memoire()
    GlobalFree_(memoire())
  Next
  MessageRequester("Info","Nombre de Frames enregistrées: "+Str(index)+Chr(13)+a$)
EndIf
Avatar de l’utilisateur
Ar-S
Messages : 9539
Inscription : dim. 09/oct./2005 16:51
Contact :

Re: bmp2avi

Message par Ar-S »

Pareil, l'image est ignoble.
~~~~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
graph100
Messages : 1318
Inscription : sam. 21/mai/2005 17:50

Re: bmp2avi

Message par graph100 »

chez moi ca décale tout en biais et les couleur sont découpées par bandes.
ca doit venir d'une mauvaise taille des données bitmap, et du format RGB BGR ou BRG
_________________________________________________
Mon site : CeriseCode (Attention Chantier perpétuel ;))
Mesa
Messages : 1126
Inscription : mer. 14/sept./2011 16:59

Re: bmp2avi

Message par Mesa »

J'ai déterré un code que j'ai réussi à faire fonctionner avec PB4.61.

Il permet de faire du bmp2avi et du avi2bmp.
Une modif mineur permettrait de faire du avi2jpeg ou avi2png.

Il a besoin d'une dll tierce que l'on trouve ici
http://www.sunset-team.de/Download/AVIServ.zip
(Le lien fonctionnait encore aujourd'hui.)

Plus d'explication dans le code source.

Code : Tout sélectionner

; www.purearea.net (Sourcecode collection by cnesm)
; Author: dige (updated for PB4.00 by blbltheworm)
; Date: 22. November 2003
; OS: Windows
; Demo: No

Structure AVI_INFO
  aviWidth.l
  aviHeight.l
  aviFirstFrame.l
  aviNumFrames.l
  aviFPS.b
  hWnd.l
EndStructure

Enumeration
  #Lib
EndEnumeration

UseJPEGImageDecoder()

Global FPS=25; Images par seconde : de 1 à ?=======================

Prototype.l ProtoOpenAVIforRead(file$)
Prototype.l ProtoOpenAVIforWrite(file$, ok.l )
Prototype.l ProtoAddFrameToAVI(hBmp2.l, ok2.l)

Procedure AVI2BMP ()
  file.s = OpenFileRequester( "Open AVI", "", "AVI Video|*.avi", 0 )
  
  OpenAVIforRead.ProtoOpenAVIforRead=GetFunction(#Lib, "OpenAVIforRead")
  *INF.AVI_INFO = OpenAVIforRead(file.s)
  If *INF
    MessageRequester( "AVI Stream Info", "Size: " + Str(*INF\aviWidth) + "x" + Str(*INF\aviHeight) + Chr(13) + "Frames: " + Str(*INF\aviNumFrames), 0 )
    hBmp = CreateImage ( 0, *INF\aviWidth, *INF\aviHeight )
    
    For a = *INF\aviFirstFrame To *INF\aviNumFrames - *INF\aviFirstFrame - 1
      If CallFunction( #Lib, "GetFrameFromAVI", hBmp, a )
        SaveImage(0, "Sequence_" + Right("000" + Str(a), 4 ) + ".bmp" )
        ;Dans le même dossier que le .pb ou l'exe====================
      Else
        a = *INF\aviNumFrames + 1
      EndIf
    Next
    
    CallFunction( #Lib, "CloseAVIStreams" )
    MessageRequester( "Done", "AVI splitted to bitmaps", 0 )
  Else
    MessageRequester( "Error", "Could not open avi", 0)
  EndIf
EndProcedure
Procedure BMP2AVI ()
  INF.AVI_INFO
  INF\hWnd = OpenWindow(0, 0, 0, 300, 200, "Images 2 AVI" , #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
  If INF\hWnd; And CreateGadgetList( INF\hWnd )
    ListViewGadget( 0, 0, 0, 300, 200 )
    
    file.s = SaveFileRequester( "Save AVI", "", "AVI Video|*.avi", 0 )
    If GetExtensionPart(file) <> "avi"
      file = file +".avi"
    EndIf
    
    
    dir.s = PathRequester( "Select images directory", GetPathPart( file.s ))
    
    If ExamineDirectory( 0, dir.s, "*.*" )
      Repeat
        Res = NextDirectoryEntry( 0)
        If Res = 1
          img.s = DirectoryEntryName( 0)
          ext.s = UCase(GetExtensionPart(img.s))
          
          If ext = "BMP" Or ext = "JPG" Or ext = "JPEG"
            
            hBmp = LoadImage(0, dir + img )
            If hBmp
              If INF\aviWidth <= 0:
                INF\aviWidth  = ImageWidth(0)
                INF\aviHeight = ImageHeight(0)
                INF\aviFPS    = FPS ; Play 25 Frame per Second===========
                ;                 INF\aviFirstFrame =0
                ;                 INF\aviNumFrames =50
                SetForegroundWindow_( INF\hWnd )
                OpenAVIforWrite.ProtoOpenAVIforWrite=GetFunction(#Lib, "OpenAVIforWrite")
                Debug "Si vous choisissez |Trames complètes (non compréssées)| vous aurez une video carrée."
                Debug "Essayer divers compresseurs, |Cinepack Codec by Radius| par exemple mais ils ne fonctionnent pas tous."
                Debug "Le mieux est d'installer |ffdshow| (ou K-Lite http://www.codecguide.com/download_kl.htm)."
                Debug "Avec ffdshow, vous pouvez corriger le contraste, luminosité, etc."
                Debug "ffdshow + mjpeg + qualité 100% donne un excellent résultat."
                If OpenAVIforWrite(file.s, @INF ) = #False : Res = 0 : EndIf
                ;If CallFunction( #Lib, "OpenAVIforWrite", file.s, @INF ) = #False : Res = 0 : EndIf
              EndIf
              
              If INF\aviWidth + INF\aviHeight <> ImageWidth(0) + ImageHeight(0)
                hBmp = ResizeImage( 0, INF\aviWidth, INF\aviHeight )
              EndIf
              
              If INF\aviWidth
                ;TAG DES IMAGES ICI====================================
                ;                 StartDrawing( ImageOutput( 0) )
                ;                 ; Make some image effects ...
                ;                 DrawingMode( 1|2 )
                ;                 DrawText(1, 1, "PureBasic RuLeS! :-)" )
                ;                 DrawText(INF\aviWidth - TextWidth( img ) - 10, INF\aviHeight - 20 , img )
                ;                 StopDrawing()
                
                AddFrameToAVI.ProtoAddFrameToAVI=GetFunction(#Lib, "AddFrameToAVI")
                If AddFrameToAVI( hBmp, -1 ) = #True
                  ;If CallFunction( #Lib, "AddFrameToAVI", hBmp, -1 ) = #True ; -1 Autoincrement FrameNr
                  Frames + 1
                EndIf
              EndIf
            Else
              img + " failed"
            EndIf
            AddGadgetItem( 0, -1, img )
          EndIf
        EndIf
      Until Res = 0
      AddGadgetItem(0, -1, "Done. " + Str(Frames) + " Images." )
      CallFunction( #Lib, "CloseAVIStreams" )
      Repeat : Until WaitWindowEvent() = #PB_Event_CloseWindow
    EndIf
  EndIf
EndProcedure

If OpenLibrary( #Lib, "AVIServ093.dll" )
  ;If OpenLibrary( #Lib, "AVIServ093UC.dll" )
  If CallFunction( #Lib, "AVI_Init" )
    
    ;CHOIX ICI============================================
    ;AVI2BMP() ; Splitt AVI video into singel frames
    BMP2AVI() ; Create AVI and add *jpg, *bmp images
    
    CallFunction( #Lib, "AVI_Quit" )
  EndIf
  CloseLibrary( #Lib )
Else
  MessageRequester( "Error", "Could not open AVIServ93.dll", 0)
EndIf

End


; Die Dll kann unter http://www.sunset-team.de/Download/AVIServ.zip
; heruntergeladen werden [11 kB]
;
; Nachfolgend 2 mögliche Anwendungsbeispiele:
; AVI2BMP : Konvertiert eine AVI Datei in Einzelbilder
; BMP2AVI : Erstellt ein AVI Video aus JPG, BMP Bildern eines Verzeichnises


; IDE Options = PureBasic v4.00 (Windows - x86)
; Folding = -
Mesa.
IdeasVacuum
Messages : 3
Inscription : dim. 21/oct./2012 1:56

Re: bmp2avi

Message par IdeasVacuum »

À l'aide de fichiers bmp simple

à

If AddFrameToAVI(hBmp, -1) = #True

Je me fais: [ERROR] Invalid memory access. (read error at address 0)

Edit: A échoué parce que j'ai eu le compilateur la valeur Unicode

OpenAVIforWrite échoue si "AVIServ093UC.dll" est ouvert (et compilateur la valeur Unicode)

Non Unicode avec "AVIServ093.dll" fonctionne très bien (BMP2AVI)
IdeasVacuum
Messages : 3
Inscription : dim. 21/oct./2012 1:56

Re: bmp2avi

Message par IdeasVacuum »

AVI2BMP()
Ne parvient pas à :
If CallFunction (#Lib, "GetFrameFromAVI", hBmp, a)
Lorsque vous essayez de fractionner un AVI fait précédemment avec BMP2AVI()
IdeasVacuum
Messages : 3
Inscription : dim. 21/oct./2012 1:56

Re: bmp2avi

Message par IdeasVacuum »

"OpenAVIforWrite()" affiche une petite fenêtre pour l'utilisateur à sélectionner un codec.

Est-il possible à la place d'ajouter le nom de codec pour la structure AVI_INFO ?

Je voudrais par défaut vers le codec Microsoft vidéo 1 qui est le meilleur choix pour mon application.

D'autres raisons :
1) Certains des codecs disponibles ou ne fonctionnent pas ou les résultats ne sont pas bonnes;
2) Beaucoup d'utilisateurs ne sauront pas quel codec choisir.
Répondre