How do I refresh the video codecs shown in the lis

2019-07-11 13:04发布

I have a Delphi 6 application with a Wizard that helps people select an appropriate video codec. It uses AviSaveOptions() to show the user a list of video codecs so they can select one. The choice is saved to disk for later re-use. At one point in the Wizard, the user is directed to download and install one out of several popular video codecs using their browser in the event they don't have a suitable one. However, after they install the new video codec and return to my app, when I call AviSaveOptions() for the second time so they can select the newly installed video codec, the list does not show the new codec.

If I exit my application completely and return to the Wizard, calling AviSaveOptions() does show the new codec in the dialog box. I obviously would like to refresh the list from within my app so the user doesn't have to reload the program to select the new codec. I do call AviFileInit() and AviFileExit() within my method that calls AviSaveOptions(). What else do I need to do so that the codec list shown in the dialog box by AviSaveOptions() is updated to show the newly installed video codec? Below is the code I am using to call 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;

0条回答
登录 后发表回答