dimanche 27 septembre 2015

What is wrong with the if else if else statement in this C# script?

I am having trouble with a C# script that uses the Sony Vegas Pro scripting API to generate an edit list of video clips for trimming in ffmpeg. The full script and details of the purpose can be found at http://ift.tt/1iD6h1V.

Part of my script is shown below. I am not a programmer so it is cobbled together from other scripts, some research, and plenty of guesswork.

When I run the script I get the error "The name 'OffsetAdjusterFrames' does not exist in the current context", relating to the line Timecode OffsetAdjuster = Timecode.FromFrames(OffsetAdjusterFrames); , and "The name 'DurationAdjusterFrames' does not exist in the current context" relating to the next line.

The problem seems to be with the line if (clipOffsetOriginalFrames == 0) or with something else in that if else if else statement. Maybe differing value types? If I bypass the whole of that if else if else statement by commenting it out and explicitly declaring OffsetAdjusterFrames and DurationAdjusterFrames then the rest of the script works.

Any help would be appreciated as I have run out of things to try. Thanks.

...
    Timecode clipOffsetOriginal = videoEvent.ActiveTake.Offset;
    // clipOffsetOriginal as a number of frames
    Int64 clipOffsetOriginalFrames = videoEvent.ActiveTake.Offset.FrameCount;

    Timecode clipOffset = clipOffsetOriginal - startAdd;
    Timecode clipDuration = videoEvent.Length + startAdd + endAdd;

    // Reset start to zero if start was not trimmed at all, and compensate length
    if (clipOffsetOriginalFrames == 0)
    {
        int OffsetAdjusterFrames = 2;
        int DurationAdjusterFrames = -2;
    }
    // Reset start to zero if start had been trimmed by just 1 frame, and compensate length
    else if (clipOffsetOriginalFrames == 1)
    {
        int OffsetAdjusterFrames = 1;
        int DurationAdjusterFrames = -1;
    }
    else
    {
        int OffsetAdjusterFrames = 0;
        int DurationAdjusterFrames = 0;
    }

    Timecode OffsetAdjuster = Timecode.FromFrames(OffsetAdjusterFrames);
    Timecode DurationAdjuster = Timecode.FromFrames(DurationAdjusterFrames);
    Timecode clipOffsetAdjusted = clipOffset + OffsetAdjuster;
    Timecode clipDurationAdjusted = clipDuration + DurationAdjuster;

    // Convert start and duration from timecode to seconds
    double start = clipOffsetAdjusted.ToMilliseconds() / 1000;
            double duration = clipDurationAdjusted.ToMilliseconds() / 1000;

    string triminfo = String.Format(basename + ".mp4 " + start + " " + duration);
...

Aucun commentaire:

Enregistrer un commentaire