Small fixes for the screen capture.

git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@1636 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
RKrom 2012-02-07 14:27:52 +00:00
commit b08c8991a5
3 changed files with 28 additions and 16 deletions

View file

@ -250,18 +250,18 @@ namespace Greenshot.Helpers {
info.rate = rate; info.rate = rate;
info.suggestedBufferSize = stride * height; info.suggestedBufferSize = stride * height;
// create stream
if (Avi32.AVIFileCreateStream(file, out stream, ref info) != 0) {
throw new ApplicationException("Failed creating stream");
}
// describe compression options // describe compression options
Avi32.AVICOMPRESSOPTIONS options = new Avi32.AVICOMPRESSOPTIONS(); Avi32.AVICOMPRESSOPTIONS options = new Avi32.AVICOMPRESSOPTIONS();
// create stream
if (Avi32.AVIFileCreateStream(file, out stream, ref info) != 0) {
throw new ApplicationException("Failed creating stream");
}
// uncomment if video settings dialog is required to show // uncomment if video settings dialog is required to show
int retCode = 0;
if (codec == null) { if (codec == null) {
int retCode = Avi32.AVISaveOptions( stream, ref options ); retCode = Avi32.AVISaveOptions( stream, ref options );
if (retCode == 0) { if (retCode == 0) {
LOG.Debug("Cancel clicked!"); LOG.Debug("Cancel clicked!");
return false; return false;
@ -270,7 +270,8 @@ namespace Greenshot.Helpers {
options.handler = Avi32.mmioFOURCC(codec); options.handler = Avi32.mmioFOURCC(codec);
options.quality = quality; options.quality = quality;
} }
// create compressed stream // create compressed stream
int retval = Avi32.AVIMakeCompressedStream(out streamCompressed, stream, ref options, IntPtr.Zero); int retval = Avi32.AVIMakeCompressedStream(out streamCompressed, stream, ref options, IntPtr.Zero);
if (retval != 0) { if (retval != 0) {
@ -320,6 +321,12 @@ namespace Greenshot.Helpers {
} }
} }
public void AddEmptyFrame() {
lock (this) {
position++;
}
}
/// <summary> /// <summary>
/// Add new frame to the AVI file. /// Add new frame to the AVI file.
/// </summary> /// </summary>

View file

@ -728,7 +728,7 @@ namespace Greenshot.Helpers {
} }
if (screenCapture != null) { if (screenCapture != null) {
screenCapture.RecordMouse = capture.CursorVisible; screenCapture.RecordMouse = capture.CursorVisible;
if (screenCapture.Start(15)) { if (screenCapture.Start(25)) {
return; return;
} }
// User clicked cancel or a problem occured // User clicked cancel or a problem occured

View file

@ -45,6 +45,7 @@ namespace Greenshot.Helpers {
private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(ScreenCaptureHelper)); private static log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(ScreenCaptureHelper));
private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>(); private static CoreConfiguration conf = IniConfig.GetIniSection<CoreConfiguration>();
private const int MAX_FRAMES = 500; private const int MAX_FRAMES = 500;
private const int ALIGNMENT = 8;
private IntPtr hWndDesktop = IntPtr.Zero; private IntPtr hWndDesktop = IntPtr.Zero;
private IntPtr hDCDesktop = IntPtr.Zero; private IntPtr hDCDesktop = IntPtr.Zero;
private IntPtr hDCDest = IntPtr.Zero; private IntPtr hDCDest = IntPtr.Zero;
@ -109,13 +110,13 @@ namespace Greenshot.Helpers {
LOG.InfoFormat("Starting recording rectangle {0}", recordingRectangle); LOG.InfoFormat("Starting recording rectangle {0}", recordingRectangle);
recordingSize = recordingRectangle.Size; recordingSize = recordingRectangle.Size;
} }
if (recordingSize.Width % 8 > 0) { if (recordingSize.Width % ALIGNMENT > 0) {
LOG.InfoFormat("Correcting width to be factor 8, {0} => {1}", recordingSize.Width, recordingSize.Width + (8-(recordingSize.Width % 8))); LOG.InfoFormat("Correcting width to be factor alignment, {0} => {1}", recordingSize.Width, recordingSize.Width + (ALIGNMENT - (recordingSize.Width % ALIGNMENT)));
recordingSize = new Size(recordingSize.Width + (8-(recordingSize.Width % 8)), recordingSize.Height); recordingSize = new Size(recordingSize.Width + (ALIGNMENT - (recordingSize.Width % ALIGNMENT)), recordingSize.Height);
} }
if (recordingSize.Height % 8 > 0) { if (recordingSize.Height % ALIGNMENT > 0) {
LOG.InfoFormat("Correcting Height to be factor 8, {0} => {1}", recordingSize.Height, recordingSize.Height + (8-(recordingSize.Height % 8))); LOG.InfoFormat("Correcting Height to be factor alignment, {0} => {1}", recordingSize.Height, recordingSize.Height + (ALIGNMENT - (recordingSize.Height % ALIGNMENT)));
recordingSize = new Size(recordingSize.Width, recordingSize.Height + (8-(recordingSize.Height % 8))); recordingSize = new Size(recordingSize.Width, recordingSize.Height + (ALIGNMENT - (recordingSize.Height % ALIGNMENT)));
} }
this.framesPerSecond = framesPerSecond; this.framesPerSecond = framesPerSecond;
// "P/Invoke" Solution for capturing the screen // "P/Invoke" Solution for capturing the screen
@ -224,7 +225,11 @@ namespace Greenshot.Helpers {
msToNextCapture = MSBETWEENCAPTURES; msToNextCapture = MSBETWEENCAPTURES;
} else { } else {
// Compensating // Compensating
msToNextCapture = Math.Max(0, MSBETWEENCAPTURES - sleeptime); do {
aviWriter.AddEmptyFrame();
sleeptime += MSBETWEENCAPTURES;
} while (sleeptime < 0);
msToNextCapture = sleeptime;
} }
} }
Cleanup(); Cleanup();