public void StartRecording(string path, string name)
        {
            job = new LiveJob();
            dvs = job.AddDeviceSource(Video, Audio);
            job.ActivateSource(dvs);

            WindowsMediaOutputFormat outputFormat = new WindowsMediaOutputFormat();
            AdvancedVC1VideoProfile profile = new AdvancedVC1VideoProfile();
            profile.Bitrate = new ConstantBitrate(1280, false);
            profile.Size = new System.Drawing.Size(640, 360);

            WmaAudioProfile audioProfile = new WmaAudioProfile();

            outputFormat.AudioProfile = audioProfile;
            outputFormat.VideoProfile = profile;
            job.OutputFormat = outputFormat;

            CurrentVideoPath = Path.Combine(path, name);

            FileArchivePublishFormat fileOut = new FileArchivePublishFormat();
            fileOut.OutputFileName = CurrentVideoPath;

            job.PublishFormats.Add(fileOut);
            job.StartEncoding();

            IsRecording = true;
        }
示例#2
0
        /// <summary>
        /// Resize, trim, and save a video file.
        /// </summary>
        /// <param name="filename">Full path to the video to resize.</param>
        /// <param name="outFile">Full path to where the output file should be saved.</param>
        /// <param name="resizeValue">The height, width, or precentage to resize to, as specified by the resizeOption parameter.</param>
        /// <param name="resizeOption">The type of resize which resizeValue is referring to.</param>
        /// <param name="outTypeOption">The output video file type.</param>
        /// <param name="videoQuality">The quality of the output video. A value of 100 means 8kbps for full HD (1980x1080)</param>
        /// <param name="trimRange">The range, in seconds, to trim the video clip to. Set to null to not trim the clip.</param>
        /// <param name="jobProgressCallback">Delegate function which is called at regular intervals for progress updates during the job.</param>
        /// <returns>Void.</returns>
        private static void ProcessVideoFile(string filename, string outFile, int resizeValue, comboOptions resizeOption,
                                             videoOutTypeOptions outTypeOption = videoOutTypeOptions.WMV,
                                             int videoQuality = 100,
                                             Tuple <double, double> trimRange = null,
                                             VideoProgressDelegateCallback jobProgressCallback = null)
        {
            Job       j            = new Job();
            MediaItem mediaItem    = new MediaItem(filename);
            var       originalSize = mediaItem.OriginalVideoSize;
            // Get new dimensions
            Tuple <int, int> newSize = GetNewSize(resizeOption, originalSize.Width, originalSize.Height, resizeValue);
            // Round to the nearest 4 pixels - this is required by encoder
            // Encoder says the value must be an even integer between 64 and 4096 and a multiple of 4
            int newWidth  = Convert.ToInt32(Math.Round(newSize.Item1 / 4.0) * 4);
            int newHeight = Convert.ToInt32(Math.Round(newSize.Item2 / 4.0) * 4);

            if (newWidth < 64 || newHeight < 64 || newWidth > 4096 || newHeight > 4096)
            {
                throw new Exception("New height and width must be between 64 and 4096 pixels");
            }

            double bitsPerSecondPerPixel = 8000.0 / 2000000.0;  // Assume 8kbps for full HD
            int    bitRate = Convert.ToInt32(bitsPerSecondPerPixel * videoQuality * newWidth * newHeight / 100);

            WindowsMediaOutputFormat outFormat = new WindowsMediaOutputFormat();

            outFormat.AudioProfile             = new Microsoft.Expression.Encoder.Profiles.WmaAudioProfile();
            outFormat.VideoProfile             = new Microsoft.Expression.Encoder.Profiles.AdvancedVC1VideoProfile();
            outFormat.VideoProfile.AspectRatio = mediaItem.OriginalAspectRatio;
            outFormat.VideoProfile.AutoFit     = true;
            outFormat.VideoProfile.Bitrate     = new Microsoft.Expression.Encoder.Profiles.VariableUnconstrainedBitrate(bitRate);
            outFormat.VideoProfile.Size        = new Size(newWidth, newHeight);

            mediaItem.VideoResizeMode = VideoResizeMode.Letterbox;
            mediaItem.OutputFormat    = outFormat;

            if (!(trimRange == null))
            {
                Source source = mediaItem.Sources[0];
                source.Clips[0].StartTime = TimeSpan.FromSeconds(trimRange.Item1);
                source.Clips[0].EndTime   = TimeSpan.FromSeconds(trimRange.Item2);
            }

            mediaItem.OutputFileName = Path.GetFileName(outFile);

            j.MediaItems.Add(mediaItem);
            j.CreateSubfolder = false;
            j.OutputDirectory = Path.GetDirectoryName(outFile);

            if (jobProgressCallback != null)
            {
                j.EncodeProgress += new EventHandler <EncodeProgressEventArgs>(jobProgressCallback);
            }
            j.Encode();
            j.Dispose();
        }
