2

我有一个制作 AVI 电影的 Delphi 6 应用程序。我已经到了可以编写具有未压缩视频帧的 AVI 文件的程度。当我尝试创建压缩视频流时,我在调用 AVIStreamSetFormat() 时收到 AVIERR_MEMORY 错误:

hr := AVIStreamSetFormat(
        FAvi_.thePsCompressed, 
        0, 
        @dsBmih, 
        dsBmih.biSize + dsBmih.biClrUsed * sizeof(RGBQUAD));

为什么我会收到此错误,我该怎么做才能修复它?

这是我使用Radius 压缩器选择 Cinepak 代码后压缩选项数据结构的内容,使用调用 AVISaveOptions()。请注意,如果我选择不同的压缩机,我仍然会收到错误消息:

fccType: 0
fccHandler: 1684633187
dwKeyFrameEvery: 0
dwQuality: 8800
dwBytesPerSecond: 0
dwFlags: 8
lpFormat: nil
cbFormat: 0
lpParms: nil
cbParms: 4
dwInterleaveEvery: 0

下面是 TBitmapHeaderInfo 数据结构的内容:

biSize: 40
biWidth: 320
biHeight: -240
biPlanes: 1
biBitcount: 32
biCompression: 0
biSizeImage: 307200
biXPelsPerMeter: 0
biYPelsPerMeter: 0
biClrUsed: 0
biClrImportant: 0

这是包含对 AVIStreamSetFormat() 的调用的方法:

function TAviWriterWithCompression.compressionDirect(
                                opts: PAVICOMPRESSOPTIONS;
                                bShowDialog: boolean;
                                hparent: HWND;
                                dsBmih: TBitmapInfoHeader;
                                sizeImage: integer;
                                DIBValues: Pointer;
                                framesPerSecond: integer): HRESULT;
var
    lastErr: string;
    hr: HRESULT;
    myopts: TAVICOMPRESSOPTIONS;
    aopts: array[0..0] of PAVICOMPRESSOPTIONS;
    res: Bool;
begin
    if not FIsVirginFile then
    begin
        // The output file already has at least one audio or video frame so
        //  setting or changing the compression format is not allowed.
        Result := LongInt(AVIERR_ERROR);

        // =========================== EXIT POINT ==============
        exit;
    end; // if not Assigned(FAvi_) then

    if not Assigned(FAvi_) then
    begin
        Result := LongInt(AVIERR_BADHANDLE);

        // =========================== EXIT POINT ==============
        exit;
    end; // if not Assigned(FAvi_) then

    // Check the utility object for an error.
    if (FAvi_.iserr) then
    begin
        Result := LongInt(AVIERR_ERROR);
        // =========================== EXIT POINT ==============
        exit;
    end; // if (FAvi_.iserr) then

    // Make sure the compressor has not already been selected.
    if Assigned(FAvi_.thePsCompressed) then
    begin
        Result := LongInt(AVIERR_COMPRESSOR);
        // =========================== EXIT POINT ==============
        exit;
    end; // if (FAvi_.iserr) then

    // create the stream, if it wasn't there before
    if not Assigned(FAvi_.thePs) then
    begin
        hr := createVideoStream(dsBmih, framesPerSecond);

        if hr <> AVIERR_OK then
        begin
            Result := hr;

            // Set the error flag in our utility object.
            FAvi_.iserr := true;

            // =========================== EXIT POINT ==============
            exit;
        end; // if hr <> AVIERR_OK then
    end; // if not Assigned(FAvi_.thePs) then

    // set the compression, prompting dialog if necessary
    if not Assigned(FAvi_.thePsCompressed) then
    begin
        ZeroMemory(@myopts, sizeof(myopts));

        if Assigned(opts) then
            // Use the provided compressor options
            aopts[0] := opts
        else
            // Use our initialized (empty) variable.
            aopts[0] := @myopts;

        // Does the caller want to show the compressor dialog box?
        if (bShowDialog) then
        begin
            res := AVISaveOptions(hparent, 0, 1, FAvi_.thePs, aopts[0]);

            if not res then
            begin
                AVISaveOptionsFree(1, aopts[0]);

                // Set the error flag.
                FAvi_.iserr := true;

                Result := LongInt(AVIERR_USERABORT);

                // =========================== EXIT POINT ==============
                exit;
            end; // if res = 0 then
        end; // if (bShowDialog) then

        hr := AVIMakeCompressedStream(FAvi_.thePsCompressed, FAvi_.thePs, aopts[0], nil);

        if hr <> AVIERR_OK then
        begin
            Result := hr;

            // Set the error flag in our utility object.
            FAvi_.iserr := true;

            // =========================== EXIT POINT ==============
            exit;
        end; // if hr <> AVIERR_OK then

        AVISaveOptionsFree(1, aopts[0]);
        postDiagMsg('Avi::compression after AVISaveOptionsFree()');

        // >>>> This is where I get the AVIERR_MEMORY error.
        hr := AVIStreamSetFormat(FAvi_.thePsCompressed, 0, @dsBmih, dsBmih.biSize + dsBmih.biClrUsed * sizeof(RGBQUAD));

        if hr <> AVIERR_OK then
        begin
            Result := hr;

            // Set the error flag in our utility object.
            FAvi_.iserr := true;

            // =========================== EXIT POINT ==============
            exit;
        end; // if hr <> AVIERR_OK then
    end; // if not Assigned(FAvi_.thePsCompressed) then

    Result := AVIERR_OK;
end;
4

1 回答 1

3

可能是结构体中的负值导致的biHeightTBitmapHeaderInfo也就是说存储在DIB部分的位值代表的是垂直翻转的图像。

某些编解码器可能无法解决此问题。因此,请尝试确保您选择的视频流压缩器可以处理图像头的大小和位深度。您必须仅使用受支持的图像格式,如果您的编解码器不支持翻转图像,则您必须自己翻转 DIB 图像数据并手动修改图像标题。

于 2012-05-03T14:30:55.213 回答