Example #1
0
        private void btnChooseOutput_Click(object sender, EventArgs e)
        {
            PresetDescriptor preset = comboPresets.SelectedItem as PresetDescriptor;

            SaveFileDialog dlg = new SaveFileDialog();

            string filter = string.Empty;

            if (!string.IsNullOrEmpty(preset.FileExtension))
            {
                dlg.DefaultExt = preset.FileExtension;
                filter         = string.Format("(*.{0})|*.{0}|", preset.FileExtension);
            }

            filter             += "All files (*.*)|*.*";
            dlg.Filter          = filter;
            dlg.OverwritePrompt = true;

            if (txtOutput.Text.Length > 0)
            {
                dlg.FileName         = System.IO.Path.GetFileName(txtOutput.Text);
                dlg.InitialDirectory = System.IO.Path.GetDirectoryName(txtOutput.Text);
            }

            if (DialogResult.OK != dlg.ShowDialog())
            {
                return;
            }

            txtOutput.Text   = dlg.FileName;
            txtAudioLog.Text = Util.AudioLogForVideoFile(dlg.FileName, preset);
        }
Example #2
0
        public static string AudioLogForVideoFile(string videoFile, PresetDescriptor preset)
        {
            var audioPin = Util.MediaSocketFromPreset(preset.Name).Pins.FirstOrDefault(pin =>
                                                                                       (pin.StreamInfo.MediaType == PrimoSoftware.AVBlocks.MediaType.Audio));

            if (audioPin == null)
            {
                return(string.Empty);
            }

            var ext = DefaulAudioFileExtension(audioPin.StreamInfo);

            if (ext == null)
            {
                return(string.Empty);
            }

            return(System.IO.Path.ChangeExtension(videoFile, ext));
        }
Example #3
0
        public CaptureDSForm()
        {
            InitializeComponent();
#if WIN64
            this.Text += " (64-bit)";
#endif

            EnumInputDev(FilterCategory.AudioInputDevice, listAudioDev);
            listAudioDev.Items.Insert(0, new DevItem()
            {
                FriendlyName = "[ No audio input ]",
                //  DisplayName = null
            });

            EnumInputDev(FilterCategory.VideoInputDevice, listVideoDev);

            statsTimer          = new System.Windows.Forms.Timer();
            statsTimer.Tick    += new EventHandler(UpdateStats);
            statsTimer.Interval = 500;

            bIgnoreDeviceSelection = false;
            bRecording             = false;
            cmdRecord.Text         = sStartRecording;
            txtRecording.Visible   = false;

            ResetStats();

            int h = previewBox.Size.Height;
            int w = previewBox.Size.Width;
            previewBox.Size = new Size(w, w * 3 / 4);

            for (int i = 0; i < AvbTranscoder.Presets.Length; ++i)
            {
                PresetDescriptor preset = AvbTranscoder.Presets[i];

                if (!preset.AudioOnly)
                {
                    comboPresets.Items.Add(preset);
                }
            }

            comboPresets.SelectedIndex = 0;
        }
Example #4
0
        private void comboPresets_SelectedIndexChanged(object sender, EventArgs e)
        {
            PresetDescriptor preset = comboPresets.SelectedItem as PresetDescriptor;

            if (string.IsNullOrEmpty(preset.FileExtension) || txtOutput.Text.Length == 0)
            {
                return;
            }

            string newExt = "." + preset.FileExtension;
            string oldExt = System.IO.Path.GetExtension(txtOutput.Text);

            if (oldExt != newExt)
            {
                string newFile = System.IO.Path.ChangeExtension(txtOutput.Text, newExt);
                txtOutput.Text = newFile;
            }

            txtAudioLog.Text = Util.AudioLogForVideoFile(txtOutput.Text, preset);
        }
