/// <summary> /// Get the next sample from the appropriate source given the specified payload and the recompression and /// slide stream settings for this segment. /// </summary> private bool getNextSample(PayloadType payload, out BufferChunk sample, out long timestamp, out bool newstream, out bool keyframe) { if (payload == PayloadType.dynamicAudio) { if (norecompression) { if (audiorecompression) { newstream = false; keyframe = false; return(mixer.GetNextStreamSample(out sample, out timestamp)); } else { keyframe = false; return(audioStreams[0].GetNextSample(out sample, out timestamp, out newstream)); } } else { newstream = false; keyframe = false; return(mixer.GetNextSample(out sample, out timestamp)); } } else if (payload == PayloadType.dynamicVideo) { if (norecompression) { if (useSlideStream) { newstream = false; //unsupported: //return slideStream.GetNextStreamSample(out sample, out timestamp, out keyframe); } else { return(videoStream.GetNextSample(out sample, out timestamp, out keyframe, out newstream)); } } else { //Note: keyframe is not relevant for uncompressed video. if (useSlideStream) { newstream = false; keyframe = false; return(slideStream.GetNextSample(out sample, out timestamp, out newstream)); } else { keyframe = false; return(videoStream.GetNextSample(out sample, out timestamp, out newstream)); } } } sample = null; timestamp = 0; newstream = false; keyframe = false; return(false); }
/// <summary> /// Capture stills from the video stream. Create a temporary directory and save the images there. /// Compile a list of DataItem objects to indicate when the slide transitions should take place. /// </summary> /// <returns></returns> public string Process() { ImageFilter.ImageFilter imgFilter = null; try { imgFilter = new ImageFilter.ImageFilter(); imgFilter.DifferenceThreshold = this.differenceThreshold; } catch { this.errorLog.Append("Video capture images in the presentation will not be filtered probably " + "because ImageMagick is not available in the configuration.\r\n"); } this.differenceMetrics = new List <double>(); metadata = new List <PresentationMgr.DataItem>(); RTUpdate rtu = new RTUpdate(); this.deckGuid = Guid.NewGuid(); rtu.DeckGuid = this.deckGuid; rtu.SlideSize = 1.0; rtu.DeckType = (Int32)DeckTypeEnum.Presentation; this.videoStream = new StreamMgr(videoDescriptor.VideoCname, videoDescriptor.VideoName, new DateTime(this.start), new DateTime(this.end), false, PayloadType.dynamicVideo); this.videoStream.ToRawWMFile(this.progressTracker); MediaTypeVideoInfo mtvi = videoStream.GetUncompressedVideoMediaType(); this.tempdir = Utility.GetTempDir(); Directory.CreateDirectory(this.tempdir); string filebase = "slide"; string extent = ".jpg"; int fileindex = 1; BufferChunk bc; long time; bool newStream; string previousFile = null; this.stopNow = false; while ((!stopNow) && (videoStream.GetNextSample(out bc, out time, out newStream))) { if ((time - lastFramegrab) >= (long)(this.frameGrabIntervalMs * Constants.TicksPerMs)) { DateTime dt = new DateTime(time); Debug.WriteLine("time=" + dt.ToString() + ";length=" + bc.Length.ToString()); lastFramegrab = time; string filepath = Path.Combine(tempdir, filebase + fileindex.ToString() + extent); PixelFormat pixelFormat = subtypeToPixelFormat(mtvi.SubType); Bitmap bm = new Bitmap(mtvi.VideoInfo.BitmapInfo.Width, mtvi.VideoInfo.BitmapInfo.Height, pixelFormat); BitmapData bd = bm.LockBits(new Rectangle(0, 0, mtvi.VideoInfo.BitmapInfo.Width, mtvi.VideoInfo.BitmapInfo.Height), ImageLockMode.ReadWrite, pixelFormat); Marshal.Copy(bc.Buffer, 0, bd.Scan0, bc.Length); bm.UnlockBits(bd); bm.RotateFlip(RotateFlipType.RotateNoneFlipY); if ((SCALE) && (mtvi.VideoInfo.BitmapInfo.Width >= 1280)) { int w = mtvi.VideoInfo.BitmapInfo.Width / 2; int h = mtvi.VideoInfo.BitmapInfo.Height / 2; Bitmap scaled = new Bitmap(bm, new Size(w, h)); scaled.Save(filepath, ImageFormat.Jpeg); } else { bm.Save(filepath, ImageFormat.Jpeg); } if (imgFilter != null) { string filterMsg; bool filterError; double metric; bool differ = imgFilter.ImagesDiffer(filepath, previousFile, out filterMsg, out filterError, out metric); if (filterError) { //this.errorLog.Append(filterMsg); Console.WriteLine(filterMsg); } if (!differ) { continue; } this.differenceMetrics.Add(metric); Console.WriteLine("Framegrab slide index: " + fileindex.ToString() + "; difference: " + metric.ToString() + "; time: " + dt.ToString()); } rtu.SlideIndex = fileindex - 1; // This is a zero-based index metadata.Add(new PresentationMgr.DataItem(time - this.offset, PresentationMgr.CopyRTUpdate(rtu))); fileindex++; previousFile = filepath; } } return(null); }