gpt4 book ai didi

c# - 视频时长是应有的两倍

转载 作者:行者123 更新时间:2023-12-04 23:02:39 26 4
gpt4 key购买 nike

我试图记录我的电脑屏幕,因为我正在使用 Accord。

我在 Accord 3.8.0.0 版上一切正常,但是当我升级到 3.8.2.0-alpha 版时,我的录制视频速度变慢了,大约需要两倍才能完成。

所以一个 10 秒的视频实际上需要 20 秒才能播放(在视频播放器中,视频的持续时间也是 10 秒)。

我在谷歌搜索并没有找到任何有用的东西。可能是由于发布的 alpha 版本。

我设法从使用这个 3.8.2.0-alpha 版本的 Accord 项目的维护者那里找到了一个项目:https://github.com/cesarsouza/screencast-capture

我下载了 zip 文件,解压项目,构建项目,修复编译错误(将 Dispose() 更改为 Stop() )然后运行应用程序,但问题仍然存在......生成的视频文件仍然很慢......

我的 3.8.2.0-alpha 版本代码的主要方法是这些(它们取自我下载的上一个项目):

public void StartRecording()
{
if (IsRecording || !IsPlaying)
return;

int height = area.Height;
int width = area.Width;
Rational framerate = new Rational(1000, screenStream.FrameInterval);
int videoBitRate = 1200 * 1000;

OutputPath = Path.Combine(main.CurrentDirectory, fileName);
RecordingStartTime = DateTime.MinValue;
videoWriter = new VideoFileWriter();
videoWriter.BitRate = videoBitRate;
videoWriter.FrameRate = framerate;
videoWriter.Width = width;
videoWriter.Height = height;
videoWriter.VideoCodec = VideoCodec.H264;
videoWriter.VideoOptions["crf"] = "18";
videoWriter.VideoOptions["preset"] = "veryfast";
videoWriter.VideoOptions["tune"] = "zerolatency";
videoWriter.VideoOptions["x264opts"] = "no-mbtree:sliced-threads:sync-lookahead=0";

videoWriter.Open(OutputPath);

HasRecorded = false;
IsRecording = true;
}

void VideoPlayer_NewFrameReceived(object sender, Accord.Video.NewFrameEventArgs eventArgs)
{
DateTime currentFrameTime = eventArgs.CaptureFinished;

// Encode the last frame at the same time we prepare the new one
Task.WaitAll(
Task.Run(() =>
{
lock (syncObj) // Save the frame to the video file.
{
if (IsRecording)
{
if (RecordingStartTime == DateTime.MinValue)
RecordingStartTime = DateTime.Now;

TimeSpan timestamp = currentFrameTime - RecordingStartTime;
if (timestamp > TimeSpan.Zero)
videoWriter.WriteVideoFrame(this.lastFrame, timestamp, this.lastFrameRegion);
}
}
}),

Task.Run(() =>
{
// Adjust the window according to the current capture
// mode. Also adjusts to keep even widths and heights.
CaptureRegion = AdjustWindow();

// Crop the image if the mode requires it
if (CaptureMode == CaptureRegionOption.Fixed ||
CaptureMode == CaptureRegionOption.Window)
{
crop.Rectangle = CaptureRegion;

eventArgs.Frame = croppedImage = crop.Apply(eventArgs.Frame, croppedImage);
eventArgs.FrameSize = crop.Rectangle.Size;
}

//// Draw extra information on the screen
bool captureMouse = Settings.Default.CaptureMouse;
bool captureClick = Settings.Default.CaptureClick;
bool captureKeys = Settings.Default.CaptureKeys;

if (captureMouse || captureClick || captureKeys)
{
cursorCapture.CaptureRegion = CaptureRegion;
clickCapture.CaptureRegion = CaptureRegion;
keyCapture.Font = Settings.Default.KeyboardFont;

using (Graphics g = Graphics.FromImage(eventArgs.Frame))
{
g.CompositingQuality = CompositingQuality.HighSpeed;
g.SmoothingMode = SmoothingMode.HighSpeed;

float invWidth = 1; // / widthScale;
float invHeight = 1; // / heightScale;

if (captureMouse)
cursorCapture.Draw(g, invWidth, invHeight);

if (captureClick)
clickCapture.Draw(g, invWidth, invHeight);

if (captureKeys)
keyCapture.Draw(g, invWidth, invHeight);
}
}
})
);

// Save the just processed frame and mark it to be encoded in the next iteration:
lastFrame = eventArgs.Frame.Copy(lastFrame);

lastFrameRegion = new Rectangle(0, 0, eventArgs.FrameSize.Width, eventArgs.Frame.Height);
}

