Example #1
0
 private void ProcessMovie(string movieFileName, string destinationFolder)
 {
     try {
         NutcrackerProcessingMovie f = new NutcrackerProcessingMovie();
         f.Show();
         ffmpeg.ffmpeg converter = new ffmpeg.ffmpeg(movieFileName);
         converter.MakeThumbnails(50, 50, destinationFolder);
         f.Close();
     }
     catch (Exception ex) {
         MessageBox.Show("There was a problem converting " + movieFileName + ": " + ex.Message, "Error Converting Movie",
                         MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
     }
 }
Example #2
0
        private void GetVideoInformation()
        {
            // This is only done each time a Video file is changed.
            // No point doing this every time it needs to render.
            // So once a user adds a video file to the effect this code will no longer be used.
            string videoFilename = Path.Combine(VideoPath, _data.FileName);

            try
            {
                VideoQuality = 50;                 // Set quality to 50% when a new file is opened.
                // Delete old path and create new path for processed video
                EstablishTempFolder();
                // Gets Video length and Frame rate will continue if users start position is less then the video length.
                ffmpeg.ffmpeg videoLengthInfo = new ffmpeg.ffmpeg(videoFilename);
                string        result          = videoLengthInfo.GetVideoInfo(_tempFilePath);
                // Get Video Length
                int      durationIndex = result.IndexOf("Duration: ");
                string   videoInfo     = result.Substring(durationIndex + 10, 8);
                string[] words         = videoInfo.Split(':');
                TimeSpan videoTimeSpan = new TimeSpan(Int32.Parse(words[0]), Int32.Parse(words[1]), Int32.Parse(words[2]));
                VideoLength = (int)videoTimeSpan.TotalSeconds;

                // Saves one frame from video then grabs it to determine Video size.
                // This was to replace the way Accord did it as it makes sense to do the Video size
                // conversion when generating all the images. This can reduces each bitmap file size significantly.
                ffmpeg.ffmpeg videoSizeInfo = new ffmpeg.ffmpeg(videoFilename);
                videoSizeInfo.GetVideoSize(_tempFilePath + "\\Temp.bmp");
                var image = Image.FromFile(_tempFilePath + "\\Temp.bmp");

                // Saves the Video info to data store.
                _data.VideoSize = new Size(image.Width, image.Height);

                image.Dispose();
                _getNewVideoInfo = false;
            }
            catch (Exception ex)
            {
                var messageBox = new MessageBoxForm("There was a problem converting " + videoFilename + ": " + ex.Message,
                                                    "Error Converting Video", MessageBoxButtons.OK, SystemIcons.Error);
                messageBox.ShowDialog();
                _videoFileDetected = false;
            }
        }
 private void ProcessMovie(string movieFileName, string destinationFolder)
 {
     try {
         NutcrackerProcessingMovie f = new NutcrackerProcessingMovie();
         f.Show();
         ffmpeg.ffmpeg converter = new ffmpeg.ffmpeg(movieFileName);
         converter.MakeThumbnails(50, 50, destinationFolder);
         f.Close();
     }
     catch (Exception ex) {
         //messageBox Arguments are (Text, Title, No Button Visible, Cancel Button Visible)
         MessageBoxForm.msgIcon = SystemIcons.Error; //this is used if you want to add a system icon to the message form.
         var messageBox = new MessageBoxForm("There was a problem converting " + movieFileName + ": " + ex.Message, "Error Converting Movie", false, true);
         messageBox.ShowDialog();
     }
 }
Example #4
0
        private void ProcessMovie(string folder)
        {
            //Delete old path and create new path for processed video
            if (System.IO.Directory.Exists(_data.Video_DataPath))
            {
                Directory.Delete(folder, true);
            }
            _data.Video_DataPath = Path.Combine(_tempPath, Guid.NewGuid().ToString());
            System.IO.Directory.CreateDirectory(_data.Video_DataPath);
            _moviePicturesFileList = null;

            //Setup scale size to process.
            int renderHeight = BufferHt;
            int renderWidth  = BufferWi;

            if (!ScaleToGrid)
            {
                renderWidth  = (int)(BufferWi * ((double)ScalePercent / 100 + 1));
                renderHeight = (int)(BufferHt * ((double)ScalePercent / 100 + 1));
                if (renderWidth % 2 != 0)
                {
                    renderWidth += 1;
                }
            }

            string colorType = EffectColorType == EffectColorType.RenderGreyScale ? " -pix_fmt gray" : ""; //Effcet type will be Color or Gray scale
            string frameRate = " -r " + 20;                                                                //Video Frame rate is set to 20 to matach Vixen

            string videoFilename = Path.Combine(_videoPath, _data.FileName);

            try
            {
                //Gets Video length and will continue if users start position is less then the video length.
                ffmpeg.ffmpeg videoLengthInfo = new ffmpeg.ffmpeg(videoFilename);
                string        result          = videoLengthInfo.MakeThumbnails(_data.Video_DataPath);
                int           index           = result.IndexOf("Duration: ");
                string        videoInfo       = result.Substring(index + 10, 8);
                string[]      words           = videoInfo.Split(':');
                TimeSpan      videoTimeSpan   = new TimeSpan(Int32.Parse(words[0]), Int32.Parse(words[1]), Int32.Parse(words[2]));
                VideoLength = (int)videoTimeSpan.TotalSeconds;

                //Gets selected video if Video length is longer then the entered start time.
                if (VideoLength > StartTimeSeconds + (TimeSpan.TotalSeconds * ((double)PlayBackSpeed / 100 + 1)))
                {
                    ffmpeg.ffmpeg converter = new ffmpeg.ffmpeg(videoFilename);
                    converter.MakeThumbnails(_data.Video_DataPath, StartTimeSeconds, ((TimeSpan.TotalSeconds * ((double)PlayBackSpeed / 100 + 1))),
                                             renderWidth, renderHeight, MaintainAspect, frameRate, colorType, RotateVideo);
                    _moviePicturesFileList = Directory.GetFiles(_data.Video_DataPath).OrderBy(f => f).ToList();
                    _currentMovieImageNum  = 0;
                }
                else
                {
                    MessageBoxForm.msgIcon = SystemIcons.Error;                     //this is used if you want to add a system icon to the message form.
                    var messageBox = new MessageBoxForm("Entered Start Time plus Effect length is greater than the Video Length of " + _data.FileName,
                                                        "Invalid Start Time. Decrease the Start Time", MessageBoxButtons.OK, SystemIcons.Error);
                    messageBox.ShowDialog();
                }
            }
            catch (Exception ex)
            {
                var messageBox = new MessageBoxForm("There was a problem converting " + videoFilename + ": " + ex.Message,
                                                    "Error Converting Video", MessageBoxButtons.OK, SystemIcons.Error);
                messageBox.ShowDialog();
            }
        }
Example #5
0
        private void ProcessMovie(string folder)
        {
            //Delete old path and create new path for processed video
            if (Directory.Exists(_data.Video_DataPath))
            {
                Directory.Delete(folder, true);
            }
            _data.Video_DataPath = Path.Combine(_tempPath, Guid.NewGuid().ToString());
            Directory.CreateDirectory(_data.Video_DataPath);

            string videoFilename = Path.Combine(_videoPath, _data.FileName);

            try
            {
                _reader = new VideoFileReader();
                _reader.Open(videoFilename);
                var    count         = _reader.FrameCount;
                var    videoTimespan = TimeSpan.FromSeconds(count / _reader.FrameRate.Value);
                var    frameScale    = _reader.FrameRate.Value / 20;
                int    renderHeight;
                int    renderWidth;
                string cropVideo = "";

                if (StretchToGrid)                 // Will stretch the image to the grid size.
                {
                    renderWidth  = BufferWi;
                    renderHeight = BufferHt;
                }
                else
                {
                    // Will scaled the image to the grid size.
                    GetNewImageSize(out renderWidth, out renderHeight, BufferWi, BufferHt);
                    if (!ScaleToGrid)                     // Scale and crop the image based on users scale setting
                    {
                        renderWidth  = (int)(renderWidth * ((double)ScalePercent / 100 + 1));
                        renderHeight = (int)(renderHeight * ((double)ScalePercent / 100 + 1));
                        int cropWidth  = Math.Min(renderWidth, BufferWi);
                        int cropHeight = Math.Min(renderHeight, BufferHt);
                        cropVideo = $", crop={cropWidth}:{cropHeight}:{renderWidth - cropWidth / 2}:{renderHeight - cropHeight / 2}";
                    }
                }

                // Will adjust the render size if element is below 10 as FFMPEG could refuse to scale.
                if (renderHeight < 10 || renderWidth < 10)
                {
                    // I don't see any point continuing if the element is this small.
                    if (renderHeight <= 2 || renderWidth <= 2)
                    {
                        _videoFileDetected = false;
                        return;
                    }
                    GetNewImageSize(out renderWidth, out renderHeight, 50, (int)(50 * ((double)renderWidth / renderHeight)));
                }

                _reader.Close();
                _reader.Dispose();

                VideoLength = (int)videoTimespan.TotalSeconds;
                // Gets selected video if Video length is longer then the entered start time.
                if (VideoLength > StartTimeSeconds + (TimeSpan.TotalSeconds * ((double)PlayBackSpeed / 100 + 1)))
                {
                    ffmpeg.ffmpeg converter = new ffmpeg.ffmpeg(videoFilename);
                    _currentMovieImageNum = 0;
                    // Height and Width needs to be evenly divisible to work or ffmpeg complains.
                    if (renderHeight % 2 != 0)
                    {
                        renderHeight++;
                    }
                    if (renderWidth % 2 != 0)
                    {
                        renderWidth++;
                    }
                    converter.MakeScaledVideo(_data.Video_DataPath, StartTimeSeconds, ((TimeSpan.TotalSeconds * ((double)PlayBackSpeed / 100 + 1))),
                                              renderWidth, renderHeight, frameScale, MaintainAspect, 20, RotateVideo, cropVideo);
                    _videoFileDetected = true;
                }
                else
                {
                    MessageBoxForm.msgIcon = SystemIcons.Error;                     // This is used if you want to add a system icon to the message form.
                    var messageBox = new MessageBoxForm("Entered Start Time plus Effect length is greater than the Video Length of " + _data.FileName,
                                                        "Invalid Start Time. Decrease the Start Time", MessageBoxButtons.OK, SystemIcons.Error);
                    messageBox.ShowDialog();
                    _videoFileDetected = false;
                }
            }
            catch (Exception ex)
            {
                var messageBox = new MessageBoxForm("There was a problem converting " + videoFilename + ": " + ex.Message,
                                                    "Error Converting Video", MessageBoxButtons.OK, SystemIcons.Error);
                messageBox.ShowDialog();
                _videoFileDetected = false;
            }
        }
Example #6
0
        private void ProcessMovie()
        {
            EstablishTempFolder();

            string videoFilename = Path.Combine(VideoPath, _data.FileName);

            try
            {
                if (VideoQuality == 0 || _getNewVideoInfo)
                {
                    GetVideoInformation();
                }

                string cropVideo = "";

                if (StretchToGrid)                 // Will stretch the image to the grid size.
                {
                    _renderWidth  = BufferWi;
                    _renderHeight = BufferHt;
                }
                else
                {
                    // Will scale the image to the grid size.
                    GetNewImageSize(out _renderWidth, out _renderHeight, BufferWi, BufferHt);
                    if (!ScaleToGrid)                     // Scale and crop the image based on users scale setting
                    {
                        _renderWidth  = (int)(_renderWidth * ((double)ScalePercent / 100 + 1));
                        _renderHeight = (int)(_renderHeight * ((double)ScalePercent / 100 + 1));
                    }
                }

                double videoQuality = TargetPositioning == TargetPositioningType.Locations ? (double)VideoQuality / 100 : 1;
                if (_renderWidth > MaxRenderWidth || _renderHeight > MaxRenderHeight)
                {
                    _ratioWidth   = (double)_renderWidth / MaxRenderWidth / videoQuality;
                    _ratioHeight  = (double)_renderHeight / MaxRenderHeight / videoQuality;
                    _renderHeight = (int)(MaxRenderHeight * videoQuality);
                    _renderWidth  = (int)(MaxRenderWidth * videoQuality);
                }
                else
                {
                    _ratioWidth = _ratioHeight = 1;
                }

                if (!StretchToGrid && !ScaleToGrid)
                {
                    int cropWidth  = _renderWidth > BufferWi ? BufferWi : _renderWidth;
                    int cropHeight = _renderHeight > BufferHt ? BufferHt : _renderHeight;
                    cropVideo = $", crop={cropWidth}:{cropHeight}:{(_renderWidth - cropWidth) / 2}:{(_renderHeight - cropHeight) / 2}";
                }

                // Will adjust the render size if element is below 10 as FFMPEG could refuse to scale.
                if (_renderHeight < 10 || _renderWidth < 10)
                {
                    // I don't see any point continuing if the element is this small.
                    if (_renderHeight <= 2 || _renderWidth <= 2)
                    {
                        _videoFileDetected = false;
                        return;
                    }
                    GetNewImageSize(out _renderWidth, out _renderHeight, 50, (int)(50 * ((double)_renderWidth / _renderHeight)));
                }

                // Gets selected video if Video length is longer then the entered start time.
                if (VideoLength > StartTimeSeconds + (TimeSpan.TotalSeconds * ((double)PlayBackSpeed / 100 + 1)))
                {
                    ffmpeg.ffmpeg converter = new ffmpeg.ffmpeg(videoFilename);
                    _currentMovieImageNum = 0;
                    // Height and Width needs to be evenly divisible to work or ffmpeg complains.
                    if (_renderHeight % 2 != 0)
                    {
                        _renderHeight++;
                    }
                    if (_renderWidth % 2 != 0)
                    {
                        _renderWidth++;
                    }
                    converter.MakeScaledThumbNails(_tempFilePath, StartTimeSeconds, ((TimeSpan.TotalSeconds * ((double)PlayBackSpeed / 100 + 1))),
                                                   _renderWidth, _renderHeight, MaintainAspect, RotateVideo, cropVideo);
                    _moviePicturesFileList = Directory.GetFiles(_tempFilePath).OrderBy(f => f).ToList();

                    _videoFileDetected = true;
                }
                else
                {
                    var messageBox = new MessageBoxForm("Entered Start Time plus Effect length is greater than the Video Length of " + _data.FileName,
                                                        "Invalid Start Time. Decrease the Start Time", MessageBoxButtons.OK, SystemIcons.Error);
                    messageBox.StartPosition = FormStartPosition.CenterScreen;
                    messageBox.TopMost       = true;
                    messageBox.ShowDialog();
                    _videoFileDetected = false;
                }
            }
            catch (Exception ex)
            {
                Logging.Error(ex, $"There was a problem converting {videoFilename}");
                var messageBox = new MessageBoxForm("There was a problem converting " + videoFilename + ": " + ex.Message,
                                                    "Error Converting Video", MessageBoxButtons.OK, SystemIcons.Error);
                messageBox.StartPosition = FormStartPosition.CenterScreen;
                messageBox.TopMost       = true;
                messageBox.ShowDialog();
                _videoFileDetected = false;
            }
        }
 private void ProcessMovie(string movieFileName, string destinationFolder)
 {
     try {
         NutcrackerProcessingMovie f = new NutcrackerProcessingMovie();
         f.Show();
         ffmpeg.ffmpeg converter = new ffmpeg.ffmpeg(movieFileName);
         converter.MakeThumbnails(50, 50, destinationFolder);
         f.Close();
     }
     catch (Exception ex) {
         MessageBox.Show("There was a problem converting " + movieFileName + ": " + ex.Message, "Error Converting Movie",
                         MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
     }
 }
Example #8
0
        private void ProcessMovie(string folder)
        {
            //Delete old path and create new path for processed video
            if (System.IO.Directory.Exists(_data.Video_DataPath))
            {
                Directory.Delete(folder, true);
            }
            _data.Video_DataPath = Path.Combine(_tempPath, Guid.NewGuid().ToString());
            System.IO.Directory.CreateDirectory(_data.Video_DataPath);
            _moviePicturesFileList = null;

            //Setup scale size to process.
            int renderHeight = BufferHt;
            int renderWidth = BufferWi;
            if (!ScaleToGrid)
            {
                renderWidth = (int)(BufferWi * ((double)ScalePercent / 100 + 1));
                renderHeight = (int)(BufferHt * ((double)ScalePercent / 100 + 1));
                if (renderWidth % 2 != 0)
                {
                    renderWidth += 1;
                }
            }

            string colorType = EffectColorType == EffectColorType.RenderGreyScale ? " -pix_fmt gray" : ""; //Effcet type will be Color or Gray scale
            string frameRate = " -r " + 20; //Video Frame rate is set to 20 to matach Vixen

            string videoFilename = Path.Combine(_videoPath, _data.FileName);
            try
            {
                //Gets Video length and will continue if users start position is less then the video length.
                ffmpeg.ffmpeg videoLengthInfo = new ffmpeg.ffmpeg(videoFilename);
                string result = videoLengthInfo.MakeThumbnails(_data.Video_DataPath);
                int index = result.IndexOf("Duration: ");
                string videoInfo = result.Substring(index + 10, 8);
                string[] words = videoInfo.Split(':');
                TimeSpan videoTimeSpan = new TimeSpan(Int32.Parse(words[0]), Int32.Parse(words[1]), Int32.Parse(words[2]));
                VideoLength = (int)videoTimeSpan.TotalSeconds;

                //Gets selected video if Video length is longer then the entered start time.
                if (VideoLength > StartTimeSeconds + (TimeSpan.TotalSeconds*((double) PlayBackSpeed/100 + 1)))
                {
                    ffmpeg.ffmpeg converter = new ffmpeg.ffmpeg(videoFilename);
                    converter.MakeThumbnails(_data.Video_DataPath, StartTimeSeconds, ((TimeSpan.TotalSeconds*((double) PlayBackSpeed/100 + 1))),
                        renderWidth, renderHeight, MaintainAspect, frameRate, colorType, RotateVideo);
                    _moviePicturesFileList = Directory.GetFiles(_data.Video_DataPath).OrderBy(f => f).ToList();
                    _currentMovieImageNum = 0;
                }
                else
                {
                    MessageBoxForm.msgIcon = SystemIcons.Error; //this is used if you want to add a system icon to the message form.
                    var messageBox = new MessageBoxForm("Entered Start Time plus Effect length is greater than the Video Length of " + _data.FileName,
                        "Invalid Start Time. Decrease the Start Time", MessageBoxButtons.OK, SystemIcons.Error);
                    messageBox.ShowDialog();
                }
            }
            catch (Exception ex)
            {
                var messageBox = new MessageBoxForm("There was a problem converting " + videoFilename + ": " + ex.Message,
                    "Error Converting Video", MessageBoxButtons.OK, SystemIcons.Error);
                messageBox.ShowDialog();
            }
        }