Exemplo n.º 1
0
        ///////////////////////////////////////////////////////////////////////////////
        // Construction and Initializing methods                                     //
        ///////////////////////////////////////////////////////////////////////////////
        #region CONSTRUCTION

        /// <summary>
        /// Initializes a new instance of the DSRecordWithDMO class.
        /// </summary>
        /// <param name="newImageHandler">An <see cref="ImageFromVectorGraphics"/>
        /// with the callback.</param>
        /// <param name="newVideoExportProperties">A <see cref="VideoExportProperties"/> with
        /// the video export properties.</param>
        /// <param name="newPreviewWindow">A <see cref="Control"/> with
        /// the preview panel.</param>
        public DSRecordWithDMO(
            ImageFromVectorGraphics newImageHandler,
            VideoExportProperties newVideoExportProperties,
            Control newPreviewWindow)
        {
            try
            {
                // set the image provider
                this.imageHandler = newImageHandler;

                // set the video properties
                this.videoExportProperties = newVideoExportProperties;

                if (this.videoExportProperties.OutputVideoProperties.VideoCompressor != string.Empty)
                {
                    // Create the filter for the selected video compressor
                    this.videoCompressor = DirectShowUtils.CreateFilter(
                        FilterCategory.VideoCompressorCategory,
                        this.videoExportProperties.OutputVideoProperties.VideoCompressor);
                }

                if (this.videoExportProperties.OutputVideoProperties.AudioCompressor != string.Empty)
                {
                    // Create the filter for the selected video compressor
                    this.audioCompressor = DirectShowUtils.CreateFilter(
                        FilterCategory.AudioCompressorCategory,
                        this.videoExportProperties.OutputVideoProperties.AudioCompressor);
                }

                // Set up preview window
                this.previewWindow = newPreviewWindow;

                // Set up the graph
                if (!this.SetupGraph())
                {
                    throw new OperationCanceledException("The DirectShow graph could not be created,"
                                                         + " try to use another video or audio compressor.");
                }
            }
            catch
            {
                this.Dispose();
                throw;
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// Sets the parameters for the mixer DMO according to
        /// the given <see cref="VideoExportProperties"/>
        /// </summary>
        /// <param name="dmoWrapperFilter">The <see cref="IBaseFilter"/>
        /// that contains the DMO.</param>
        /// <param name="exportProperties">The <see cref="VideoExportProperties"/>
        /// to use.</param>
        private void SetDMOParams(IBaseFilter dmoWrapperFilter, VideoExportProperties exportProperties)
        {
            int hr;

            IMediaParams dmoParams        = dmoWrapperFilter as IMediaParams;
            MPData       outputBackground = new MPData();
            MPData       streamTop        = new MPData();
            MPData       streamLeft       = new MPData();
            MPData       streamHeight     = new MPData();
            MPData       streamWidth      = new MPData();
            MPData       streamAlpha      = new MPData();

            // Get Background color
            Color bkg = exportProperties.OutputVideoColor;

            // Convert to integer value AARRGGBB
            outputBackground.vInt = bkg.ToArgb();

            // Set DMO param
            hr = dmoParams.SetParam(0, outputBackground);
            DMOError.ThrowExceptionForHR(hr);

            streamLeft.vFloat = exportProperties.GazeVideoProperties.StreamPosition.Left;
            hr = dmoParams.SetParam(1, streamLeft);
            DMOError.ThrowExceptionForHR(hr);

            streamTop.vFloat = exportProperties.GazeVideoProperties.StreamPosition.Top;
            hr = dmoParams.SetParam(2, streamTop);
            DMOError.ThrowExceptionForHR(hr);

            streamWidth.vFloat = exportProperties.GazeVideoProperties.StreamPosition.Width;
            hr = dmoParams.SetParam(3, streamWidth);
            DMOError.ThrowExceptionForHR(hr);

            streamHeight.vFloat = exportProperties.GazeVideoProperties.StreamPosition.Height;
            hr = dmoParams.SetParam(4, streamHeight);
            DMOError.ThrowExceptionForHR(hr);

            streamAlpha.vFloat = exportProperties.GazeVideoProperties.StreamAlpha;
            hr = dmoParams.SetParam(5, streamAlpha);
            DMOError.ThrowExceptionForHR(hr);

            streamLeft.vFloat = exportProperties.UserVideoProperties.StreamPosition.Left;
            hr = dmoParams.SetParam(6, streamLeft);
            DMOError.ThrowExceptionForHR(hr);

            streamTop.vFloat = exportProperties.UserVideoProperties.StreamPosition.Top;
            hr = dmoParams.SetParam(7, streamTop);
            DMOError.ThrowExceptionForHR(hr);

            streamWidth.vFloat = exportProperties.UserVideoProperties.StreamPosition.Width;
            hr = dmoParams.SetParam(8, streamWidth);
            DMOError.ThrowExceptionForHR(hr);

            streamHeight.vFloat = exportProperties.UserVideoProperties.StreamPosition.Height;
            hr = dmoParams.SetParam(9, streamHeight);
            DMOError.ThrowExceptionForHR(hr);

            streamAlpha.vFloat = exportProperties.UserVideoProperties.StreamAlpha;
            hr = dmoParams.SetParam(10, streamAlpha);
            DMOError.ThrowExceptionForHR(hr);
        }
Exemplo n.º 3
0
    /// <summary>
    /// This method asks the user for a video filename and raises
    /// a <see cref="VideoPropertiesDialog"/> to define the video
    /// export properties.
    /// </summary>
    /// <param name="videoExportProperties">Out. A <see cref="VideoExportProperties"/>
    /// that is generated in this method.</param>
    /// <returns><strong>True</strong> if the user selected valid properties,
    /// otherwise <strong>false</strong>.</returns>
    private bool GetVideoProperties(out VideoExportProperties videoExportProperties)
    {
      videoExportProperties = new VideoExportProperties();

      if (this.sfdVideo.ShowDialog() == DialogResult.OK)
      {
        videoExportProperties.UserVideoTempFile = Path.GetTempFileName();

        videoExportProperties.UserVideoProperties.StreamFilename = this.usercamVideoPlayer.MovieFile;
        videoExportProperties.UserVideoProperties.StreamSize = this.usercamVideoPlayer.VideoSize;
        videoExportProperties.UserVideoProperties.StreamScreenshot =
          this.usercamVideoPlayer.Screenshot;
        videoExportProperties.UserVideoProperties.StreamName = "Uservideo";
        videoExportProperties.UserVideoProperties.StreamStartTime = this.userVideoStartTime + this.trialTimeLine.SectionStartTime;
        videoExportProperties.UserVideoProperties.StreamEndTime = this.userVideoStartTime + this.trialTimeLine.SectionEndTime;

        videoExportProperties.GazeVideoProperties.StreamScreenshot =
          (Bitmap)this.Picture.RenderToImage();
        videoExportProperties.GazeVideoProperties.StreamName = "Gaze video";
        videoExportProperties.GazeVideoProperties.StreamStartTime = this.trialTimeLine.SectionStartTime;
        videoExportProperties.GazeVideoProperties.StreamEndTime = this.trialTimeLine.SectionEndTime;
        videoExportProperties.GazeVideoProperties.StreamSize = videoExportProperties.GazeVideoProperties.StreamScreenshot.Size;

        VideoPropertiesDialog videoPropertiesDlg = new VideoPropertiesDialog();
        videoPropertiesDlg.VideoExportProperties = videoExportProperties;

        if (videoPropertiesDlg.ShowDialog() == DialogResult.OK)
        {
          videoExportProperties = videoPropertiesDlg.VideoExportProperties;

          // Save filename in member.
          videoExportProperties.OutputVideoProperties.Filename = this.sfdVideo.FileName;
          return true;
        }
      }

      return false;
    }
Exemplo n.º 4
0
    /// <summary>
    /// This method cuts the given user video to the
    /// appropriate length by copying the selected part to
    /// a new temporary file with the new output properties
    /// </summary>
    /// <param name="videoExportProperties">The <see cref="VideoExportProperties"/>
    /// to use during export.</param>
    private void CreatePartialUserVideo(VideoExportProperties videoExportProperties)
    {
      this.newSplash.IsPreviewVisible = false;
      this.newSplash.Header = "Preparing User Video";

      string userVideoFile = this.videoExportProperties.UserVideoProperties.StreamFilename;

      MediaInfo videoHeader = new MediaInfo();
      videoHeader.Open(userVideoFile);
      bool hasVideo = videoHeader.Get(StreamKind.Video, 0, "ID") != string.Empty;
      bool hasAudio = videoHeader.Get(StreamKind.Audio, 0, "ID") != string.Empty;
      videoHeader.Close();

      // Init DESCombine with audio and/or video support depending on
      // what the user video contains.
      // audio is "", if there is no audio stream
      this.desCombine = new DESCombine(
        this.videoExportProperties.OutputVideoProperties.FrameRate,
        32,
        this.videoExportProperties.UserVideoProperties.StreamSize.Width,
        this.videoExportProperties.UserVideoProperties.StreamSize.Height,
        hasAudio,
        hasVideo);

      if (hasVideo && hasAudio)
      {
        this.desCombine.AddAVFile(
          this.videoExportProperties.UserVideoProperties.StreamFilename,
          this.videoExportProperties.UserVideoProperties.StreamStartTime * 10000,
          this.videoExportProperties.UserVideoProperties.StreamEndTime * 10000);
      }
      else if (hasVideo)
      {
        this.desCombine.AddVideoFile(
          this.videoExportProperties.UserVideoProperties.StreamFilename,
          this.videoExportProperties.UserVideoProperties.StreamStartTime * 10000,
          this.videoExportProperties.UserVideoProperties.StreamEndTime * 10000);
      }
      else if (hasAudio)
      {
        this.desCombine.AddAudioFile(
          this.videoExportProperties.UserVideoProperties.StreamFilename,
          this.videoExportProperties.UserVideoProperties.StreamStartTime * 10000,
          this.videoExportProperties.UserVideoProperties.StreamEndTime * 10000);
      }

      IBaseFilter videoCompressor = null;
      if (this.videoExportProperties.OutputVideoProperties.VideoCompressor != string.Empty)
      {
        // Create the filter for the selected video compressor
        videoCompressor = DirectShowUtils.CreateFilter(
          FilterCategory.VideoCompressorCategory,
          this.videoExportProperties.OutputVideoProperties.VideoCompressor);
      }

      IBaseFilter audioCompressor = null;
      if (this.videoExportProperties.OutputVideoProperties.AudioCompressor != string.Empty)
      {
        // Create the filter for the selected video compressor
        audioCompressor = DirectShowUtils.CreateFilter(
          FilterCategory.AudioCompressorCategory,
          this.videoExportProperties.OutputVideoProperties.AudioCompressor);
      }

      this.desCombine.RenderToAVI(
        this.videoExportProperties.UserVideoTempFile,
        videoCompressor,
        audioCompressor,
        null,
        null);

      this.desCombine.Completed += new EventHandler(this.desCombine_Completed);
      this.desCombine.StartRendering();
    }
Exemplo n.º 5
0
    /// <summary>
    /// Sets the parameters for the mixer DMO according to
    /// the given <see cref="VideoExportProperties"/>
    /// </summary>
    /// <param name="dmoWrapperFilter">The <see cref="IBaseFilter"/>
    /// that contains the DMO.</param>
    /// <param name="exportProperties">The <see cref="VideoExportProperties"/>
    /// to use.</param>
    private void SetDMOParams(IBaseFilter dmoWrapperFilter, VideoExportProperties exportProperties)
    {
      int hr;

      IMediaParams dmoParams = dmoWrapperFilter as IMediaParams;
      MPData outputBackground = new MPData();
      MPData streamTop = new MPData();
      MPData streamLeft = new MPData();
      MPData streamHeight = new MPData();
      MPData streamWidth = new MPData();
      MPData streamAlpha = new MPData();

      // Get Background color
      Color bkg = exportProperties.OutputVideoColor;

      // Convert to integer value AARRGGBB
      outputBackground.vInt = bkg.ToArgb();

      // Set DMO param
      hr = dmoParams.SetParam(0, outputBackground);
      DMOError.ThrowExceptionForHR(hr);

      streamLeft.vFloat = exportProperties.GazeVideoProperties.StreamPosition.Left;
      hr = dmoParams.SetParam(1, streamLeft);
      DMOError.ThrowExceptionForHR(hr);

      streamTop.vFloat = exportProperties.GazeVideoProperties.StreamPosition.Top;
      hr = dmoParams.SetParam(2, streamTop);
      DMOError.ThrowExceptionForHR(hr);

      streamWidth.vFloat = exportProperties.GazeVideoProperties.StreamPosition.Width;
      hr = dmoParams.SetParam(3, streamWidth);
      DMOError.ThrowExceptionForHR(hr);

      streamHeight.vFloat = exportProperties.GazeVideoProperties.StreamPosition.Height;
      hr = dmoParams.SetParam(4, streamHeight);
      DMOError.ThrowExceptionForHR(hr);

      streamAlpha.vFloat = exportProperties.GazeVideoProperties.StreamAlpha;
      hr = dmoParams.SetParam(5, streamAlpha);
      DMOError.ThrowExceptionForHR(hr);

      streamLeft.vFloat = exportProperties.UserVideoProperties.StreamPosition.Left;
      hr = dmoParams.SetParam(6, streamLeft);
      DMOError.ThrowExceptionForHR(hr);

      streamTop.vFloat = exportProperties.UserVideoProperties.StreamPosition.Top;
      hr = dmoParams.SetParam(7, streamTop);
      DMOError.ThrowExceptionForHR(hr);

      streamWidth.vFloat = exportProperties.UserVideoProperties.StreamPosition.Width;
      hr = dmoParams.SetParam(8, streamWidth);
      DMOError.ThrowExceptionForHR(hr);

      streamHeight.vFloat = exportProperties.UserVideoProperties.StreamPosition.Height;
      hr = dmoParams.SetParam(9, streamHeight);
      DMOError.ThrowExceptionForHR(hr);

      streamAlpha.vFloat = exportProperties.UserVideoProperties.StreamAlpha;
      hr = dmoParams.SetParam(10, streamAlpha);
      DMOError.ThrowExceptionForHR(hr);
    }
Exemplo n.º 6
0
    ///////////////////////////////////////////////////////////////////////////////
    // Construction and Initializing methods                                     //
    ///////////////////////////////////////////////////////////////////////////////
    #region CONSTRUCTION

    /// <summary>
    /// Initializes a new instance of the DSRecordWithDMO class.
    /// </summary>
    /// <param name="newImageHandler">An <see cref="ImageFromVectorGraphics"/>
    /// with the callback.</param>
    /// <param name="newVideoExportProperties">A <see cref="VideoExportProperties"/> with 
    /// the video export properties.</param>
    /// <param name="newPreviewWindow">A <see cref="Control"/> with 
    /// the preview panel.</param>
    public DSRecordWithDMO(
      ImageFromVectorGraphics newImageHandler,
      VideoExportProperties newVideoExportProperties,
      Control newPreviewWindow)
    {
      try
      {
        // set the image provider
        this.imageHandler = newImageHandler;

        // set the video properties
        this.videoExportProperties = newVideoExportProperties;

        if (this.videoExportProperties.OutputVideoProperties.VideoCompressor != string.Empty)
        {
          // Create the filter for the selected video compressor
          this.videoCompressor = DirectShowUtils.CreateFilter(
            FilterCategory.VideoCompressorCategory,
            this.videoExportProperties.OutputVideoProperties.VideoCompressor);
        }

        if (this.videoExportProperties.OutputVideoProperties.AudioCompressor != string.Empty)
        {
          // Create the filter for the selected video compressor
          this.audioCompressor = DirectShowUtils.CreateFilter(
            FilterCategory.AudioCompressorCategory,
            this.videoExportProperties.OutputVideoProperties.AudioCompressor);
        }

        // Set up preview window
        this.previewWindow = newPreviewWindow;

        // Set up the graph
        if (!this.SetupGraph())
        {
          throw new OperationCanceledException("The DirectShow graph could not be created,"
            + " try to use another video or audio compressor.");
        }
      }
      catch
      {
        this.Dispose();
        throw;
      }
    }