From b7d58ef36558da095a6aceed27077867f948ff41 Mon Sep 17 00:00:00 2001 From: Aron Parker Date: Thu, 22 Feb 2018 00:41:14 +0100 Subject: [PATCH] Added support for x264vfw --- AviRecorder/Video/Avi/FourCC.cs | 1 + .../Video/Compression/VideoCompressorInfo.cs | 32 +++++++++++++++---- 2 files changed, 27 insertions(+), 6 deletions(-) diff --git a/AviRecorder/Video/Avi/FourCC.cs b/AviRecorder/Video/Avi/FourCC.cs index 4c3540e..7d508f4 100644 --- a/AviRecorder/Video/Avi/FourCC.cs +++ b/AviRecorder/Video/Avi/FourCC.cs @@ -40,6 +40,7 @@ public static class FourCC #if COMPATIBILITY public const uint i420 = 'i' << 0 | '4' << 8 | '2' << 16 | '0' << 24; public const uint LAGS = 'L' << 0 | 'A' << 8 | 'G' << 16 | 'S' << 24; + public const uint x264 = 'X' << 0 | '2' << 8 | '6' << 16 | '4' << 24; #endif public static uint Make(string fcc) diff --git a/AviRecorder/Video/Compression/VideoCompressorInfo.cs b/AviRecorder/Video/Compression/VideoCompressorInfo.cs index b60a7a4..228778a 100644 --- a/AviRecorder/Video/Compression/VideoCompressorInfo.cs +++ b/AviRecorder/Video/Compression/VideoCompressorInfo.cs @@ -52,21 +52,41 @@ public static VideoCompressorInfo[] GetCompressorInfos() #endif using (var hic = ICOpen(FourCC.VIDC, icInfo.fccHandler, IcMode.Compress)) - if (!hic.IsInvalid && ICGetInfo(hic, ref icInfo, (uint)Marshal.SizeOf()) != IntPtr.Zero && SupportsFlags(icInfo.dwFlags)) - results.Add(new VideoCompressorInfo(ref icInfo)); + { + if (hic.IsInvalid) + continue; + + if (ICGetInfo(hic, ref icInfo, (uint)Marshal.SizeOf()) == IntPtr.Zero) + continue; + + if (!SupportsVideoCompressor(ref icInfo)) + continue; + + results.Add(new VideoCompressorInfo(ref icInfo)); + } } return results.ToArray(); } - private static bool SupportsFlags(VideoCompressorFlags dwFlags) + private static bool SupportsVideoCompressor(ref ICINFO icInfo) { - const VideoCompressorFlags unsupportedFlags = VideoCompressorFlags.Quality | VideoCompressorFlags.Crunch | VideoCompressorFlags.CompressFrames; +#if COMPATIBILITY + if (icInfo.fccHandler == FourCC.x264) + return true; +#endif - if ((dwFlags & unsupportedFlags) != 0) + const VideoCompressorFlags unsupportedFlags = VideoCompressorFlags.Quality | + VideoCompressorFlags.Crunch | + VideoCompressorFlags.CompressFrames; + + if ((icInfo.dwFlags & unsupportedFlags) != 0) return false; - return (dwFlags & VideoCompressorFlags.Temporal) == 0 || (dwFlags & VideoCompressorFlags.FastTemporalC) != 0; + bool requiresPreviousFrame = (icInfo.dwFlags & VideoCompressorFlags.Temporal) != 0 && + (icInfo.dwFlags & VideoCompressorFlags.FastTemporalC) == 0; + + return !requiresPreviousFrame; } } }