请问怎么在AVI文件后面多加几帧呢?res = AVIStreamWrite(psCompressed, i, 1,  bmp.PointerToBits, bmp.SizeImage, AVIIF_KEYFRAME, _
                            ByVal 0&, ByVal 0&)应该怎么改呢?
还有,要写入图片的哪个AVI文件没有压缩过的。
请高人指点,谢谢

解决方案 »

  1.   

    用AVIStreamLength得到当前打开的文件的最后一帧的序号,然后加1,作为AVIStreamWrite的第二个参数.这样的话就可以添加新帧.
      

  2.   

    AVI有很种格式,有压缩的,也有没有压缩的;有无声API和有声API之分。我个人觉得没那么简单。何不用专门工具编辑一下添加几帧呢?比如:Adoble Premiere 是微型机上用得最多的非线性编辑工具,本人一直用这个软件编辑视频,相当专业!
      

  3.   

    没压缩的AVI元格式应该挺好说,以前是做过.压缩过的就有些麻烦了,要知道压缩格式,添加好后还得按原样压缩回去....
      

  4.   

    不知道 爲什麽     avilen = AVIStreamLength(psCompressed)
    avilen總是0呢 ?
      

  5.   

    老马您能够发一个例子给我吗?先谢谢了
    mail : [email protected]
      

  6.   

    .....那是给别人写的一个工程,不能给你代码的.不过,你的psCompressed确定是个有效的流句柄么?你前面怎么得到这个句柄的?如果可以,你把全部代码发上来,也许能帮你折腾.
      

  7.   

    估计他是要自己写个工具,在AVI头尾加广告-_-b我写的那个单子就是这样-_-b
      

  8.   


    Private Sub cmdWriteAVI_Click()
     
        Dim file As cFileDlg
        Dim InitDir As String
        Dim szOutputAVIFile As String
        Dim res As Long
        Dim pfile As Long 'ptr PAVIFILE
        Dim bmp As cDIB
        Dim ps As Long 'ptr PAVISTREAM
        Dim psCompressed As Long 'ptr PAVISTREAM
        Dim strhdr As AVI_STREAM_INFO
        Dim BI As BITMAPINFOHEADER
        Dim opts As AVI_COMPRESS_OPTIONS
        Dim pOpts As Long
        Dim i As Long
        
       Debug.Print
        Set file = New cFileDlg
        'get an avi filename from user
        With file
            .DefaultExt = "avi"
            .DlgTitle = "Choose a filename to save AVI to..."
            .Filter = "AVI Files|*.avi"
            .OwnerHwnd = Me.hWnd
        End With
        szOutputAVIFile = "MyAVI.avi"
        If file.VBGetSaveFileName(szOutputAVIFile) <> True Then Exit Sub
            
    '    Open the file for writing
        res = AVIFileOpen(pfile, szOutputAVIFile, OF_WRITE Or OF_CREATE, 0&)
        If (res <> AVIERR_OK) Then GoTo error    'Get the first bmp in the list for setting format
        Set bmp = New cDIB
        lstDIBList.ListIndex = 0
        If bmp.CreateFromFile(lstDIBList.Text) <> True Then
            MsgBox "Could not load first bitmap file in list!", vbExclamation, App.title
            GoTo error
        End If'   Fill in the header for the video stream
        With strhdr
            .fccType = mmioStringToFOURCC("vids", 0&)    '// stream type video
            .fccHandler = 0&                             '// default AVI handler
            .dwScale = 1
            .dwRate = Val(txtFPS)                        '// fps
            .dwSuggestedBufferSize = bmp.SizeImage       '// size of one frame pixels
            Call SetRect(.rcFrame, 0, 0, bmp.Width, bmp.Height)       '// rectangle for stream
        End With
        
        'validate user input
        If strhdr.dwRate < 1 Then strhdr.dwRate = 1
        If strhdr.dwRate > 30 Then strhdr.dwRate = 30'   And create the stream
        res = AVIFileCreateStream(pfile, ps, strhdr)
        If (res <> AVIERR_OK) Then GoTo error    'get the compression options from the user
        'Careful! this API requires a pointer to a pointer to a UDT
        pOpts = VarPtr(opts)
        res = AVISaveOptions(Me.hWnd, _
                            ICMF_CHOOSE_KEYFRAME Or ICMF_CHOOSE_DATARATE, _
                            1, _
                            ps, _
                            pOpts) 'returns TRUE if User presses OK, FALSE if Cancel, or error code
        If res <> 1 Then 'In C TRUE = 1
            Call AVISaveOptionsFree(1, pOpts)
            GoTo error
        End If
        
        'make compressed stream
        res = AVIMakeCompressedStream(psCompressed, ps, opts, 0&)
        If res <> AVIERR_OK Then GoTo error
        
        'set format of stream according to the bitmap
        With BI
            .biBitCount = bmp.BitCount
            .biClrImportant = bmp.ClrImportant
            .biClrUsed = bmp.ClrUsed
            .biCompression = bmp.Compression
            .biHeight = bmp.Height
            .biWidth = bmp.Width
            .biPlanes = bmp.Planes
            .biSize = bmp.SizeInfoHeader
            .biSizeImage = bmp.SizeImage
            .biXPelsPerMeter = bmp.XPPM
            .biYPelsPerMeter = bmp.YPPM
        End With
        
        'set the format of the compressed stream
        res = AVIStreamSetFormat(psCompressed, 0, ByVal bmp.PointerToBitmapInfo, bmp.SizeBitmapInfo)
        If (res <> AVIERR_OK) Then GoTo error'   Now write out each video frame
        For i = 0 To lstDIBList.ListCount - 1
            lstDIBList.ListIndex = i
            bmp.CreateFromFile (lstDIBList.Text) 'load the bitmap (ignore errors)
            res = AVIStreamWrite(psCompressed, _
                                i, _
                                1, _
                                bmp.PointerToBits, _
                                bmp.SizeImage, _
                                AVIIF_KEYFRAME, _
                                ByVal 0&, _
                                ByVal 0&)
            If res <> AVIERR_OK Then GoTo error
            'Show user feedback
            imgPreview.Picture = LoadPicture(lstDIBList.Text)
            imgPreview.Refresh
            lblStatus = "Frame number " & i & " saved"
            lblStatus.Refresh
        Next
        lblStatus = "Finished!"error:
    '   Now close the file
        Set file = Nothing
        Set bmp = Nothing
        
        If (ps <> 0) Then Call AVIStreamClose(ps)    If (psCompressed <> 0) Then Call AVIStreamClose(psCompressed)    If (pfile <> 0) Then Call AVIFileClose(pfile)    Call AVIFileExit    If (res <> AVIERR_OK) Then
            MsgBox "There was an error writing the file.", vbInformation, App.title
        End If
    End Sub
      

  9.   

    但是我想在后面加啊,这个是如果没有文件的时候才用的,如果有AVI文件的话就要在后面添帧了,现在就是不知道怎么添...
      

  10.   

    先得取到最后一帧才行,然后再添加.你之前说调用AVIStreamLength出错,你的流句柄是怎么得到的?我在这个代码里好象没看到你在哪里调用AVIFileGetStream取得流句柄了啊.