Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 无法理解此方法(它如何尝试匹配帧速率?)_Java_Video_Video Streaming_Xuggle - Fatal编程技术网

Java 无法理解此方法(它如何尝试匹配帧速率?)

Java 无法理解此方法(它如何尝试匹配帧速率?),java,video,video-streaming,xuggle,Java,Video,Video Streaming,Xuggle,我在浏览时遇到了以下片段: } 我抓了很多东西,但不明白这个方法有什么用?我们回来干什么?为什么我们在方法返回后让线程休眠该方法的目的是什么 这是链接中的完整代码: } 似乎是这样的: * So instead, the following code does a poor-man's version of trying to * match up the frame-rate requested for each IVideoPicture with the system * clock

我在浏览时遇到了以下片段:

}

我抓了很多东西,但不明白这个方法有什么用?我们回来干什么?为什么我们在方法返回后让线程休眠该方法的目的是什么

这是链接中的完整代码:

}

似乎是这样的:

 * So instead, the following code does a poor-man's version of trying to
 * match up the frame-rate requested for each IVideoPicture with the system
 * clock time on your computer.

延迟是为了尝试匹配帧率。

伪码中的粗略算法:

Is this the first frame?
  > Yes, save the frame time and the current time.

  > No, do the following:
    See how much time has passed since the first frame was displayed in System Time
    See the difference in time between the current frame and the first frame

    If there is a discrepancy
      >Return a number of milliseconds to sleep for, else return 0.
因此,您得到的是以下的总体算法:

Decode frame
Check if we need to delay the frame (the method in question)
Delay
Display frame
这样,程序显示的帧速率将永远不会超过视频声明的可变帧速率。该方法保持前一帧时间的状态,并计算睡眠时间

编辑:延迟是必要的,因为你可以解码帧很多!比视频的帧速率快。假设你有一台运行这个程序的相当慢的机器,解码一帧需要10毫秒。我们还可以假设视频的帧速率是可变的,但大约是每秒10帧或每帧100毫秒。现在,如果你从我们的“整体算法”中走出这一步:

Decode frame (10ms)
Display frame (1ms)
Decode frame (10ms)
Display frame (1ms)
如果发生这种情况,你会发现每10毫秒显示一帧,这意味着视频将以每秒100帧的速度显示,这是错误的

EDIT2:我想你是问我们为什么不这样做

Decode frame
Frame Delta = Current Frame Time - Previous Frame Time
Delay (for Delta milliseconds)
Display frame
问题是,如果解码或显示帧需要很长时间,会发生什么情况?这将导致帧速率明显低于文件中的帧速率

相反,该算法将第一帧与系统时间同步,然后进行一点额外计算:

long systemTimeChange = currentSystemTime - firstFrameSystemTime;
long frameTimeChange = currentFrameTime - firstFrameTime;

// Subtract the time elapsed.
long differenceInChanges = frameTimeChange - systemTimeChange;
if(differenceInChanges > 0) {
  // It was faster to decode than the frame rate!
  Thread.sleep(differenceInChanges);
}
系统时间实际上表示特定帧被解码的时间,FrameTime大致表示视频的帧速率。所以区别是这样的:差异=帧速率-解码率+容差当解码视频所花费的时间大于它所花费的时间或者媒体显示所花费的时间较长时,容差可能很有用。以下是您从差异中得到的信息:


由于解码速度与视频的帧速率相比太快,因此我们必须等待一段时间,现在无法显示该帧。我们使用systemTimeStamp来同步帧,并将其保持到正确的时间。在上图中,您可以看到解码速率有多快,但与解码速率相比,帧速率很慢。

它是如何尝试匹配帧速率的?这就是问题所在。没关系。但是你能解释一下为什么会出现这种差异吗?记录系统时间的需要是什么?请在你的回答中详细说明我已经编辑了我的答案。实际上,延迟是为了防止以解码速率显示帧,解码速率通常比帧速率快。为什么我们需要记录系统时间?这有什么帮助?我已经在EDIT2中提到了你的评论。系统时间用于同步视频播放速度。
Decode frame
Check if we need to delay the frame (the method in question)
Delay
Display frame
Decode frame (10ms)
Display frame (1ms)
Decode frame (10ms)
Display frame (1ms)
Decode frame
Frame Delta = Current Frame Time - Previous Frame Time
Delay (for Delta milliseconds)
Display frame
long systemTimeChange = currentSystemTime - firstFrameSystemTime;
long frameTimeChange = currentFrameTime - firstFrameTime;

// Subtract the time elapsed.
long differenceInChanges = frameTimeChange - systemTimeChange;
if(differenceInChanges > 0) {
  // It was faster to decode than the frame rate!
  Thread.sleep(differenceInChanges);
}