Пример #1
0
        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();
            }
        }
Пример #2
0
        /// <summary>
        /// Now you just set StartInfo.Arguments, callback, input, output
        /// </summary>
        private static FFMPEGProcess CreateFFMPEGProcess()
        {
            FFMPEGProcess process = new FFMPEGProcess();

            process.StartInfo.UseShellExecute        = false;
            process.StartInfo.RedirectStandardOutput = false;
            process.StartInfo.RedirectStandardError  = false;
            process.StartInfo.CreateNoWindow         = true;

            process.EnableRaisingEvents = false;

            return(process);
        }
Пример #3
0
        public static void GetThumbnailWait(string input, string output, int size)
        {
            FFMPEGProcess process = CreateFFMPEGProcess();

            process.StartInfo.FileName  = "ffmpeg.exe";
            process.StartInfo.Arguments = CreateFfmpegThumbnailArgs(input, output, size);
            process.input  = input;
            process.output = output;

            process.Start();

            process.WaitForExit();

            process.Close();
            process.Dispose();
        }
Пример #4
0
        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);
                }
            }
        }
Пример #5
0
        public static void GetThumbnailAsync(string input, string output, int size, Action <string> callback)
        {
            FFMPEGProcess ffmpeg = CreateFFMPEGProcess();

            ffmpeg.StartInfo.FileName  = "ffmpeg.exe";
            ffmpeg.StartInfo.Arguments = CreateFfmpegThumbnailArgs(input, output, size);
            ffmpeg.callback            = callback;
            ffmpeg.input  = input;
            ffmpeg.output = output;

            ffmpeg.Exited += (sender, e) =>
            {
                var process = (FFMPEGProcess)sender;

                if (process.callback != null)
                {
                    callback.Invoke(process.output);
                }

                process.Dispose();
            };

            ffmpeg.Start();
        }