AVIServ.dll - Read/Write AVI

Developed or developing a new product in PureBasic? Tell the world about it.
dige
Addict
Addict
Posts: 1391
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

AVIServ.dll - Read/Write AVI

Post 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
Last edited by dige on Mon Oct 22, 2012 8:54 am, edited 2 times in total.
TronDoc
Enthusiast
Enthusiast
Posts: 310
Joined: Wed Apr 30, 2003 3:50 am
Location: 3DoorsDown

Post 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
peace
[pI 166Mhz 32Mb w95]
[pII 350Mhz 256Mb atir3RagePro WinDoze '98 FE & 2k]
[Athlon 1.3Ghz 160Mb XPHome & RedHat9]
dige
Addict
Addict
Posts: 1391
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Post 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
dige
Addict
Addict
Posts: 1391
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Post 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
TronDoc
Enthusiast
Enthusiast
Posts: 310
Joined: Wed Apr 30, 2003 3:50 am
Location: 3DoorsDown

Post 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
peace
[pI 166Mhz 32Mb w95]
[pII 350Mhz 256Mb atir3RagePro WinDoze '98 FE & 2k]
[Athlon 1.3Ghz 160Mb XPHome & RedHat9]
Hi-Toro
Enthusiast
Enthusiast
Posts: 269
Joined: Sat Apr 26, 2003 3:23 pm

Cool!

Post 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!
James Boyd
http://www.hi-toro.com/
Death to the Pixies!
User avatar
J. Baker
Addict
Addict
Posts: 2181
Joined: Sun Apr 27, 2003 8:12 am
Location: USA
Contact:

Post 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
Hi-Toro
Enthusiast
Enthusiast
Posts: 269
Joined: Sat Apr 26, 2003 3:23 pm

Works here...

Post 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!
James Boyd
http://www.hi-toro.com/
Death to the Pixies!
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

ok works, was this written in purebasic or in something else?
will source become available?
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
dige
Addict
Addict
Posts: 1391
Joined: Wed Apr 30, 2003 8:15 am
Location: Germany
Contact:

Post 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
Hi-Toro
Enthusiast
Enthusiast
Posts: 269
Joined: Sat Apr 26, 2003 3:23 pm

Post 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!
James Boyd
http://www.hi-toro.com/
Death to the Pixies!
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6166
Joined: Sat May 17, 2003 11:31 am
Contact:

Post by blueznl »

me too
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
dagcrack
Addict
Addict
Posts: 1868
Joined: Sun Mar 07, 2004 8:47 am
Location: Argentina
Contact:

Post by dagcrack »

That message is horrible :cry:
TIGER
User
User
Posts: 81
Joined: Mon Feb 23, 2004 8:33 pm

Post 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)
PIII450 128RAM TNT2
dagcrack
Addict
Addict
Posts: 1868
Joined: Sun Mar 07, 2004 8:47 am
Location: Argentina
Contact:

Post 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?)
Post Reply