1000/60fpsミリ秒ごとウィンドウのスクリーンショットを取り、pngファイルとしてディレクトリに保存してから、VideoFileWriter
を使用して、それらの画像からAVIファイルを作成します。しかし、私はどのようにフレームレートを使用するべきではありません。どのように定義すればよいですか? width
またはheight
に基づいていますか?私はvirtualdub
で使用されているデフォルトのフレームレートをコピーしようとしましたが、1000であることがわかりました。私はそのレートを試しましたが、ビデオ出力はredicuosly slowでした。いくつかのドキュメントの例では25
を使用しています。私はそれをどのように定義するのか本当にわからない。pngファイルをビデオファイルに変換するために使用される適切なフレームレートは何ですか?
const int width = 1920;
const int height = 1080;
const int frameRate = 60;
using (var writer = new VideoFileWriter())
{
writer.Open("output.avi", width, height, frameRate, VideoCodec.MPEG4);
foreach (string file in Directory.EnumerateFiles(dest_path, "*.png"))
{
using (var img = (Bitmap)Image.FromFile(file))
{
writer.WriteVideoFrame(img);
}
}
}
コードscrenshotsを取るために使用される:、私はスクリーンショットを撮るためにタイマーを使用
int i = 0;
void doRecord()
{
using (var img = GetScreenshot(handle))
{
string filename = Path.Combine(dest_path, string.Format("{0}.png", ++i));
img.Save(filename, ImageFormat.Png);
}
}
public Bitmap GetScreenshot(IntPtr hwnd)
{
RECT rc;
if (!GetWindowRect(hwnd, out rc))
throw new Win32Exception(Marshal.GetLastWin32Error());
Bitmap bmp = new Bitmap(rc.right - rc.left, rc.bottom - rc.top, PixelFormat.Format32bppArgb);
using (var gfxBmp = Graphics.FromImage(bmp))
{
IntPtr hdcBitmap = gfxBmp.GetHdc();
bool succeeded = PrintWindow(hwnd, hdcBitmap, 0);
gfxBmp.ReleaseHdc(hdcBitmap);
if (!succeeded)
{
gfxBmp.FillRectangle(new SolidBrush(Color.Gray), new Rectangle(Point.Empty, bmp.Size));
}
IntPtr hRgn = CreateRectRgn(0, 0, 0, 0);
GetWindowRgn(hwnd, hRgn);
Region region = Region.FromHrgn(hRgn);
if (!region.IsEmpty(gfxBmp))
{
gfxBmp.ExcludeClip(region);
gfxBmp.Clear(Color.Transparent);
}
return bmp;
}
}
次のように設定します
const int fps = 60;
timer1.Interval = 1000/fps;
timer1.Start();
と
private void timer1_Tick(object sender, EventArgs e)
{
doRecord();
}
私の理解では、平均的なモニタは60Hzで動作しますので、1/60秒間のスクリーンショットを撮ってください。 (これはあなたが求めているものですか?また、それを「定義する」とはどういう意味ですか?) – Eric
私はすでに1/60秒でスクリーンショットを撮っています。私の質問は 'VideoFileWriter'から' Open() 'メソッドで渡されたフレームレートを定義する方法です。 60も1/60も、「通常の」ビデオ速度にはなりませんでした。それは速すぎた。 – Jack