示例#1
0
        public Image ExtractSingleFrame(int positionToExtract, Size dimensions)
        {
            string           tempFile   = Path.ChangeExtension(Path.GetTempFileName(), "jpg");
            FFMPEGParameters parameters = new FFMPEGParameters()
            {
                InputFilePath  = FilePath,
                DisableAudio   = true,
                OutputOptions  = String.Format("-f image2 -ss {0} -vframes 1", positionToExtract),
                Size           = dimensions,
                OutputFilePath = tempFile,
            };

            ;
            string output = FFMPEG.Execute(parameters);

            if (!File.Exists(tempFile))
            {
                throw new Exception("Could not create single frame image from video clip");
            }

            Image previewImage = LoadImageFromFile(tempFile);

            try
            {
                File.Delete(tempFile);
            }

            catch (Exception ex)
            {
                throw new Exception("Failed to delete temporary file used for thumbnail " + ex.Message);
            }

            return(previewImage);
        }
示例#2
0
        protected void GetVideoInfo()
        {
            string output = FFMPEG.Execute(FilePath);

            Duration     = InfoProcessor.GetDuration(output);
            AudioBitRate = InfoProcessor.GetAudioBitRate(output);
            AudioFormat  = InfoProcessor.GetAudioFormat(output);
            VideoFormat  = InfoProcessor.GetVideoFormat(output);
            Dimensions   = InfoProcessor.GetVideoDimensions(output);
        }
示例#3
0
        public string WatermarkVideo(string watermarkImageFilePath, bool overwrite, WatermarkPosition position, Point offset)
        {
            string extension      = Path.GetExtension(FilePath);
            string tempOutputFile = Path.ChangeExtension(Path.GetTempFileName(), extension);

            string overlayFormat;

            switch (position)
            {
            case WatermarkPosition.TopLeft:
                overlayFormat = "{0}:{1}";
                break;

            case WatermarkPosition.TopRight:
                overlayFormat = "main_w-overlay_w-{0}:{1}";
                break;

            case WatermarkPosition.BottomLeft:
                overlayFormat = "{0}:main_h-overlay_h-{1}";
                break;

            case WatermarkPosition.BottomRight:
                overlayFormat = "main_w-overlay_w-{0}:main_h-overlay_h-{1}";
                break;

            case WatermarkPosition.Center:
                overlayFormat = "(main_w-overlay_w)/2-{0}:(main_h-overlay_h)/2-{1}";
                break;

            case WatermarkPosition.MiddleLeft:
                overlayFormat = "{0}:(main_h-overlay_h)/2-{1}";
                break;

            case WatermarkPosition.MiddleRight:
                overlayFormat = "main_w-overlay_w-{0}:(main_h-overlay_h)/2-{1}";
                break;

            case WatermarkPosition.CenterTop:
                overlayFormat = "(main_w-overlay_w)/2-{0}:{1}";
                break;

            case WatermarkPosition.CenterBottom:
                overlayFormat = "(main_w-overlay_w)/2-{0}:main_h-overlay_h-{1}";
                break;

            default:
                throw new ArgumentException("Invalid position specified");
            }

            string overlayPostion = String.Format(overlayFormat, offset.X, offset.Y);

            FFMPEGParameters parameters = new FFMPEGParameters
            {
                InputFilePath  = FilePath,
                OutputFilePath = tempOutputFile,
                SameQ          = true,
                Overwrite      = true,
                VideoFilter    = String.Format("\"movie=\\'{0}\\' [logo]; [in][logo] overlay={1} [out]\"", watermarkImageFilePath.Replace("\\", "\\\\"), overlayPostion)
            };


            string output = FFMPEG.Execute(parameters);

            if (File.Exists(tempOutputFile) == false)
            {
                throw new ApplicationException(String.Format("Failed to watermark video {0}{1}{2}", FilePath, Environment.NewLine, output));
            }

            FileInfo watermarkedVideoFileInfo = new FileInfo(tempOutputFile);

            if (watermarkedVideoFileInfo.Length == 0)
            {
                throw new ApplicationException(String.Format("Failed to watermark video {0}{1}{2}", FilePath, Environment.NewLine, output));
            }

            if (overwrite)
            {
                File.Delete(FilePath);
                File.Move(tempOutputFile, FilePath);

                return(FilePath);
            }

            return(tempOutputFile);
        }