任何人都知道导致速度变慢的问题可能是什么?

编辑:

我想我设法找到了我的问题:
pts:4.032000e+003   pts_time:0.252  dts:2.016000e+003   dts_time:0.126  duration:6.720000e+002  duration_time:0.042 stream_index:0
pts:6.720000e+003 pts_time:0.42 dts:3.360000e+003 dts_time:0.21 duration:6.720000e+002 duration_time:0.042 stream_index:0
pts:1.075200e+004 pts_time:0.672 dts:5.376000e+003 dts_time:0.336 duration:6.720000e+002 duration_time:0.042 stream_index:0
pts:1.344000e+004 pts_time:0.84 dts:6.720000e+003 dts_time:0.42 duration:6.720000e+002 duration_time:0.042 stream_index:0
pts:1.612800e+004 pts_time:1.008 dts:8.064000e+003 dts_time:0.504 duration:6.720000e+002 duration_time:0.042 stream_index:0
pts:1.881600e+004 pts_time:1.176 dts:9.408000e+003 dts_time:0.588 duration:6.720000e+002 duration_time:0.042 stream_index:0
pts:2.150400e+004 pts_time:1.344 dts:1.075200e+004 dts_time:0.672 duration:6.720000e+002 duration_time:0.042 stream_index:0
pts:2.553600e+004 pts_time:1.596 dts:1.276800e+004 dts_time:0.798 duration:6.720000e+002 duration_time:0.042 stream_index:0
pts:2.822400e+004 pts_time:1.764 dts:1.411200e+004 dts_time:0.882 duration:6.720000e+002 duration_time:0.042 stream_index:0
pts:3.091200e+004 pts_time:1.932 dts:1.545600e+004 dts_time:0.966 duration:6.720000e+002 duration_time:0.042 stream_index:0
pts:3.494400e+004 pts_time:2.184 dts:1.747200e+004 dts_time:1.092 duration:6.720000e+002 duration_time:0.042 stream_index:0
pts:3.897600e+004 pts_time:2.436 dts:1.948800e+004 dts_time:1.218 duration:6.720000e+002 duration_time:0.042 stream_index:0
pts:4.166400e+004 pts_time:2.604 dts:2.083200e+004 dts_time:1.302 duration:6.720000e+002 duration_time:0.042 stream_index:0
pts:4.704000e+004 pts_time:2.94 dts:2.352000e+004 dts_time:1.47 duration:6.720000e+002 duration_time:0.042 stream_index:0
pts:5.107200e+004 pts_time:3.192 dts:2.553600e+004 dts_time:1.596 duration:6.720000e+002 duration_time:0.042 stream_index:0

PTS 始终是 DTS 的两倍,这就是视频以慢速呈现的原因。

不幸的是,我不知道为什么会发生这种情况......有人有任何线索吗?

最佳答案

这实际上是 alpha 版本中的一个错误。 See here for more information.

您始终可以编辑源代码并使用您添加的更正构建项目,但是,如果我正确理解许可证,这可能需要您发布您用作 LGPL 的任何代码。但请不要相信我的话,因为我不是律师。

避免法律问题的可能修复方法是仅降级到最后一个正式版本,因为那里不存在该错误。

关于c# - 视频时长是应有的两倍,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51385277/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com