示例#3
0
        private void Encode()
        {
            using (Job job = new Job())
            {
                string[] file = System.IO.Directory.GetFiles(videoPath, "*.xesc");
                mediaItem = new MediaItem(file[0]);
                Size size = mediaItem.OriginalVideoSize;
                windowsMediaOutputFormat = new WindowsMediaOutputFormat();
                windowsMediaOutputFormat.VideoProfile             = new Microsoft.Expression.Encoder.Profiles.AdvancedVC1VideoProfile();
                windowsMediaOutputFormat.AudioProfile             = new Microsoft.Expression.Encoder.Profiles.WmaAudioProfile();
                windowsMediaOutputFormat.VideoProfile.AspectRatio = new System.Windows.Size(16, 9);
                windowsMediaOutputFormat.VideoProfile.AutoFit     = true;

                if (size.Width >= 1920 && size.Height >= 1080)
                {
                    windowsMediaOutputFormat.VideoProfile.Size    = new Size(1920, 1080);
                    windowsMediaOutputFormat.VideoProfile.Bitrate = new Microsoft.Expression.Encoder.Profiles.VariableUnconstrainedBitrate(6000);
                }
                else if (size.Width >= 1280 && size.Height >= 720)
                {
                    windowsMediaOutputFormat.VideoProfile.Size    = new Size(1280, 720);
                    windowsMediaOutputFormat.VideoProfile.Bitrate = new Microsoft.Expression.Encoder.Profiles.VariableUnconstrainedBitrate(4000);
                }
                else
                {
                    windowsMediaOutputFormat.VideoProfile.Size    = new Size(size.Height, size.Width);
                    windowsMediaOutputFormat.VideoProfile.Bitrate = new Microsoft.Expression.Encoder.Profiles.VariableUnconstrainedBitrate(2000);
                }

                mediaItem.VideoResizeMode = VideoResizeMode.Letterbox;
                mediaItem.OutputFormat    = windowsMediaOutputFormat;

                job.MediaItems.Add(mediaItem);
                job.CreateSubfolder = false;
                job.OutputDirectory = videoPath;
                job.EncodeProgress += new EventHandler <EncodeProgressEventArgs>(JobEncodeProgress);
                job.Encode();

                System.IO.File.Delete(file[0]);
            }
        }
示例#4
0
        void Encode()
        {
            using (j = new Job())
            {
                MediaItem mediaItem             = new MediaItem(job.OutputScreenCaptureFileName);
                var       size                  = mediaItem.OriginalVideoSize;
                WindowsMediaOutputFormat format = new WindowsMediaOutputFormat();
                format.VideoProfile             = new Microsoft.Expression.Encoder.Profiles.AdvancedVC1VideoProfile();
                format.AudioProfile             = new Microsoft.Expression.Encoder.Profiles.WmaAudioProfile();
                format.VideoProfile.AspectRatio = new System.Windows.Size(16, 9);
                format.VideoProfile.AutoFit     = true;
                if (size.Width > 1920 && size.Height > 1080)
                {
                    format.VideoProfile.Size    = new Size(1920, 1080);
                    format.VideoProfile.Bitrate = new Microsoft.Expression.Encoder.Profiles.VariableUnconstrainedBitrate(6000);
                }
                else if (size.Width > 1280 && size.Height > 720)
                {
                    format.VideoProfile.Size    = new Size(1280, 720);
                    format.VideoProfile.Bitrate = new Microsoft.Expression.Encoder.Profiles.VariableUnconstrainedBitrate(4000);
                }
                else
                {
                    format.VideoProfile.Size    = new Size(size.Width, Size.Height);
                    format.VideoProfile.Bitrate = new Microsoft.Expression.Encoder.Profiles.VariableUnconstrainedBitrate(2000);
                }

                mediaItem.VideoResizeMode = VideoResizeMode.Letterbox;
                mediaItem.OutputFormat    = format;
                j.MediaItems.Add(mediaItem);
                j.CreateSubfolder = false;
                j.OutputDirectory = folderBrowserDialog1.SelectedPath;
                j.EncodeProgress += new EventHandler <EncodeProgressEventArgs>(j_encodeProgress);
                j.Encode();
            }
        }
