private static IEnumerable<FrameFingerPrintWrapper> IndexVideo( string videoFile, MediaInfo info, long maxMemory ) { TimeSpan totalDuration = info.GetDuration(); var ffmpegProcessSettings = new FFMPEGProcessVideoSettings( videoFile, info.GetFramerate().Numerator, info.GetFramerate().Denominator * 4, FFMPEGMode.PlaybackAtFourX ); using (var indexingPool = new VideoIndexingExecutor(4, (long)Math.Round((3.0 * maxMemory) / 4.0))) using (var byteStore = new RawByteStore(info.GetWidth(), info.GetHeight(), indexingPool, (long)Math.Round(maxMemory / 4.0))) using (var ffmpegProcess = new FFMPEGProcess(ffmpegProcessSettings, (byteArray, bytesToSubmit) => { byteStore.Submit(byteArray, bytesToSubmit); })) { ffmpegProcess.Execute(); byteStore.Shutdown(); byteStore.Wait(); indexingPool.Shutdown(); indexingPool.Wait(); return indexingPool.GetFingerPrints(); } }
private static WritableLockBitImage GetFrameFromVideo(VideoFingerPrintWrapper video, int frameNumber) { using (MediaInfoProcess mediaInfoProcess = new MediaInfoProcess(video.FilePath)) { MediaInfo mediaInfo = mediaInfoProcess.Execute(); if (mediaInfo.GetFramerate().Numerator == 0) { throw new Exception("Did not get valid frame rate"); } int width = mediaInfo.GetWidth(); int height = mediaInfo.GetHeight(); var ffmpegProcessSettings = new FFMPEGProcessVideoSettings( video.FilePath, mediaInfo.GetFramerate().Numerator, mediaInfo.GetFramerate().Denominator * 4, FFMPEGMode.SeekFrame ); ffmpegProcessSettings.TargetFrame = frameNumber; byte[] frameBytes = new byte[width * height * 3]; int offset = 0; using ( var ffmpegProcess = new FFMPEGProcess( ffmpegProcessSettings, (stdoutBytes, numBytes) => { Buffer.BlockCopy(stdoutBytes, 0, frameBytes, offset, numBytes); offset += numBytes; }, false ) ) { ffmpegProcess.Execute(); if (offset != 3 * width * height) { throw new Exception("Did not get all bytes to produce valid frame"); } WritableLockBitImage videoFrame = new WritableLockBitImage(width, height, frameBytes); videoFrame.Lock(); return(videoFrame); } } }