Konverter der Bilder zu einem Video umwandelt

  • VB.NET

Es gibt 13 Antworten in diesem Thema. Der letzte Beitrag () ist von StarGate01.

    Gibt's auch Code?

    Nö.
    "Life isn't about winning the race. Life is about finishing the race and how many people we can help finish the race." ~Marc Mero

    Nun bin ich also auch soweit: Keine VB-Fragen per PM! Es gibt hier ein Forum, verdammt!
    Natürlich geht das ohne dll. Entweder du liest dir ewig lange Formatspezifikationen durch haust dich auf lowlevel Ebene durch was bei AVI recht müßselig werden dürfte oder du verwendest WinAPI oder eventuell sogar ComInterfaces von Windows um dir selbst die Funktionalität zu erstellen die du brauchst. Such mal hier nen bisschen rum: msdn.microsoft.com/de-de/libra…op/dd756860(v=vs.85).aspx
    Das ist eine von mehreren API's.
    Jedoch wird auch das deine Kompetenz bei weitem übersteigen und somit Dll oder lass es. Es geht nunmal nicht immer alles so einfach. Gerade Multimedia ist oft sehr kompliziert.

    Ach ja ich würde mich an deiner Stelle mal an den Google Support wenden. Irgendwas scheint bei dir kaput zu sein:
    google.at/search?q=vb.net+crea…&sourceid=chrome&ie=UTF-8

    google.at/search?q=c%23+create…&sourceid=chrome&ie=UTF-8


    Opensource Audio-Bibliothek auf github: KLICK, im Showroom oder auf NuGet.
    Ich hatte mich mal damit auseinandergesetzt.
    Der folgende Code stammt nicht von mir.

    AVI.vb
    Spoiler anzeigen

    VB.NET-Quellcode

    1. Imports System.Drawing.Imaging
    2. Imports System.Runtime.InteropServices
    3. Public Class Avi
    4. Public Const StreamtypeVIDEO As Integer = 1935960438
    5. Public Const OF_SHARE_DENY_WRITE As Integer = 32
    6. Public Const BMP_MAGIC_COOKIE As Integer = 19778
    7. <StructLayout(LayoutKind.Sequential, Pack:=1)> _
    8. Public Structure RECTstruc
    9. Public left As UInt32
    10. Public top As UInt32
    11. Public right As UInt32
    12. Public bottom As UInt32
    13. End Structure
    14. <StructLayout(LayoutKind.Sequential, Pack:=1)> _
    15. Public Structure BITMAPINFOHEADERstruc
    16. Public biSize As UInt32
    17. Public biWidth As Int32
    18. Public biHeight As Int32
    19. Public biPlanes As Int16
    20. Public biBitCount As Int16
    21. Public biCompression As UInt32
    22. Public biSizeImage As UInt32
    23. Public biXPelsPerMeter As Int32
    24. Public biYPelsPerMeter As Int32
    25. Public biClrUsed As UInt32
    26. Public biClrImportant As UInt32
    27. End Structure
    28. <StructLayout(LayoutKind.Sequential, Pack:=1)> _
    29. Public Structure AVISTREAMINFOstruc
    30. Public fccType As UInt32
    31. Public fccHandler As UInt32
    32. Public dwFlags As UInt32
    33. Public dwCaps As UInt32
    34. Public wPriority As UInt16
    35. Public wLanguage As UInt16
    36. Public dwScale As UInt32
    37. Public dwRate As UInt32
    38. Public dwStart As UInt32
    39. Public dwLength As UInt32
    40. Public dwInitialFrames As UInt32
    41. Public dwSuggestedBufferSize As UInt32
    42. Public dwQuality As UInt32
    43. Public dwSampleSize As UInt32
    44. Public rcFrame As RECTstruc
    45. Public dwEditCount As UInt32
    46. Public dwFormatChangeCount As UInt32
    47. <MarshalAs(UnmanagedType.ByValArray, SizeConst:=64)> _
    48. Public szName As UInt16()
    49. End Structure
    50. 'Initialize the AVI library
    51. <DllImport("avifil32.dll")> _
    52. Public Shared Sub AVIFileInit()
    53. End Sub
    54. 'Open an AVI file
    55. <DllImport("avifil32.dll", PreserveSig:=True)> _
    56. Public Shared Function AVIFileOpen(ByRef ppfile As Integer, ByVal szFile As [String], ByVal uMode As Integer, ByVal pclsidHandler As Integer) As Integer
    57. End Function
    58. 'Create a new stream in an open AVI file
    59. <DllImport("avifil32.dll")> _
    60. Public Shared Function AVIFileCreateStream(ByVal pfile As Integer, ByRef ppavi As IntPtr, ByRef ptr_streaminfo As AVISTREAMINFOstruc) As Integer
    61. End Function
    62. 'Set the format for a new stream
    63. <DllImport("avifil32.dll")> _
    64. Public Shared Function AVIStreamSetFormat(ByVal aviStream As IntPtr, ByVal lPos As Int32, ByRef lpFormat As BITMAPINFOHEADERstruc, ByVal cbFormat As Int32) As Integer
    65. End Function
    66. 'Write a sample to a stream
    67. <DllImport("avifil32.dll")> _
    68. Public Shared Function AVIStreamWrite(ByVal aviStream As IntPtr, ByVal lStart As Int32, ByVal lSamples As Int32, ByVal lpBuffer As IntPtr, ByVal cbBuffer As Int32, ByVal dwFlags As Int32, _
    69. ByVal dummy1 As Int32, ByVal dummy2 As Int32) As Integer
    70. End Function
    71. 'Release an open AVI stream
    72. <DllImport("avifil32.dll")> _
    73. Public Shared Function AVIStreamRelease(ByVal aviStream As IntPtr) As Integer
    74. End Function
    75. 'Release an open AVI file
    76. <DllImport("avifil32.dll")> _
    77. Public Shared Function AVIFileRelease(ByVal pfile As Integer) As Integer
    78. End Function
    79. 'Close the AVI library
    80. <DllImport("avifil32.dll")> _
    81. Public Shared Sub AVIFileExit()
    82. End Sub
    83. End Class



    AVIWriter.vb
    Spoiler anzeigen

    VB.NET-Quellcode

    1. Imports System.Drawing.Imaging
    2. Imports System.Runtime.InteropServices
    3. Public Class AviWriter
    4. Private aviFile As Integer = 0
    5. Private aviStream As IntPtr = IntPtr.Zero
    6. Private frameRate As UInt32 = 0
    7. Private countFrames As Integer = 0
    8. Private width As Integer = 0
    9. Private height As Integer = 0
    10. Private stride As UInt32 = 0
    11. Private fccType As UInt32 = Avi.StreamtypeVIDEO
    12. Private fccHandler As UInt32 = 1668707181
    13. Private strideInt As Integer
    14. Private strideU As UInteger
    15. Private heightU As UInteger
    16. Private widthU As UInteger
    17. Public Sub OpenAVI(ByVal fileName As String, ByVal frameRate As UInt32)
    18. Me.frameRate = frameRate
    19. Avi.AVIFileInit()
    20. Dim OpeningError As Integer = Avi.AVIFileOpen(aviFile, fileName, 4097, 0)
    21. If OpeningError <> 0 Then
    22. Throw New Exception("Error in AVIFileOpen: " + OpeningError.ToString())
    23. End If
    24. End Sub
    25. Public Sub AddFrame(ByVal bmp As Bitmap)
    26. bmp.RotateFlip(RotateFlipType.RotateNoneFlipY)
    27. Dim bmpData As BitmapData = bmp.LockBits(New Rectangle(0, 0, bmp.Width, bmp.Height), ImageLockMode.[ReadOnly], PixelFormat.Format24bppRgb)
    28. If countFrames = 0 Then
    29. Dim bmpDatStride As UInteger = bmpData.Stride
    30. Me.stride = DirectCast(bmpDatStride, UInt32)
    31. Me.width = bmp.Width
    32. Me.height = bmp.Height
    33. CreateStream()
    34. End If
    35. strideInt = stride
    36. Dim writeResult As Integer = Avi.AVIStreamWrite(aviStream, countFrames, 1, bmpData.Scan0, DirectCast((strideInt * height), Int32), 0, 0, 0)
    37. If writeResult <> 0 Then
    38. Throw New Exception("Error in AVIStreamWrite: " + writeResult.ToString())
    39. End If
    40. bmp.UnlockBits(bmpData)
    41. System.Math.Max(System.Threading.Interlocked.Increment(countFrames), countFrames - 1)
    42. End Sub
    43. Private Sub CreateStream()
    44. Dim strhdr As New Avi.AVISTREAMINFOstruc()
    45. strhdr.fccType = fccType
    46. strhdr.fccHandler = fccHandler
    47. strhdr.dwScale = 1
    48. strhdr.dwRate = frameRate
    49. strideU = stride
    50. heightU = height
    51. strhdr.dwSuggestedBufferSize = DirectCast((stride * strideU), UInt32)
    52. strhdr.dwQuality = 10000
    53. heightU = height
    54. widthU = width
    55. strhdr.rcFrame.bottom = DirectCast(heightU, UInt32)
    56. strhdr.rcFrame.right = DirectCast(widthU, UInt32)
    57. strhdr.szName = New UInt16(64) {}
    58. Dim createResult As Integer = Avi.AVIFileCreateStream(aviFile, aviStream, strhdr)
    59. If createResult <> 0 Then
    60. Throw New Exception("Error in AVIFileCreateStream: " + createResult.ToString())
    61. End If
    62. Dim bi As New Avi.BITMAPINFOHEADERstruc()
    63. Dim bisize As UInteger = Marshal.SizeOf(bi)
    64. bi.biSize = DirectCast(bisize, UInt32)
    65. bi.biWidth = DirectCast(width, Int32)
    66. bi.biHeight = DirectCast(height, Int32)
    67. bi.biPlanes = 1
    68. bi.biBitCount = 24
    69. strideU = stride
    70. heightU = height
    71. bi.biSizeImage = DirectCast((strideU * heightU), UInt32)
    72. Dim formatResult As Integer = Avi.AVIStreamSetFormat(aviStream, 0, bi, Marshal.SizeOf(bi))
    73. If formatResult <> 0 Then
    74. Throw New Exception("Error in AVIStreamSetFormat: " + formatResult.ToString())
    75. End If
    76. End Sub
    77. Public Sub Close()
    78. If aviStream <> IntPtr.Zero Then
    79. Avi.AVIStreamRelease(aviStream)
    80. aviStream = IntPtr.Zero
    81. End If
    82. If aviFile <> 0 Then
    83. Avi.AVIFileRelease(aviFile)
    84. aviFile = 0
    85. End If
    86. Avi.AVIFileExit()
    87. End Sub
    88. End Class



    Verwendung:

    VB.NET-Quellcode

    1. Dim Writer As New AviWriter
    2. Writer.OpenAVI("C:\bla\bla.avi", 10) 'pfad, framerate
    3. For Each Frame In bmpArray 'array von Bitmaps
    4. Writer.AddFrame(Frame)
    5. Next
    6. Writer.Close()


    Quelle: Codeproject

    Viel Erfolg noch,
    SᴛᴀʀGᴀᴛᴇ01

    Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von „StarGate01“ ()

    Das ist ja ma toll. Das ist eh genau der Wrapper für das die API's die ich gepostet habe :)
    Jedoch würde mir da noch ne Hintergrundmusik fehlen.


    Opensource Audio-Bibliothek auf github: KLICK, im Showroom oder auf NuGet.