mirror of
https://github.com/greenshot/greenshot
synced 2025-08-19 21:13:23 -07:00
Small changes in unused code, for cleanup.
git-svn-id: http://svn.code.sf.net/p/greenshot/code/trunk@2363 7dccd23d-a4a3-4e1f-8c07-b4c1b4018ab4
This commit is contained in:
parent
d7af595d0d
commit
69754804a0
2 changed files with 1108 additions and 881 deletions
|
@ -12,6 +12,8 @@ using System.Drawing.Imaging;
|
||||||
using System.Runtime.InteropServices;
|
using System.Runtime.InteropServices;
|
||||||
|
|
||||||
using GreenshotPlugin.UnmanagedHelpers;
|
using GreenshotPlugin.UnmanagedHelpers;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
|
||||||
namespace Greenshot.Helpers {
|
namespace Greenshot.Helpers {
|
||||||
|
|
||||||
|
@ -72,7 +74,9 @@ namespace Greenshot.Helpers {
|
||||||
/// method.</para></remarks>
|
/// method.</para></remarks>
|
||||||
///
|
///
|
||||||
public int Width {
|
public int Width {
|
||||||
get { return width; }
|
get {
|
||||||
|
return width;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -84,7 +88,9 @@ namespace Greenshot.Helpers {
|
||||||
/// method.</para></remarks>
|
/// method.</para></remarks>
|
||||||
///
|
///
|
||||||
public int Height {
|
public int Height {
|
||||||
get { return height; }
|
get {
|
||||||
|
return height;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -94,9 +100,10 @@ namespace Greenshot.Helpers {
|
||||||
/// <remarks><para>The property tell current position in video stream, which actually equals
|
/// <remarks><para>The property tell current position in video stream, which actually equals
|
||||||
/// to the amount of frames added using <see cref="AddFrame"/> method.</para></remarks>
|
/// to the amount of frames added using <see cref="AddFrame"/> method.</para></remarks>
|
||||||
///
|
///
|
||||||
public int Position
|
public int Position {
|
||||||
{
|
get {
|
||||||
get { return position; }
|
return position;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -110,10 +117,13 @@ namespace Greenshot.Helpers {
|
||||||
///
|
///
|
||||||
/// <para>Default frame rate is set to <b>25</b>.</para></remarks>
|
/// <para>Default frame rate is set to <b>25</b>.</para></remarks>
|
||||||
///
|
///
|
||||||
public int FrameRate
|
public int FrameRate {
|
||||||
{
|
get {
|
||||||
get { return rate; }
|
return rate;
|
||||||
set { rate = value; }
|
}
|
||||||
|
set {
|
||||||
|
rate = value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -127,10 +137,13 @@ namespace Greenshot.Helpers {
|
||||||
///
|
///
|
||||||
/// <para>Default video codec is set <b>"DIB "</b>, which means no compression.</para></remarks>
|
/// <para>Default video codec is set <b>"DIB "</b>, which means no compression.</para></remarks>
|
||||||
///
|
///
|
||||||
public string Codec
|
public string Codec {
|
||||||
{
|
get {
|
||||||
get { return codec; }
|
return codec;
|
||||||
set { codec = value; }
|
}
|
||||||
|
set {
|
||||||
|
codec = value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -144,10 +157,13 @@ namespace Greenshot.Helpers {
|
||||||
///
|
///
|
||||||
/// <para>Default value is set to <b>-1</b> - default compression quality of the codec.</para></remarks>
|
/// <para>Default value is set to <b>-1</b> - default compression quality of the codec.</para></remarks>
|
||||||
///
|
///
|
||||||
public int Quality
|
public int Quality {
|
||||||
{
|
get {
|
||||||
get { return quality; }
|
return quality;
|
||||||
set { quality = value; }
|
}
|
||||||
|
set {
|
||||||
|
quality = value;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -168,7 +184,8 @@ namespace Greenshot.Helpers {
|
||||||
///
|
///
|
||||||
/// <remarks>Initializes Video for Windows library.</remarks>
|
/// <remarks>Initializes Video for Windows library.</remarks>
|
||||||
///
|
///
|
||||||
public AVIWriter(string codec) : this() {
|
public AVIWriter(string codec)
|
||||||
|
: this() {
|
||||||
this.codec = codec;
|
this.codec = codec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -226,12 +243,8 @@ namespace Greenshot.Helpers {
|
||||||
lock (this) {
|
lock (this) {
|
||||||
// calculate stride
|
// calculate stride
|
||||||
stride = width * 4;
|
stride = width * 4;
|
||||||
if ((stride % 4) != 0)
|
if ((stride % 4) != 0) {
|
||||||
stride += (4 - stride % 4);
|
stride += (4 - stride % 4);
|
||||||
|
|
||||||
// create new file
|
|
||||||
if (Avi32.AVIFileOpen(out file, fileName, Avi32.OpenFileMode.Create | Avi32.OpenFileMode.Write, IntPtr.Zero) != 0) {
|
|
||||||
throw new ApplicationException("Failed opening file");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.width = width;
|
this.width = width;
|
||||||
|
@ -240,6 +253,8 @@ namespace Greenshot.Helpers {
|
||||||
// describe new stream
|
// describe new stream
|
||||||
Avi32.AVISTREAMINFO info = new Avi32.AVISTREAMINFO();
|
Avi32.AVISTREAMINFO info = new Avi32.AVISTREAMINFO();
|
||||||
|
|
||||||
|
LOG.InfoFormat("Available codecs: {0}", String.Join(", ", Avi32.AvailableCodecs.ToArray()));
|
||||||
|
|
||||||
info.type = Avi32.mmioFOURCC("vids");
|
info.type = Avi32.mmioFOURCC("vids");
|
||||||
if (codec != null) {
|
if (codec != null) {
|
||||||
info.handler = Avi32.mmioFOURCC(codec);
|
info.handler = Avi32.mmioFOURCC(codec);
|
||||||
|
@ -250,14 +265,19 @@ namespace Greenshot.Helpers {
|
||||||
info.rate = rate;
|
info.rate = rate;
|
||||||
info.suggestedBufferSize = stride * height;
|
info.suggestedBufferSize = stride * height;
|
||||||
|
|
||||||
// describe compression options
|
try {
|
||||||
Avi32.AVICOMPRESSOPTIONS options = new Avi32.AVICOMPRESSOPTIONS();
|
// create new file
|
||||||
|
if (Avi32.AVIFileOpen(out file, fileName, Avi32.OpenFileMode.Create | Avi32.OpenFileMode.Write, IntPtr.Zero) != 0) {
|
||||||
|
throw new ApplicationException("Failed opening file");
|
||||||
|
}
|
||||||
|
|
||||||
// create stream
|
// create stream
|
||||||
if (Avi32.AVIFileCreateStream(file, out stream, ref info) != 0) {
|
if (Avi32.AVIFileCreateStream(file, out stream, ref info) != 0) {
|
||||||
throw new ApplicationException("Failed creating stream");
|
throw new ApplicationException("Failed creating stream");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// describe compression options
|
||||||
|
Avi32.AVICOMPRESSOPTIONS options = new Avi32.AVICOMPRESSOPTIONS();
|
||||||
// uncomment if video settings dialog is required to show
|
// uncomment if video settings dialog is required to show
|
||||||
int retCode = 0;
|
int retCode = 0;
|
||||||
if (codec == null) {
|
if (codec == null) {
|
||||||
|
@ -266,28 +286,49 @@ namespace Greenshot.Helpers {
|
||||||
LOG.Debug("Cancel clicked!");
|
LOG.Debug("Cancel clicked!");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
codec = Avi32.decode_mmioFOURCC(options.handler);
|
||||||
|
quality = options.quality;
|
||||||
} else {
|
} else {
|
||||||
options.handler = Avi32.mmioFOURCC(codec);
|
options.handler = Avi32.mmioFOURCC(codec);
|
||||||
options.quality = quality;
|
options.quality = quality;
|
||||||
}
|
}
|
||||||
|
LOG.DebugFormat("Codec {0} selected with quality {1}.", codec, quality);
|
||||||
|
|
||||||
|
AviError retval;
|
||||||
// create compressed stream
|
// create compressed stream
|
||||||
int retval = Avi32.AVIMakeCompressedStream(out streamCompressed, stream, ref options, IntPtr.Zero);
|
try {
|
||||||
if (retval != 0) {
|
retval = Avi32.AVIMakeCompressedStream(out streamCompressed, stream, ref options, IntPtr.Zero);
|
||||||
throw new ApplicationException("Failed creating compressed stream: " + retval);
|
} catch (Exception exCompress) {
|
||||||
|
LOG.Warn("Couldn't use compressed stream.", exCompress);
|
||||||
|
retval = AviError.AVIERR_OK;
|
||||||
}
|
}
|
||||||
|
if (retval != AviError.AVIERR_OK) {
|
||||||
|
throw new ApplicationException(string.Format("Failed creating compressed stream: {0}", retval));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// describe frame format
|
// describe frame format
|
||||||
BitmapInfoHeader bitmapInfoHeader = new BitmapInfoHeader(width, height, 32);
|
BitmapInfoHeader bitmapInfoHeader = new BitmapInfoHeader(width, height, 32);
|
||||||
|
|
||||||
// set frame format
|
// set frame format
|
||||||
|
if (streamCompressed != IntPtr.Zero) {
|
||||||
retval = Avi32.AVIStreamSetFormat(streamCompressed, 0, ref bitmapInfoHeader, Marshal.SizeOf(bitmapInfoHeader.GetType()));
|
retval = Avi32.AVIStreamSetFormat(streamCompressed, 0, ref bitmapInfoHeader, Marshal.SizeOf(bitmapInfoHeader.GetType()));
|
||||||
|
} else {
|
||||||
|
retval = Avi32.AVIStreamSetFormat(stream, 0, ref bitmapInfoHeader, Marshal.SizeOf(bitmapInfoHeader.GetType()));
|
||||||
|
}
|
||||||
if (retval != 0) {
|
if (retval != 0) {
|
||||||
throw new ApplicationException("Failed creating compressed stream: "+ retval);
|
throw new ApplicationException(string.Format("Failed creating stream: {0}", retval));
|
||||||
}
|
}
|
||||||
position = 0;
|
position = 0;
|
||||||
return true;
|
return true;
|
||||||
|
} catch (Exception ex) {
|
||||||
|
Close();
|
||||||
|
Avi32.AVIFileExit();
|
||||||
|
if (File.Exists(fileName)) {
|
||||||
|
File.Delete(fileName);
|
||||||
|
}
|
||||||
|
throw ex;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -350,19 +391,19 @@ namespace Greenshot.Helpers {
|
||||||
/// <remarks>The class provides Video for Windows and some other Avi32 functions and structurs.</remarks>
|
/// <remarks>The class provides Video for Windows and some other Avi32 functions and structurs.</remarks>
|
||||||
///
|
///
|
||||||
internal static class Avi32 {
|
internal static class Avi32 {
|
||||||
/// <summary>
|
private static readonly log4net.ILog LOG = log4net.LogManager.GetLogger(typeof(Avi32));
|
||||||
/// Copy a block of memory.
|
|
||||||
/// </summary>
|
|
||||||
///
|
|
||||||
/// <param name="dst">Destination pointer.</param>
|
|
||||||
/// <param name="src">Source pointer.</param>
|
|
||||||
/// <param name="count">Memory block's length to copy.</param>
|
|
||||||
///
|
|
||||||
/// <returns>Return's the value of <b>dst</b> - pointer to destination.</returns>
|
|
||||||
///
|
|
||||||
[DllImport("ntdll.dll")]
|
|
||||||
public static extern int memcpy(int dst, int src, int count);
|
|
||||||
|
|
||||||
|
[DllImport("MSVFW32", CharSet = CharSet.Ansi)]
|
||||||
|
static extern bool ICInfo(int fccType, int fccHandler, ref ICINFO lpicinfo);
|
||||||
|
|
||||||
|
[DllImport("MSVFW32"), PreserveSig]
|
||||||
|
static extern IntPtr ICOpen(int fccType, int fccHandler, ICMODE wMode);
|
||||||
|
|
||||||
|
[DllImport("MSVFW32")]
|
||||||
|
static extern int ICClose(IntPtr hic);
|
||||||
|
|
||||||
|
[DllImport("MSVFW32", CharSet = CharSet.Ansi)]
|
||||||
|
static extern int ICGetInfo(IntPtr hic, ref ICINFO lpicinfo, int cb);
|
||||||
|
|
||||||
// --- Video for Windows Functions
|
// --- Video for Windows Functions
|
||||||
|
|
||||||
|
@ -370,13 +411,13 @@ namespace Greenshot.Helpers {
|
||||||
/// Initialize the AVIFile library.
|
/// Initialize the AVIFile library.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
///
|
///
|
||||||
[DllImport("avifil32.dll")]
|
[DllImport("avifil32")]
|
||||||
public static extern void AVIFileInit();
|
public static extern void AVIFileInit();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Exit the AVIFile library.
|
/// Exit the AVIFile library.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
[DllImport("avifil32.dll")]
|
[DllImport("avifil32")]
|
||||||
public static extern void AVIFileExit();
|
public static extern void AVIFileExit();
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -390,8 +431,8 @@ namespace Greenshot.Helpers {
|
||||||
///
|
///
|
||||||
/// <returns>Returns zero on success or error code otherwise.</returns>
|
/// <returns>Returns zero on success or error code otherwise.</returns>
|
||||||
///
|
///
|
||||||
[DllImport("avifil32.dll", CharSet = CharSet.Unicode)]
|
[DllImport("avifil32", CharSet = CharSet.Unicode)]
|
||||||
public static extern int AVIFileOpen(out IntPtr aviHandler, String fileName, OpenFileMode mode, IntPtr handler);
|
public static extern AviError AVIFileOpen(out IntPtr aviHandler, String fileName, OpenFileMode mode, IntPtr handler);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Release an open AVI stream.
|
/// Release an open AVI stream.
|
||||||
|
@ -401,7 +442,7 @@ namespace Greenshot.Helpers {
|
||||||
///
|
///
|
||||||
/// <returns>Returns the reference count of the file.</returns>
|
/// <returns>Returns the reference count of the file.</returns>
|
||||||
///
|
///
|
||||||
[DllImport("avifil32.dll")]
|
[DllImport("avifil32")]
|
||||||
public static extern int AVIFileRelease(IntPtr aviHandler);
|
public static extern int AVIFileRelease(IntPtr aviHandler);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -415,7 +456,7 @@ namespace Greenshot.Helpers {
|
||||||
///
|
///
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
///
|
///
|
||||||
[DllImport("avifil32.dll")]
|
[DllImport("avifil32")]
|
||||||
public static extern int AVIFileGetStream(IntPtr aviHandler, out IntPtr streamHandler, int streamType, int streamNumner);
|
public static extern int AVIFileGetStream(IntPtr aviHandler, out IntPtr streamHandler, int streamType, int streamNumner);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -428,7 +469,7 @@ namespace Greenshot.Helpers {
|
||||||
///
|
///
|
||||||
/// <returns>Returns zero if successful or an error otherwise.</returns>
|
/// <returns>Returns zero if successful or an error otherwise.</returns>
|
||||||
///
|
///
|
||||||
[DllImport("avifil32.dll")]
|
[DllImport("avifil32")]
|
||||||
public static extern int AVIFileCreateStream(IntPtr aviHandler, out IntPtr streamHandler, ref AVISTREAMINFO streamInfo);
|
public static extern int AVIFileCreateStream(IntPtr aviHandler, out IntPtr streamHandler, ref AVISTREAMINFO streamInfo);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -439,7 +480,7 @@ namespace Greenshot.Helpers {
|
||||||
///
|
///
|
||||||
/// <returns>Returns the current reference count of the stream.</returns>
|
/// <returns>Returns the current reference count of the stream.</returns>
|
||||||
///
|
///
|
||||||
[DllImport("avifil32.dll")]
|
[DllImport("avifil32")]
|
||||||
public static extern int AVIStreamRelease(IntPtr streamHandler);
|
public static extern int AVIStreamRelease(IntPtr streamHandler);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -453,8 +494,8 @@ namespace Greenshot.Helpers {
|
||||||
///
|
///
|
||||||
/// <returns>Returns zero if successful or an error otherwise.</returns>
|
/// <returns>Returns zero if successful or an error otherwise.</returns>
|
||||||
///
|
///
|
||||||
[DllImport("avifil32.dll")]
|
[DllImport("avifil32")]
|
||||||
public static extern int AVIStreamSetFormat(IntPtr streamHandler, int position, ref BitmapInfoHeader format, int formatSize);
|
public static extern AviError AVIStreamSetFormat(IntPtr streamHandler, int position, ref BitmapInfoHeader format, int formatSize);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get the starting sample number for the stream.
|
/// Get the starting sample number for the stream.
|
||||||
|
@ -464,7 +505,7 @@ namespace Greenshot.Helpers {
|
||||||
///
|
///
|
||||||
/// <returns>Returns the number if successful or – 1 otherwise.</returns>
|
/// <returns>Returns the number if successful or – 1 otherwise.</returns>
|
||||||
///
|
///
|
||||||
[DllImport("avifil32.dll")]
|
[DllImport("avifil32")]
|
||||||
public static extern int AVIStreamStart(IntPtr streamHandler);
|
public static extern int AVIStreamStart(IntPtr streamHandler);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -472,7 +513,7 @@ namespace Greenshot.Helpers {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="streamHandler">Handle to an open stream.</param>
|
/// <param name="streamHandler">Handle to an open stream.</param>
|
||||||
/// <returns>Returns the stream's length, in samples, if successful or -1 otherwise. </returns>
|
/// <returns>Returns the stream's length, in samples, if successful or -1 otherwise. </returns>
|
||||||
[DllImport("avifil32.dll")]
|
[DllImport("avifil32")]
|
||||||
public static extern int AVIStreamLength(IntPtr streamHandler);
|
public static extern int AVIStreamLength(IntPtr streamHandler);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -485,7 +526,7 @@ namespace Greenshot.Helpers {
|
||||||
///
|
///
|
||||||
/// <returns>Returns zero if successful or an error otherwise.</returns>
|
/// <returns>Returns zero if successful or an error otherwise.</returns>
|
||||||
///
|
///
|
||||||
[DllImport("avifil32.dll", CharSet = CharSet.Unicode)]
|
[DllImport("avifil32", CharSet = CharSet.Unicode)]
|
||||||
public static extern int AVIStreamInfo(IntPtr streamHandler, ref AVISTREAMINFO streamInfo, int infoSize);
|
public static extern int AVIStreamInfo(IntPtr streamHandler, ref AVISTREAMINFO streamInfo, int infoSize);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -494,7 +535,7 @@ namespace Greenshot.Helpers {
|
||||||
/// <param name="streamHandler">Pointer to the video stream used as the video source.</param>
|
/// <param name="streamHandler">Pointer to the video stream used as the video source.</param>
|
||||||
/// <param name="wantedFormat">Pointer to a structure that defines the desired video format. Specify NULL to use a default format.</param>
|
/// <param name="wantedFormat">Pointer to a structure that defines the desired video format. Specify NULL to use a default format.</param>
|
||||||
/// <returns>Returns an object that can be used with the <see cref="AVIStreamGetFrame"/> function.</returns>
|
/// <returns>Returns an object that can be used with the <see cref="AVIStreamGetFrame"/> function.</returns>
|
||||||
[DllImport("avifil32.dll")]
|
[DllImport("avifil32")]
|
||||||
public static extern IntPtr AVIStreamGetFrameOpen(IntPtr streamHandler, ref BitmapInfoHeader wantedFormat);
|
public static extern IntPtr AVIStreamGetFrameOpen(IntPtr streamHandler, ref BitmapInfoHeader wantedFormat);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -503,7 +544,7 @@ namespace Greenshot.Helpers {
|
||||||
/// <param name="streamHandler">Pointer to the video stream used as the video source.</param>
|
/// <param name="streamHandler">Pointer to the video stream used as the video source.</param>
|
||||||
/// <param name="wantedFormat">Pointer to a structure that defines the desired video format. Specify NULL to use a default format.</param>
|
/// <param name="wantedFormat">Pointer to a structure that defines the desired video format. Specify NULL to use a default format.</param>
|
||||||
/// <returns>Returns a <b>GetFrame</b> object that can be used with the <see cref="AVIStreamGetFrame"/> function.</returns>
|
/// <returns>Returns a <b>GetFrame</b> object that can be used with the <see cref="AVIStreamGetFrame"/> function.</returns>
|
||||||
[DllImport("avifil32.dll")]
|
[DllImport("avifil32")]
|
||||||
public static extern IntPtr AVIStreamGetFrameOpen(IntPtr streamHandler, int wantedFormat);
|
public static extern IntPtr AVIStreamGetFrameOpen(IntPtr streamHandler, int wantedFormat);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -511,7 +552,7 @@ namespace Greenshot.Helpers {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="getFrameObject">Handle returned from the <see cref="AVIStreamGetFrameOpen(IntPtr,int)"/> function.</param>
|
/// <param name="getFrameObject">Handle returned from the <see cref="AVIStreamGetFrameOpen(IntPtr,int)"/> function.</param>
|
||||||
/// <returns>Returns zero if successful or an error otherwise.</returns>
|
/// <returns>Returns zero if successful or an error otherwise.</returns>
|
||||||
[DllImport("avifil32.dll")]
|
[DllImport("avifil32")]
|
||||||
public static extern int AVIStreamGetFrameClose(IntPtr getFrameObject);
|
public static extern int AVIStreamGetFrameClose(IntPtr getFrameObject);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -520,7 +561,7 @@ namespace Greenshot.Helpers {
|
||||||
/// <param name="getFrameObject">Pointer to a GetFrame object.</param>
|
/// <param name="getFrameObject">Pointer to a GetFrame object.</param>
|
||||||
/// <param name="position">Position, in samples, within the stream of the desired frame.</param>
|
/// <param name="position">Position, in samples, within the stream of the desired frame.</param>
|
||||||
/// <returns>Returns a pointer to the frame data if successful or NULL otherwise.</returns>
|
/// <returns>Returns a pointer to the frame data if successful or NULL otherwise.</returns>
|
||||||
[DllImport("avifil32.dll")]
|
[DllImport("avifil32")]
|
||||||
public static extern IntPtr AVIStreamGetFrame(IntPtr getFrameObject, int position);
|
public static extern IntPtr AVIStreamGetFrame(IntPtr getFrameObject, int position);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -537,8 +578,8 @@ namespace Greenshot.Helpers {
|
||||||
///
|
///
|
||||||
/// <returns>Returns zero if successful or an error otherwise.</returns>
|
/// <returns>Returns zero if successful or an error otherwise.</returns>
|
||||||
///
|
///
|
||||||
[DllImport("avifil32.dll")]
|
[DllImport("avifil32")]
|
||||||
public static extern int AVIStreamWrite(IntPtr streamHandler, int start, int samples, IntPtr buffer, int bufferSize, int flags, IntPtr samplesWritten, IntPtr bytesWritten);
|
public static extern AviError AVIStreamWrite(IntPtr streamHandler, int start, int samples, IntPtr buffer, int bufferSize, int flags, IntPtr samplesWritten, IntPtr bytesWritten);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Retrieve the save options for a file and returns them in a buffer.
|
/// Retrieve the save options for a file and returns them in a buffer.
|
||||||
|
@ -549,7 +590,7 @@ namespace Greenshot.Helpers {
|
||||||
/// <param name="streamInterfaces">Pointer to an array of stream interface pointers.</param>
|
/// <param name="streamInterfaces">Pointer to an array of stream interface pointers.</param>
|
||||||
/// <param name="options">Pointer to an array of pointers to AVICOMPRESSOPTIONS structures.</param>
|
/// <param name="options">Pointer to an array of pointers to AVICOMPRESSOPTIONS structures.</param>
|
||||||
/// <returns>Returns TRUE if the user pressed OK, FALSE for CANCEL, or an error otherwise.</returns>
|
/// <returns>Returns TRUE if the user pressed OK, FALSE for CANCEL, or an error otherwise.</returns>
|
||||||
[DllImport("avifil32.dll")]
|
[DllImport("avifil32")]
|
||||||
public static extern int AVISaveOptions(IntPtr window, int flags, int streams, [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] IntPtr[] streamInterfaces, [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] IntPtr[] options);
|
public static extern int AVISaveOptions(IntPtr window, int flags, int streams, [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] IntPtr[] streamInterfaces, [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] IntPtr[] options);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
@ -558,8 +599,8 @@ namespace Greenshot.Helpers {
|
||||||
/// <param name="streams">Count of the AVICOMPRESSOPTIONS structures referenced in <b>options</b>.</param>
|
/// <param name="streams">Count of the AVICOMPRESSOPTIONS structures referenced in <b>options</b>.</param>
|
||||||
/// <param name="options">Pointer to an array of pointers to AVICOMPRESSOPTIONS structures.</param>
|
/// <param name="options">Pointer to an array of pointers to AVICOMPRESSOPTIONS structures.</param>
|
||||||
/// <returns>Returns 0.</returns>
|
/// <returns>Returns 0.</returns>
|
||||||
[DllImport("avifil32.dll")]
|
[DllImport("avifil32")]
|
||||||
public static extern int AVISaveOptionsFree(int streams, [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] IntPtr[] options);
|
public static extern AviError AVISaveOptionsFree(int streams, [In, MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 0)] IntPtr[] options);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Create a compressed stream from an uncompressed stream and a
|
/// Create a compressed stream from an uncompressed stream and a
|
||||||
|
@ -571,18 +612,61 @@ namespace Greenshot.Helpers {
|
||||||
/// <param name="options">Pointer to a structure that identifies the type of compression to use and the options to apply.</param>
|
/// <param name="options">Pointer to a structure that identifies the type of compression to use and the options to apply.</param>
|
||||||
/// <param name="clsidHandler">Pointer to a class identifier used to create the stream.</param>
|
/// <param name="clsidHandler">Pointer to a class identifier used to create the stream.</param>
|
||||||
/// <returns>Returns 0 if successful or an error otherwise.</returns>
|
/// <returns>Returns 0 if successful or an error otherwise.</returns>
|
||||||
[DllImport("avifil32.dll")]
|
[DllImport("avifil32")]
|
||||||
public static extern int AVIMakeCompressedStream(out IntPtr compressedStream, IntPtr sourceStream, ref AVICOMPRESSOPTIONS options, IntPtr clsidHandler);
|
public static extern AviError AVIMakeCompressedStream(out IntPtr compressedStream, IntPtr sourceStream, ref AVICOMPRESSOPTIONS options, IntPtr clsidHandler);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Code type
|
||||||
|
/// </summary>
|
||||||
|
public enum ICMODE {
|
||||||
|
ICMODE_COMPRESS = 1,
|
||||||
|
ICMODE_DECOMPRESS = 2,
|
||||||
|
ICMODE_FASTDECOMPRESS = 3,
|
||||||
|
ICMODE_QUERY = 4,
|
||||||
|
ICMODE_FASTCOMPRESS = 5,
|
||||||
|
ICMODE_DRAW = 8
|
||||||
|
}
|
||||||
|
|
||||||
// --- structures
|
// --- structures
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Structor for the codec info
|
||||||
|
/// See: http://msdn.microsoft.com/en-us/library/windows/desktop/dd743162%28v=vs.85%29.aspx
|
||||||
|
/// </summary>
|
||||||
|
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
|
||||||
|
public struct ICINFO {
|
||||||
|
public int dwSize;
|
||||||
|
public int fccType;
|
||||||
|
public int fccHandler;
|
||||||
|
public int dwFlags;
|
||||||
|
public int dwVersion;
|
||||||
|
public int dwVersionICM;
|
||||||
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 16)]
|
||||||
|
public string szName;
|
||||||
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
|
||||||
|
public string szDescription;
|
||||||
|
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 128)]
|
||||||
|
public string szDriver;
|
||||||
|
|
||||||
|
public ICINFO(int type) {
|
||||||
|
dwSize = Marshal.SizeOf(typeof(ICINFO));
|
||||||
|
fccType = type;
|
||||||
|
fccHandler = 0;
|
||||||
|
dwFlags = 0;
|
||||||
|
dwVersion = 0;
|
||||||
|
dwVersionICM = 0;
|
||||||
|
szName = null;
|
||||||
|
szDescription = null;
|
||||||
|
szDriver = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Structure, which contains information for a single stream .
|
/// Structure, which contains information for a single stream .
|
||||||
/// </summary>
|
/// </summary>
|
||||||
///
|
///
|
||||||
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode, Pack = 1)]
|
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode, Pack = 1)]
|
||||||
public struct AVISTREAMINFO
|
public struct AVISTREAMINFO {
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Four-character code indicating the stream type.
|
/// Four-character code indicating the stream type.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -721,8 +805,7 @@ namespace Greenshot.Helpers {
|
||||||
/// </summary>
|
/// </summary>
|
||||||
///
|
///
|
||||||
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
[StructLayout(LayoutKind.Sequential, Pack = 1)]
|
||||||
public struct AVICOMPRESSOPTIONS
|
public struct AVICOMPRESSOPTIONS {
|
||||||
{
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Four-character code indicating the stream type.
|
/// Four-character code indicating the stream type.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -861,6 +944,34 @@ namespace Greenshot.Helpers {
|
||||||
return new string(chs);
|
return new string(chs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Get a list of available codecs.
|
||||||
|
/// </summary>
|
||||||
|
/// <returns>List<string></returns>
|
||||||
|
public static List<string> AvailableCodecs {
|
||||||
|
get {
|
||||||
|
List<string> returnValues = new List<string>();
|
||||||
|
int codecNr = 0;
|
||||||
|
|
||||||
|
ICINFO codecInfo = new ICINFO(mmioFOURCC("VIDC"));
|
||||||
|
|
||||||
|
bool success = true;
|
||||||
|
do {
|
||||||
|
success = ICInfo(codecInfo.fccType, codecNr++, ref codecInfo);
|
||||||
|
if (success) {
|
||||||
|
IntPtr hic = ICOpen(codecInfo.fccType, codecInfo.fccHandler, ICMODE.ICMODE_QUERY);
|
||||||
|
if (hic != IntPtr.Zero) {
|
||||||
|
ICGetInfo(hic, ref codecInfo, Marshal.SizeOf(codecInfo));
|
||||||
|
string codecName = decode_mmioFOURCC(codecInfo.fccHandler);
|
||||||
|
returnValues.Add(codecName);
|
||||||
|
LOG.DebugFormat("Found codec {0} {4}, with name {1} and description {2}, driver {3}", codecName, codecInfo.szName, codecInfo.szDescription, codecInfo.szDriver, codecInfo.dwVersion);
|
||||||
|
ICClose(hic);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} while (success);
|
||||||
|
return returnValues;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Version of <see cref="AVISaveOptions(IntPtr, int, int, IntPtr[], IntPtr[])"/> for one stream only.
|
/// Version of <see cref="AVISaveOptions(IntPtr, int, int, IntPtr[], IntPtr[])"/> for one stream only.
|
||||||
|
@ -905,4 +1016,106 @@ namespace Greenshot.Helpers {
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// AVI Error Codes
|
||||||
|
/// </summary>
|
||||||
|
[Flags]
|
||||||
|
public enum AviError : uint {
|
||||||
|
/// <summary>
|
||||||
|
/// Compression is not supported for this type of data.
|
||||||
|
/// This error might be returned if you try to compress
|
||||||
|
/// data that is not audio or video.
|
||||||
|
/// </summary>
|
||||||
|
AVIERR_UNSUPPORTED = 0x80044065,
|
||||||
|
/// <summary>
|
||||||
|
/// The file couldn't be read, indicating a corrupt file or an unrecognized format
|
||||||
|
/// </summary>
|
||||||
|
AVIERR_BADFORMAT = 0x80044066,
|
||||||
|
/// <summary>
|
||||||
|
/// There is not enough memory to complete the operation.
|
||||||
|
/// </summary>
|
||||||
|
AVIERR_MEMORY = 0x80044067,
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
// TODO : Put documentation
|
||||||
|
AVIERR_INTERNAL = 0x80044068,
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
// TODO : Put documentation
|
||||||
|
AVIERR_BADFLAGS = 0x80044069,
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
// TODO : Put documentation
|
||||||
|
AVIERR_BADPARAM = 0x8004406A,
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
// TODO : Put documentation
|
||||||
|
AVIERR_BADSIZE = 0x8004406B,
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
// TODO : Put documentation
|
||||||
|
AVIERR_BADHANDLE = 0x8004406C,
|
||||||
|
/// <summary>
|
||||||
|
/// A disk error occurred while reading the file
|
||||||
|
/// </summary>
|
||||||
|
AVIERR_FILEREAD = 0x8004406D,
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
// TODO : Put documentation
|
||||||
|
AVIERR_FILEWRITE = 0x8004406E,
|
||||||
|
/// <summary>
|
||||||
|
/// A disk error occurred while opening the file
|
||||||
|
/// </summary>
|
||||||
|
AVIERR_FILEOPEN = 0x8004406F,
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
// TODO : Put documentation
|
||||||
|
AVIERR_COMPRESSOR = 0x80044070,
|
||||||
|
/// <summary>
|
||||||
|
/// A suitable compressor cannot be found.
|
||||||
|
/// </summary>
|
||||||
|
AVIERR_NOCOMPRESSOR = 0x80044071,
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
// TODO : Put documentation
|
||||||
|
AVIERR_READONLY = 0x80044072,
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
// TODO : Put documentation
|
||||||
|
AVIERR_NODATA = 0x80044073,
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
// TODO : Put documentation
|
||||||
|
AVIERR_BUFFERTOOSMALL = 0x80044074,
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
// TODO : Put documentation
|
||||||
|
AVIERR_CANTCOMPRESS = 0x80044075,
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
// TODO : Put documentation
|
||||||
|
AVIERR_USERABORT = 0x800440C6,
|
||||||
|
/// <summary>
|
||||||
|
///
|
||||||
|
/// </summary>
|
||||||
|
// TODO : Put documentation
|
||||||
|
AVIERR_ERROR = 0x800440C7,
|
||||||
|
/// <summary>
|
||||||
|
/// Operation successful
|
||||||
|
/// </summary>
|
||||||
|
AVIERR_OK = 0x0
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,6 +93,11 @@ namespace Greenshot.Helpers {
|
||||||
return exceptionToThrow;
|
return exceptionToThrow;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Start the recording
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="framesPerSecond"></param>
|
||||||
|
/// <returns></returns>
|
||||||
public bool Start(int framesPerSecond) {
|
public bool Start(int framesPerSecond) {
|
||||||
if (recordingWindow != null) {
|
if (recordingWindow != null) {
|
||||||
string windowTitle = Regex.Replace(recordingWindow.Text, @"[^\x20\d\w]", "");
|
string windowTitle = Regex.Replace(recordingWindow.Text, @"[^\x20\d\w]", "");
|
||||||
|
@ -176,8 +181,8 @@ namespace Greenshot.Helpers {
|
||||||
|
|
||||||
aviWriter = new AVIWriter();
|
aviWriter = new AVIWriter();
|
||||||
// Comment the following 2 lines to make the user select it's own codec
|
// Comment the following 2 lines to make the user select it's own codec
|
||||||
//aviWriter.Codec = "msvc";
|
aviWriter.Codec = "msvc";
|
||||||
//aviWriter.Quality = 99;
|
aviWriter.Quality = 10000;
|
||||||
|
|
||||||
aviWriter.FrameRate = framesPerSecond;
|
aviWriter.FrameRate = framesPerSecond;
|
||||||
if (aviWriter.Open(filename, recordingSize.Width, recordingSize.Height)) {
|
if (aviWriter.Open(filename, recordingSize.Width, recordingSize.Height)) {
|
||||||
|
@ -195,6 +200,9 @@ namespace Greenshot.Helpers {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Do the actual frame capture
|
||||||
|
/// </summary>
|
||||||
private void CaptureFrame() {
|
private void CaptureFrame() {
|
||||||
int MSBETWEENCAPTURES = 1000/framesPerSecond;
|
int MSBETWEENCAPTURES = 1000/framesPerSecond;
|
||||||
int msToNextCapture = MSBETWEENCAPTURES;
|
int msToNextCapture = MSBETWEENCAPTURES;
|
||||||
|
@ -262,6 +270,9 @@ namespace Greenshot.Helpers {
|
||||||
Cleanup();
|
Cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Stop the recording, after the next frame
|
||||||
|
/// </summary>
|
||||||
public void Stop() {
|
public void Stop() {
|
||||||
stop = true;
|
stop = true;
|
||||||
if (backgroundTask != null) {
|
if (backgroundTask != null) {
|
||||||
|
@ -269,6 +280,7 @@ namespace Greenshot.Helpers {
|
||||||
}
|
}
|
||||||
Cleanup();
|
Cleanup();
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Free resources
|
/// Free resources
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
@ -297,7 +309,9 @@ namespace Greenshot.Helpers {
|
||||||
if (ffmpegexe != null) {
|
if (ffmpegexe != null) {
|
||||||
try {
|
try {
|
||||||
string webMFile = filename.Replace(".avi", ".webm");
|
string webMFile = filename.Replace(".avi", ".webm");
|
||||||
ProcessStartInfo processStartInfo = new ProcessStartInfo(ffmpegexe, "-i \"" + filename + "\" -vcodec libvpx \"" + webMFile + "\"");
|
string arguments = "-i \"" + filename + "\" -codec:v libvpx -quality good -cpu-used 0 -b:v 1000k -qmin 10 -qmax 42 -maxrate 1000k -bufsize 4000k -threads 4 \"" + webMFile + "\"";
|
||||||
|
LOG.DebugFormat("Starting {0} with arguments {1}", ffmpegexe, arguments);
|
||||||
|
ProcessStartInfo processStartInfo = new ProcessStartInfo(ffmpegexe, arguments);
|
||||||
processStartInfo.CreateNoWindow = false;
|
processStartInfo.CreateNoWindow = false;
|
||||||
processStartInfo.RedirectStandardOutput = false;
|
processStartInfo.RedirectStandardOutput = false;
|
||||||
processStartInfo.UseShellExecute = false;
|
processStartInfo.UseShellExecute = false;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue