The first part is identical to SaveFrameFromVideo, then we have to call GetBitmapBits with the pBuffer parameter set to null to get the size for the buffer of bytes that will contain the 24bpp image ( GetBitmapBits always returns 24bpp images). Using GetBitmapBits to avoid saving the image on disk is a bit trickier, since we need to deal with direct access to memory. (WinStructs.VIDEOINFOHEADER)Marshal.PtrToStructure(mediaType.pbFormat,
Windows media player frame by frame code#
Their implementation is straight forward:Ĭopy Code private static Size getVideoSize(_AMMediaType mediaType) They are openVideoStream and getVideoSize. You'll notice that two private methods are used here. Throw new InvalidVideoFileException( " No video stream was found") Throw new InvalidVideoFileException(getErrorMsg(( uint)ex.ErrorCode), ex) Target.Width, target.Height, outputBitmapFile) MediaDet.WriteBitmapBits(streamLength * percentagePosition, Target = scaleToFit(target, getVideoSize(mediaType)) calculates the REAL target size of our frame if (target = Size.Empty) If (openVideoStream(videoFile, out mediaDet, out mediaType)) PercentagePosition, " Valid range is 0.0. Throw new ArgumentOutOfRangeException( " percentagePosition", If (percentagePosition > 1 || percentagePosition < 0) Copy Code public static void SaveFrameFromVideo( string videoFile,ĭouble percentagePosition, string outputBitmapFile,