示例#5
0
        //Encoding Function
        void Encode(string jobPath)
        {
            using (Job j = new Job())
            {
                MediaItem mediaItem = new MediaItem(jobPath);
                var       size      = mediaItem.OriginalVideoSize;
                WindowsMediaOutputFormat WMV_Format = new WindowsMediaOutputFormat();
                WMV_Format.VideoProfile             = new Microsoft.Expression.Encoder.Profiles.AdvancedVC1VideoProfile();
                WMV_Format.AudioProfile             = new Microsoft.Expression.Encoder.Profiles.WmaAudioProfile();
                WMV_Format.VideoProfile.AspectRatio = new System.Windows.Size(16, 9);
                WMV_Format.VideoProfile.AutoFit     = true;

                if (size.Width >= 1920 && size.Height >= 1080)
                {
                    WMV_Format.VideoProfile.Size    = new System.Drawing.Size(1920, 1080);
                    WMV_Format.VideoProfile.Bitrate = new Microsoft.Expression.Encoder.Profiles.VariableUnconstrainedBitrate(6000);
                }
                else if (size.Width >= 1280 && size.Height >= 720)
                {
                    WMV_Format.VideoProfile.Size    = new System.Drawing.Size(1280, 720);
                    WMV_Format.VideoProfile.Bitrate = new Microsoft.Expression.Encoder.Profiles.VariableUnconstrainedBitrate(4000);
                }
                else
                {
                    WMV_Format.VideoProfile.Size    = new System.Drawing.Size(size.Width, size.Height);
                    WMV_Format.VideoProfile.Bitrate = new Microsoft.Expression.Encoder.Profiles.VariableUnconstrainedBitrate(2000);
                }
                mediaItem.VideoResizeMode = VideoResizeMode.Letterbox;
                mediaItem.OutputFormat    = WMV_Format;
                j.MediaItems.Add(mediaItem);
                j.CreateSubfolder = false;
                j.OutputDirectory = gotuOutput;
                j.EncodeProgress += new EventHandler <EncodeProgressEventArgs>(j_EncodeProgress);
                j.Encode();
            }
        }
        public string StartRecording(string path, string name)
        {
            job = new LiveJob();
            dvs = job.AddDeviceSource(null, audioEncoder);
            job.ActivateSource(dvs);

            WindowsMediaOutputFormat outputFormat = new WindowsMediaOutputFormat()
            {
                AudioProfile = new WmaAudioProfile()
            };

            job.OutputFormat = outputFormat;

            string currentRecordingPath = Path.Combine(path, name);
            FileArchivePublishFormat fileOut = new FileArchivePublishFormat();
            fileOut.OutputFileName = currentRecordingPath;

            job.PublishFormats.Add(fileOut);
            job.StartEncoding();

            IsRecording = true;

            return currentRecordingPath;
        }
示例#7
0
        private void ProcessVideoFile(string filename, int resizeValue, comboOptions resizeOption,
                                      videoOutTypeOptions outTypeOption, int mpegQuality, Tuple <double, double> trimRange)
        {
            SetCurrentProgress(0, filename);

            // TODO - check if input file exists

            string outFile = GetOutputFilename(filename, outTypeOption);

            EnsureDir(outFile); // Will throw exception if can't create folder
            DialogResult result = WarnIfExists(outFile);

            switch (result)
            {
            case DialogResult.Yes:
                break;

            case DialogResult.No:
                return;

            case DialogResult.Cancel:
                this.cancelSource.Cancel();
                return;
            }

            Job       j            = new Job();
            MediaItem mediaItem    = new MediaItem(filename);
            var       originalSize = mediaItem.OriginalVideoSize;
            // Get new dimensions
            Tuple <int, int> newSize = GetNewSize(resizeOption, originalSize.Width, originalSize.Height, resizeValue);
            // Round to the nearest 4 pixels - this is required by encoder
            // Encoder says the value must be an even integer between 64 and 4096 and a multiple of 4
            int newWidth  = Convert.ToInt32(Math.Round(newSize.Item1 / 4.0) * 4);
            int newHeight = Convert.ToInt32(Math.Round(newSize.Item2 / 4.0) * 4);

            if (newWidth < 64 || newHeight < 64 || newWidth > 4096 || newHeight > 4096)
            {
                throw new Exception("New height and width must be between 64 and 4096 pixels");
                // TODO - display this in the status bar
            }

            double bitsPerSecondPerPixel = 8000.0 / 2000000.0;  // Assume 8kbps for full HD
            int    bitRate = Convert.ToInt32(bitsPerSecondPerPixel * mpegQuality * newWidth * newHeight / 100);

            WindowsMediaOutputFormat outFormat = new WindowsMediaOutputFormat();

            outFormat.AudioProfile = new Microsoft.Expression.Encoder.Profiles.WmaAudioProfile();
            // outFormat.VideoProfile = new Microsoft.Expression.Encoder.Profiles.MainVC1VideoProfile();
            outFormat.VideoProfile             = new Microsoft.Expression.Encoder.Profiles.AdvancedVC1VideoProfile();
            outFormat.VideoProfile.AspectRatio = mediaItem.OriginalAspectRatio;
            outFormat.VideoProfile.AutoFit     = true;
            outFormat.VideoProfile.Bitrate     = new Microsoft.Expression.Encoder.Profiles.VariableUnconstrainedBitrate(bitRate);
            outFormat.VideoProfile.Size        = new Size(newWidth, newHeight);

            //mediaItem.VideoResizeMode = VideoResizeMode.Letterbox;

            mediaItem.OutputFormat = outFormat;

            if (!(trimRange == null))
            {
                Source source = mediaItem.Sources[0];
                source.Clips[0].StartTime = TimeSpan.FromSeconds(trimRange.Item1);
                source.Clips[0].EndTime   = TimeSpan.FromSeconds(trimRange.Item2);
            }

            mediaItem.OutputFileName = Path.GetFileName(outFile);

            j.MediaItems.Add(mediaItem);
            j.CreateSubfolder = false;
            j.OutputDirectory = Path.GetDirectoryName(outFile);

            j.EncodeProgress += new EventHandler <EncodeProgressEventArgs>(OnJobEncodeProgress);
            j.Encode();
            j.Dispose();
        }