コード例 #1
0
ファイル: VideoSource.cs プロジェクト: nixxquality/FFMSSharp
 private void MarkLastFrameAsInvalid()
 {
     if (LastFrame != null)
         LastFrame.Invalid = true;
     LastFrame = null;
 }
コード例 #2
0
ファイル: VideoSource.cs プロジェクト: nixxquality/FFMSSharp
        /// <summary>
        /// Retrieves a video frame at a timestamp
        /// </summary>
        /// <remarks>
        /// <para>In FFMS2, the equivalent is <c>FFMS_GetFrameByTime</c>.</para>
        /// <para>The returned frame is owned by the given <see cref="VideoSource">VideoSource object</see>, and remains valid until the video source is destroyed, a different frame is requested from the video source, or the video source's input or output format is changed.</para>
        /// <para>Does the exact same thing as <see cref="GetFrame(int)">GetFrame</see> except instead of giving it a frame number you give it a timestamp in seconds, and it will retrieve the frame that starts closest to that timestamp.</para>
        /// <para>This function exists for the people who are too lazy to build and traverse a mapping between frame numbers and timestamps themselves.</para>
        /// </remarks>
        /// <param name="time">Timestamp</param>
        /// <returns>The generated <see cref="Frame">Frame object</see>.</returns>
        /// <seealso cref="GetFrame(int)"/>
        /// <exception cref="ArgumentOutOfRangeException">Trying to access a Frame that doesn't exist.</exception>
        public Frame GetFrame(double time)
        {
            if (time < 0 || time > LastTime)
                throw new ArgumentOutOfRangeException(@"time", "That frame doesn't exist.");

            var err = new FFMS_ErrorInfo
            {
                BufferSize = 1024,
                Buffer = new String((char) 0, 1024)
            };

            MarkLastFrameAsInvalid();

            IntPtr framePtr;
            lock (this)
            {
                 framePtr = NativeMethods.FFMS_GetFrameByTime(_nativePtr, time, ref err);
            }

            if (framePtr == IntPtr.Zero)
            {
                throw new NotImplementedException(string.Format(System.Globalization.CultureInfo.CurrentCulture, "Unknown FFMS2 error encountered: ({0}, {1}, '{2}'). Please report this issue on FFMSSharp's GitHub.", err.ErrorType, err.SubType, err.Buffer));
            }

            LastFrame = new Frame(framePtr);
            return LastFrame;
        }