Example #5
0
        private bool ConfigureTranscoder()
        {
            ms.transcoder = new CompositeTranscoder();
            ms.transcoder.AllowDemoMode = true;

            // set audio input pin if audio is not disabled
            if (ms.audioInput != null)
            {
                if ((ms.audioType.majorType != DirectShowLib.MediaType.Audio) ||
                    (ms.audioType.formatType != DirectShowLib.FormatType.WaveEx))
                {
                    return(false);
                }

                WaveFormatEx wfx = new WaveFormatEx();
                Marshal.PtrToStructure(ms.audioType.formatPtr, wfx);

                if (wfx.wFormatTag != 1) // WAVE_FORMAT_PCM
                {
                    return(false);
                }

                AudioStreamInfo audioInfo = new AudioStreamInfo();
                audioInfo.BitsPerSample = wfx.wBitsPerSample;
                audioInfo.Channels      = wfx.nChannels;
                audioInfo.SampleRate    = wfx.nSamplesPerSec;
                audioInfo.StreamType    = StreamType.LPCM;

                MediaSocket inputSocket = new MediaSocket();
                MediaPin    inputPin    = new MediaPin();
                inputPin.StreamInfo = audioInfo;
                inputSocket.Pins.Add(inputPin);
                inputSocket.StreamType = StreamType.LPCM;

                m_audioCB.StreamNumber = ms.transcoder.Inputs.Count;
                ms.transcoder.Inputs.Add(inputSocket);
            }

            // set video input pin
            {
                if ((ms.videoType.majorType != DirectShowLib.MediaType.Video) ||
                    (ms.videoType.formatType != DirectShowLib.FormatType.VideoInfo))
                {
                    return(false);
                }

                VideoStreamInfo videoInfo = new VideoStreamInfo();
                VideoInfoHeader vih       = (VideoInfoHeader)Marshal.PtrToStructure(ms.videoType.formatPtr, typeof(VideoInfoHeader));

                if (vih.AvgTimePerFrame > 0)
                {
                    videoInfo.FrameRate = (double)10000000 / vih.AvgTimePerFrame;
                }

                videoInfo.Bitrate            = 0; //vih.BitRate;
                videoInfo.FrameHeight        = Math.Abs(vih.BmiHeader.Height);
                videoInfo.FrameWidth         = vih.BmiHeader.Width;
                videoInfo.DisplayRatioWidth  = videoInfo.FrameWidth;
                videoInfo.DisplayRatioHeight = videoInfo.FrameHeight;
                videoInfo.ScanType           = ScanType.Progressive;
                videoInfo.Duration           = 0;

                if (ms.videoType.subType == MediaSubType.MJPG)
                {
                    videoInfo.StreamType  = StreamType.Mjpeg;
                    videoInfo.ColorFormat = ColorFormat.YUV422;
                }
                else
                {
                    videoInfo.StreamType  = StreamType.UncompressedVideo;
                    videoInfo.ColorFormat = Util.GetColorFormat(ref ms.videoType.subType);
                }

                // unsupported capture format
                if (videoInfo.ColorFormat == ColorFormat.Unknown)
                {
                    return(false);
                }

                switch (videoInfo.ColorFormat)
                {
                case ColorFormat.BGR32:
                case ColorFormat.BGRA32:
                case ColorFormat.BGR24:
                case ColorFormat.BGR444:
                case ColorFormat.BGR555:
                case ColorFormat.BGR565:
                    videoInfo.FrameBottomUp = (vih.BmiHeader.Height > 0);
                    break;
                }

                MediaSocket inputSocket = new MediaSocket();
                MediaPin    inputPin    = new MediaPin();
                inputPin.StreamInfo = videoInfo;
                inputSocket.Pins.Add(inputPin);
                inputSocket.StreamType = StreamType.UncompressedVideo;

                m_videoCB.StreamNumber = ms.transcoder.Inputs.Count;
                ms.transcoder.Inputs.Add(inputSocket);
            }

            PresetDescriptor preset = comboPresets.SelectedItem as PresetDescriptor;
            MediaSocket      outputSocket;

            outputSocket      = Util.MediaSocketFromPreset(preset.Name);
            outputSocket.File = txtOutput.Text;

            SetRealTimeVideoMode(outputSocket);

            ms.transcoder.Outputs.Add(outputSocket);

            ms.transcoder.AudioLog = txtAudioLog.Text;

            if (!ms.transcoder.Open())
            {
                MessageBox.Show(ms.transcoder.Error.Message + "\n" + ms.transcoder.Error.Hint,
                                "Transcoder Open Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return(false);
            }

            return(true);
        }