Page 1 of 2

AVIServ.dll - Read/Write AVI

Posted: Thu Oct 09, 2003 11:47 am
by dige
Dll/Inlcude for easy read, edit, write avi 16/24Bit videos. (no sound support)

You can download the Dll and the source (developed with PB 4.10)
at: http://www.sunset-team.de/Download/AVIServ.zip [18 kB]

Please remind, the dll is still in beta status and unchanged since 2007...

Code: Select all

; How to use it
; 2 examples AVI2BMP, BMP2AVI

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

Enumeration
  #Lib
EndEnumeration

UseJPEGImageDecoder()

Procedure AVI2BMP ()
  file.s = OpenFileRequester( "Open AVI", "D:\Database\Sources\ST_Soft\AVI\", "AVI Video|*.avi", 0 )
  *INF.AVI_INFO = CallFunction( #Lib, "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" )
      Else
        MessageRequester( "FrameGet error", "DIB class can only handle unpalletized memory DIBs - RGB 16 or 24bit color",  #MB_ICONEXCLAMATION | #MB_OK )
        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, #PB_Window_SystemMenu | #PB_Window_ScreenCentered, "Images 2 AVI" )
  If INF\hWnd And CreateGadgetList( INF\hWnd )
    ListViewGadget( 0, 0, 0, 300, 200 )
  
    file.s = SaveFileRequester( "Save AVI", "", "AVI Video|*.avi", 0 )
    dir.s = PathRequester( "Select images directory", GetPathPart( file.s ))
    
    If ExamineDirectory( 0, dir.s, "*.*" )
      Repeat 
        Res = NextDirectoryEntry()
        If Res = 1
          img.s = DirectoryEntryName()
          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()
                INF\aviHeight = ImageHeight()
                INF\aviFPS    = 1 ; Play 1 Frame per Second
                SetForegroundWindow_( INF\hWnd )
                If CallFunction( #Lib, "OpenAVIforWrite", file.s, @INF ) = #False : Res = 0 : EndIf
              EndIf
              
              If INF\aviWidth + INF\aviHeight <> ImageWidth() + ImageHeight()
                hBmp = ResizeImage( 0, INF\aviWidth, INF\aviHeight )
              EndIf
              
              If INF\aviWidth            
                StartDrawing( ImageOutput() )
                  ; Make some image effects ...
                  DrawingMode( 1|2 ) 
                  Locate (1, 1) : DrawText( "PureBasic RuLeS! :-)" )
                  Locate (INF\aviWidth - TextLength( img ) - 10, INF\aviHeight - 20 ) : DrawText( img )
                StopDrawing()
                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_EventCloseWindow
    EndIf
  EndIf
EndProcedure

  If OpenLibrary( #Lib, "AVIServ.dll" )
    If CallFunction( #Lib, "AVI_Init" )
      
      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 AVIServ.dll", 0)
  EndIf
  
End
Have fun!

cya dige

Posted: Thu Oct 09, 2003 11:35 pm
by TronDoc
I only did one little test and got errors..
..maybe it will help you to see the results.
included is the original .avi and the output .bmps
along with the error messages from windoze

http://trondoc.ezwebtech.com/prgrmng/d3/EASYAVI.zip

it looks like the output .bmps are 24 bit.
I think they were originally 8 bit pictures.
maybe this matters?

Joe

Posted: Fri Oct 10, 2003 5:30 am
by dige
TronDoc wrote:it looks like the output .bmps are 24 bit.
I think they were originally 8 bit pictures.
maybe this matters?
Yes, it seems to be a problem with less 16Bit colors. I'll try to fix it...
Thank you for reporting this.

cya dige

Posted: Fri Oct 10, 2003 7:16 am
by dige
I could fix the crash error and upload version 0.91B2
But DIB class can only handle unpalletized memory DIBs - RGB 16 or
24bit color... thus ... unfortunately, AVIServ will not support 8 bits avi
streams ... sorry.

cya dige

Posted: Fri Oct 10, 2003 12:29 pm
by TronDoc
dige wrote:unfortunately, AVIServ will not support 8 bits avi
streams ... sorry...
no problem.. ..as long as people know
that, they'll stil be able to use it :D Joe

Cool!

Posted: Sun Nov 02, 2003 6:05 pm
by Hi-Toro
I only just found this from the link in 'Off Topic', but this is excellent! Wanted something like this for ages. Thanks, Dige!

Posted: Tue Nov 04, 2003 8:08 pm
by J. Baker
I was able to do the AVI2BMP but not BMP2AVI under WIN XP. I'll wait for the next release and test it then. Nice work! :D

Works here...

Posted: Tue Nov 04, 2003 9:19 pm
by Hi-Toro
It works on XP here. I did think it failed at first, but it turned out I missed the requester asking me for the images directory... try again and see if finding that works!

Posted: Sun Nov 16, 2003 12:18 am
by blueznl
ok works, was this written in purebasic or in something else?
will source become available?

Posted: Mon Nov 24, 2003 9:50 am
by dige
Yes, it was written with purebasic. In the next few days, I will publish some parts of the source in the Tricks 'n' Tips section.

cya dige

Posted: Sat Nov 29, 2003 7:21 pm
by Hi-Toro
In the next few days, I will publish some parts of the source in the Tricks 'n' Tips section
Cool, looking forward to it!

Posted: Sat Nov 29, 2003 9:48 pm
by blueznl
me too

Posted: Sun Mar 07, 2004 7:25 pm
by dagcrack
That message is horrible :cry:

Posted: Tue Mar 09, 2004 4:26 am
by TIGER
Finaly i ve found what i was looking for.

What i wanted to do its create my own video format.

2 programs.
One compressor

and the second its a DLL
which you can integrate with any type of programm
to play your video.

Supports sound 8)

Posted: Thu Mar 11, 2004 8:12 am
by dagcrack
Nice Tiger!.

About this dll... it has a message when it loads.. that's the bad thing :( ( I think cause its the unlicensed - free - version.. nope?)