2

適切なビデオ コーデックを選択するのに役立つウィザードを備えた Delphi 6 アプリケーションがあります。AviSaveOptions() を使用してビデオ コーデックのリストを表示し、ユーザーが選択できるようにします。選択内容は、後で再利用できるようにディスクに保存されます。ウィザードのある時点で、ユーザーは、適切なビデオ コーデックがない場合にブラウザを使用して、いくつかの一般的なビデオ コーデックから 1 つをダウンロードしてインストールするように指示されます。ただし、新しいビデオ コーデックをインストールしてアプリに戻った後、AviSaveOptions() をもう一度呼び出して、新しくインストールしたビデオ コーデックを選択できるようにすると、リストに新しいコーデックが表示されません。

アプリケーションを完全に終了してウィザードに戻ると、AviSaveOptions() を呼び出すと、ダイアログ ボックスに新しいコーデックが表示されますユーザーが新しいコーデックを選択するためにプログラムをリロードする必要がないように、アプリ内からリストを更新したいのは明らかです。AviSaveOptions() を呼び出すメソッド内で AviFileInit() と AviFileExit() を呼び出します。AviSaveOptions() によってダイアログ ボックスに表示されるコーデック リストが更新され、新しくインストールされたビデオ コーデックが表示されるようにするには、他に何をする必要がありますか? 以下は、AviSaveOptions() を呼び出すために使用しているコードです。

function doGetUsersCompressorChoice(theCallingForm: TForm; theFccType: FOURCC): FOURCC;
var
    // theCompressionOptionsFile: TAviCompressionOptionsFile;
    theCompressionOptions: TAVICOMPRESSOPTIONS;
    res: LongBool;
    hr: HRESULT;
    intfAviStream: IAVIStream;
    testVideoFilenameSrc, testVideoFilename: string;
    aryCompressOpts: array[0..0] of PAVICOMPRESSOPTIONS;
    fullSaveOptsFilePath: string;
begin
    // fullPathToCompressorOptsFile := '';
    if not Assigned(theCallingForm) then
        raise Exception.Create('(doGetUsersCompressorChoice) The calling form is unassigned.');

    // Make sure the test video file exists.
    testVideoFilenameSrc := getTestVideoPath_compsettings + TEST_COMPRESSION_VIDEO_FILENAME;

    if not FileExists(testVideoFilenameSrc) then
        raise Exception.Create('(doGetUsersCompressorChoice) Unable to find the test video file: ' + testVideoFilename);

    // Copy it since we are about to tinker with it and don't want to damage
    //  the original.
    testVideoFilename := ChangeFileExt(testVideoFilenameSrc, '.comptest.avi');

    if FileExists(testVideoFilename) then
    begin
        // Delete it.
        if not DeleteFile(testVideoFilename) then
            raise Exception.Create('(doGetUsersCompressorChoice) Unable to delete the test video file: ' + testVideoFilename);
    end; // if FileExists(testVideoFilename) then

    // Copy the source to the test file.
    if not CopyFile(PChar(testVideoFilenameSrc), PChar(testVideoFilename), true) then
        raise Exception.Create('(doGetUsersCompressorChoice) Unable to copy the source video file to the test video file (source, dest): ' + testVideoFilenameSrc + ', ' + testVideoFilename);

    AVIFileInit;

    FillChar(theCompressionOptions, SizeOf(theCompressionOptions), 0);

    aryCompressOpts[0] := @theCompressionOptions;

    // theCompressionOptionsFile := TAviCompressionOptionsFile.Create;

    try
        // Open the test video file.
        hr := AVIStreamOpenFromFile(intfAviStream, PChar(testVideoFilename), theFccType, 0, OF_READ, nil);

        checkAviResult('doGetUsersCompressorChoice', hr, 'Unable to open the test video file (AVIStreamOpenFromFile)');

        // Now prompt the user for the desired compressor.
        res := AVISaveOptions(theCallingForm.Handle, 0, 1, intfAviStream, aryCompressOpts[0]);

        if res then
        begin
            {
                IMPORTANT: Microsoft does not use the fccType field for
                audio compressors and leaves it 0 when calling AviSaveOptions().
                To compensate we are using a fake FOURCC equal to
                ('f','a','k','e') for audio compressors.

                Therefore, you can't tell which audio compressor is in
                use.  The fake FOURCC is only to keep the compressor
                options file object and methods happy since they
                need an identifier to use when storing the compressor
                settings.

                We have a message about this on Stack Overflow but
                so far no one has provided an answer on how to ID
                the compressor being returned by

            }

            if theFccType = streamtypeAUDIO then
                Result := stringToFOURCC(FOURCC_FAKE_AUDIO_COMPRESSOR_ID)
            else
                // Result is the FOURCC of the selected compressor.
                Result := aryCompressOpts[0]^.fccHandler;

            try
                fullSaveOptsFilePath := getCompressorOptsFullFilePath(Result);

                // Save the user's selected compressor settings to disk.
                // theCompressionOptionsFile.save(aryCompressOpts[0]^);
                if writeCompOptsFile(fullSaveOptsFilePath, aryCompressOpts[0]^) <> AVIERR_OK then
                    raise Exception.Create('(doGetUsersCompressorChoice) Unable to save the compressor options to disk, file name: ' + fullSaveOptsFilePath);

                // Return the full path to the saved compressor options file.
                // fullPathToCompressorOptsFile :=
                //    theCompressionOptionsFile.fullFilename;
            finally
                // Free the compression options variable.
                AVISaveOptionsFree(1, aryCompressOpts[0]);
            end; // try
        end
        else
        begin
            // User aborted operation.  Just return the Result of 0.
            Result := 0;
        end;
    finally
        // if Assigned(theCompressionOptionsFile) then
        //    theCompressionOptionsFile.Free;

        AviFileExit;
    end; // try
end;
4

0 に答える 0