这个 C# 脚本中的 if else if else 语句有什么问题?
What is wrong with the if else if else statement in this C# script?
我在使用 C# 脚本时遇到问题,该脚本使用 Sony Vegas Pro 脚本 API 生成用于在 ffmpeg 中修剪的视频剪辑编辑列表。完整的脚本和目的的详细信息可以在 http://www.sonycreativesoftware.com/forums/showmessage.asp?forumid=21&messageid=932542.
找到
我的部分脚本如下所示。当我 运行 脚本时,我收到错误 "The name 'OffsetAdjusterFrames' does not exist in the current context",与行 Timecode OffsetAdjuster = Timecode.FromFrames(OffsetAdjusterFrames);
和 "The name 'DurationAdjusterFrames' does not exist in the current context" 有关 与下一行有关。
问题似乎出在 if (clipOffsetOriginalFrames == 0)
行或 if else if else
语句中的其他内容。如果我通过注释掉并显式声明 OffsetAdjusterFrames
和 DurationAdjusterFrames
来绕过整个 if else if else
语句,那么脚本的其余部分将起作用。
任何帮助将不胜感激,因为我 运行 无法尝试。谢谢。
编辑:这与 enter link description here 不同,因为这是 C# 而那是 Java,所以它不是真正的重复,但一般解决方案是相同的。
...
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);
...
变量 OffsetAdjusterFrames
和 DurationAdjusterFrames
在 if 语句中声明,因此它们是局部变量,不能从 if 语句外部调用。
当您将声明移到 if 语句之外时,说到方法中,它起作用了,因为变量的范围在方法中,所以只要它在方法中,就可以在 if 语句之外调用.
所以基本上只需在方法的开头声明变量,如下所示:
int OffsetAdjusterFrames;
int DurationAdjusterFrames;
然后像这样在 if 语句中分配值:
// Reset start to zero if start was not trimmed at all, and compensate length
if (clipOffsetOriginalFrames == 0)
{
OffsetAdjusterFrames = 2;
DurationAdjusterFrames = -2;
}
// Reset start to zero if start had been trimmed by just 1 frame, and compensate length
else if (clipOffsetOriginalFrames == 1)
{
OffsetAdjusterFrames = 1;
DurationAdjusterFrames = -1;
}
else
{
OffsetAdjusterFrames = 0;
DurationAdjusterFrames = 0;
}
我在使用 C# 脚本时遇到问题,该脚本使用 Sony Vegas Pro 脚本 API 生成用于在 ffmpeg 中修剪的视频剪辑编辑列表。完整的脚本和目的的详细信息可以在 http://www.sonycreativesoftware.com/forums/showmessage.asp?forumid=21&messageid=932542.
找到我的部分脚本如下所示。当我 运行 脚本时,我收到错误 "The name 'OffsetAdjusterFrames' does not exist in the current context",与行 Timecode OffsetAdjuster = Timecode.FromFrames(OffsetAdjusterFrames);
和 "The name 'DurationAdjusterFrames' does not exist in the current context" 有关 与下一行有关。
问题似乎出在 if (clipOffsetOriginalFrames == 0)
行或 if else if else
语句中的其他内容。如果我通过注释掉并显式声明 OffsetAdjusterFrames
和 DurationAdjusterFrames
来绕过整个 if else if else
语句,那么脚本的其余部分将起作用。
任何帮助将不胜感激,因为我 运行 无法尝试。谢谢。
编辑:这与 enter link description here 不同,因为这是 C# 而那是 Java,所以它不是真正的重复,但一般解决方案是相同的。
...
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);
...
变量 OffsetAdjusterFrames
和 DurationAdjusterFrames
在 if 语句中声明,因此它们是局部变量,不能从 if 语句外部调用。
当您将声明移到 if 语句之外时,说到方法中,它起作用了,因为变量的范围在方法中,所以只要它在方法中,就可以在 if 语句之外调用.
所以基本上只需在方法的开头声明变量,如下所示:
int OffsetAdjusterFrames;
int DurationAdjusterFrames;
然后像这样在 if 语句中分配值:
// Reset start to zero if start was not trimmed at all, and compensate length
if (clipOffsetOriginalFrames == 0)
{
OffsetAdjusterFrames = 2;
DurationAdjusterFrames = -2;
}
// Reset start to zero if start had been trimmed by just 1 frame, and compensate length
else if (clipOffsetOriginalFrames == 1)
{
OffsetAdjusterFrames = 1;
DurationAdjusterFrames = -1;
}
else
{
OffsetAdjusterFrames = 0;
DurationAdjusterFrames = 0;
}