/// <summary>Loads a video from a file into a MediaDet.</summary> /// <param name="filename">The path to the file to be loaded.</param> /// <param name="mediaType">The media type of the video loaded.</param> /// <returns>The MediaDet configured with the loaded video.</returns> private static MediaDetClass LoadVideo(string filename, out _AMMediaType mediaType) { // Initialize the MediaDet with the video file MediaDetClass mediaDet = new MediaDetClass(); mediaDet.Filename = filename; mediaType = new _AMMediaType(); // Loop through each of the streams in the video searching for the actual video stream int numberOfStreams = mediaDet.OutputStreams; for (int i = 0; i < numberOfStreams; i++) { // Return when we find the video stream, leaving the MediaDet set to // use that stream. mediaDet.CurrentStream = i; if (mediaDet.StreamType == MEDIATYPE_Video) { mediaType = mediaDet.StreamMediaType; return(mediaDet); } } // No video stream found. Clean up and error out. Marshal.ReleaseComObject(mediaDet); throw new ArgumentOutOfRangeException("filename", "No video stream found."); }
/// <summary> /// tries to open a video file. If successful it makes available MediaDetClass and _AMMediaType instances of the current file /// </summary> /// <param name="videoFile">Path to the video file</param> /// <param name="mediaDetClass"></param> /// <param name="aMMediaType"></param> /// <returns>true for success, false for failure (no video stream, file not supported, ...)</returns> public static bool openVideoStream(string videoFile, out IMediaDet mediaDet, out _AMMediaType aMMediaType) { mediaDet = new MediaDetClass(); //loads file mediaDet.Filename = videoFile; //gets # of streams int streamsNumber = mediaDet.OutputStreams; //finds a video stream _AMMediaType mediaType; for (int i = 0; i < streamsNumber; i++) { mediaDet.CurrentStream = i; mediaType = mediaDet.StreamMediaType; if (mediaType.majortype == JockerSoft.Media.MayorTypes.MEDIATYPE_Video) { //video stream found aMMediaType = mediaType; return true; } } //no video stream found Marshal.ReleaseComObject(mediaDet); mediaDet = null; aMMediaType = new _AMMediaType(); return false; }
/// <summary> /// 试图打开一视频文件,如果成功它便可以正常实例化成为一个合法的对象- /// MediaDetClasstries to open a video file. If successful it makes available MediaDetClass and _AMMediaType instances of the current file /// </summary> /// <param name="videoFile">视频文件路径</param> /// <param name="mediaDetClass">实例</param> /// <param name="aMMediaType">视频类型</param> /// <returns>操作结果-true for success, false for failure (no video stream, file not supported, ...)</returns> private bool openVideoStream(string videoFile, out MediaDetClass mediaDetClass, out _AMMediaType aMMediaType) { MediaDetClass mediaDet = new MediaDetClass(); //loads file //加载视频文件 mediaDet.Filename = videoFile; //gets # of streams //获得视频文件的全部流 int streamsNumber = mediaDet.OutputStreams; //finds a video stream and grabs a frame //获得视频文件流,并抓取一桢 for (int i = 0; i < streamsNumber; i++) { mediaDet.CurrentStream = i; _AMMediaType mediaType = mediaDet.StreamMediaType; if (mediaType.majortype == Tz888.Common.MayorTypes.MEDIATYPE_Video) { mediaDetClass = mediaDet; aMMediaType = mediaType; return(true); } } mediaDetClass = null; aMMediaType = new _AMMediaType(); return(false); }
void Scan() { md = new MediaDetClass(); Image img; md.Filename = fileName; md.CurrentStream = 0; int len = (int)md.StreamLength; EncryptDecryptVedio.FrameRate = md.FrameRate; for (float i = 0.0f; i < len; i = i + interval) { MainForm.counter++; string fBitmapName = storagePath + Path.GetFileNameWithoutExtension(fileName) + "_" + MainForm.counter.ToString(); md.WriteBitmapBits(i, 320, 240, fBitmapName + ".bmp"); img = Image.FromFile(fBitmapName + ".bmp"); img.Save(fBitmapName + ".jpg", ImageFormat.Jpeg); Program.images_name[Program.index_vedio] = fBitmapName; Program.index_vedio++; img.Dispose(); System.IO.File.Delete(fBitmapName + ".bmp"); } }
/// <summary> /// Public Constructor: /// Initialize Component inside Photo Preview Window /// Initialize video preview components /// Initialize various variables in Photo Preview Window /// Load the picture/video accordingly /// </summary> /// <param name="source">source file full path</param> /// <param name="target">target file full path</param> /// <param name="confWin">Form from which this from is accessed</param> public PhotoPreviewWindow(string filePath, Form previewWin) { InitializeComponent(); md = new MediaDetClass(); previewer = new VideoPreview("tmp"); this.pathname = filePath; this.WindowState = FormWindowState.Maximized; this.titleBox.Text = Path.GetFileNameWithoutExtension(filePath); this.Text = "Preview: " + Path.GetFileNameWithoutExtension(filePath); preview = previewWin; if (Photo.isPhoto(filePath)) { try { this.pictureBox.Image = Image.FromFile(filePath); } catch (Exception pe) { pictureBox.Image = global::DoubleSnap.Properties.Resources.no_preview; } } else if (Video.isVideoPreviewable(filePath)) { try { previewer.deleteTmpBmpFiles(MainWindow.storagePath); md.Filename = filePath; md.CurrentStream = 0; videoLen = (int)md.StreamLength; pictureBox.Image = global::DoubleSnap.Properties.Resources.hover_mouse; } catch (Exception pe) { pictureBox.Image = global::DoubleSnap.Properties.Resources.no_preview; } } else pictureBox.Image = global::DoubleSnap.Properties.Resources.no_preview; }
//////////////////////////////////////////////////////////////////////////私有函数 /// <summary> /// 如果打开视频文件成功,便可以正常实例化成为一个合法的对象 /// </summary> /// <param name="videoFile">视频文件的绝对路径</param> /// <param name="mediaDetClass">MediaDetClass类的实例</param> /// <param name="aMMediaType">视频类型</param> /// <returns>true为找到视频流,false为没有发现视频流(或不支持此视频格式)</returns> private static bool OpenVideoStream(string videoFile, out MediaDetClass mediaDetClass, out _AMMediaType aMMediaType) { MediaDetClass mediaDet = new MediaDetClass(); mediaDet.Filename = videoFile; //加载视频文件 int streamsNumber = mediaDet.OutputStreams; //获得输出流的个数(只统计媒体类型为MEDIATYPE_Video和MEDIATYPE_Audio的流) //获得视频文件流,并抓取一帧 for (int i = 0; i < streamsNumber; i++) { mediaDet.CurrentStream = i; _AMMediaType mediaType = mediaDet.StreamMediaType; //发现流媒体类型为视频时,传出对象 if (mediaType.majortype == MayorTypes.MEDIATYPE_Video) { mediaDetClass = mediaDet; aMMediaType = mediaType; return(true); } } //没有发现视频流时,对象置空 mediaDetClass = null; aMMediaType = new _AMMediaType(); return(false); }
int videoLen; //number of video frames; #endregion Fields #region Constructors /// <summary> /// Public Constructor: /// Initialize Component /// Initialize mainWindow, MediaDetClass and VideoPreview /// </summary> public BatchRenameWindow() { InitializeComponent(); controller = MainWindow.controller; md = new MediaDetClass(); previewer = new VideoPreview("tmp"); }
private static Bitmap generateMPlayerSceneShotOnDisk(String path, MediaDetClass mediaDet, double position, int width, int height) { String filename = System.IO.Path.GetTempPath() + System.Guid.NewGuid().ToString(); System.IO.Directory.CreateDirectory(filename); String usingFilename = null; String format = "{0}:{1}:{2}.{3}"; TimeSpan tspan = TimeSpan.FromSeconds((double)position); format = string.Format(format, tspan.Hours, tspan.Minutes, tspan.Seconds, tspan.Milliseconds); String cmdArgs = " -vo jpeg:quality=100:outdir=\\\"" + filename + "\\\" -frames 1 -nosound -noframedrop -ss " + format + " \"" + mediaDet.Filename + "\""; System.Diagnostics.Process n = new System.Diagnostics.Process(); n.StartInfo.FileName = path; n.StartInfo.Arguments = cmdArgs; n.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; n.Start(); n.WaitForExit(); n.Dispose(); n = null; usingFilename = filename + "\\00000001.jpg"; Bitmap bmp = null; if (System.IO.File.Exists(usingFilename)) { bmp = new Bitmap(usingFilename); } //cleanup return(bmp); }
int videoLen; //number of video frames; #endregion Fields #region Constructors /// <summary> /// Public Constructor: /// Initialize Component inside Smart Group Window /// Initialize controller /// Initialize video preview components /// </summary> public SmartGroupWindow() { InitializeComponent(); //mainWindow = Program.mainWindow; controller = MainWindow.controller; md = new MediaDetClass(); previewer = new VideoPreview("tmp"); }
int videoLen; //number of video frames; #endregion Fields #region Constructors /// <summary> /// Public Constructor: /// Initialize Component inside Photo Preview Window /// Initialize video preview components /// Initialize various variables in Photo Preview Window public PhotoPreviewWindow() { InitializeComponent(); this.WindowState = FormWindowState.Maximized; this.titleBox.Text = "Image Title Here..."; md = new MediaDetClass(); previewer = new VideoPreview("tmp"); }
//constructors public MDWrapper(string nazwa_pliku) { mD = new MediaDetClass(); mD.Filename=nazwa_pliku; mD.CurrentStream = 0; FrameRate=mD.FrameRate; //in fps MediaLength=mD.StreamLength; //in seconds }
private static Bitmap generateSceneshotOnDisk(MediaDetClass mediaDet, double position, int width, int height) { //Gen unique Filepath String filename = System.IO.Path.GetTempPath() + System.Guid.NewGuid().ToString(); mediaDet.WriteBitmapBits(position, width, height, filename); Bitmap bmp = new Bitmap(filename); return(bmp); }
int videoLen; //number of video frames; #endregion Fields #region Constructors /// <summary> /// Public Constructor: /// Initialize Component /// Initialize mainWindow and controller /// Set the string as jobName /// Initialize video preview components /// /// <param name="str">Job name</param> /// </summary> public PreviewWindow(string str) { InitializeComponent(); mainWindow = Program.getMainWindow(); controller = MainWindow.controller; this.str = str; md = new MediaDetClass(); previewer = new VideoPreview("tmp"); }
int targetVideoLen; //number of video frames; #endregion Fields #region Constructors /// <summary> /// Public Constructor: /// Initialize Component /// Initialize mainWindow and controller /// Set the initial text of FileNameLabel /// Initialize Video Preview Component /// </summary> public ConflictWindow() { InitializeComponent(); mainWindow = Program.getMainWindow(); controller = MainWindow.controller; warningLabel.Hide(); sourceFileNameLabel.Text = ""; targetFileNameLabel.Text = ""; targetMd = new MediaDetClass(); sourceMd = new MediaDetClass(); sourcePreviewer = new VideoPreview("tmp"); targetPreviewer = new VideoPreview("tmp"); successful = false; }
public static Bitmap generateSceneshot(CaptureType type, String exePath, MediaDetClass mediaDet, double position, int width, int height) { if (type == CaptureType.mplayer) { return(generateMPlayerSceneShotOnDisk(exePath, mediaDet, position, width, height)); } else if (type == CaptureType.ffmpeg) { return(generateFFMpegSceneShotOnDisk(exePath, mediaDet, position, width, height)); } else if (type == CaptureType.@internal) { return(generateSceneshotInMemory(mediaDet, position, width, height)); } else { return(null); } }
private static Bitmap generateSceneshotInMemory(MediaDetClass mediaDet, double position, int width, int height) { Bitmap bmp = null; unsafe { //equal to sizeof(CommonClasses.BITMAPINFOHEADER); int bmpinfoheaderSize = 40; //get size for buffer int bufferSize = (((width * height) * 24) / 8) + bmpinfoheaderSize; //equal to mediaDet.GetBitmapBits // (0d, ref bufferSize, ref *buffer, target.Width, target.Height); //allocates enough memory to store the frame IntPtr frameBuffer = System.Runtime.InteropServices.Marshal.AllocHGlobal(bufferSize); byte *frameBuffer2 = (byte *)frameBuffer.ToPointer(); //gets bitmap, save in frameBuffer2 mediaDet.GetBitmapBits(position, ref bufferSize, ref *frameBuffer2, width, height); //now in buffer2 we have a BITMAPINFOHEADER structure //followed by the DIB bits IntPtr newImage = new IntPtr(frameBuffer2 + bmpinfoheaderSize); bmp = new Bitmap(width, height, width * 3, System.Drawing.Imaging.PixelFormat.Format24bppRgb, newImage); //1. Version //bmp.RotateFlip(RotateFlipType.Rotate180FlipX); //2. Version //bmp.RotateFlip(RotateFlipType.Rotate90FlipX); //bmp.RotateFlip(RotateFlipType.Rotate90FlipY); //Test bmp.RotateFlip(RotateFlipType.RotateNoneFlipY); System.Runtime.InteropServices.Marshal.FreeHGlobal(frameBuffer); } return(bmp); }
/// <summary>Dispose of the instance.</summary> public void Dispose() { if (_mediaDetector != null) { // Free the frame buffer _frameBuffer.Dispose(); _frameBuffer = null; // Free the media type if (_mediaType.cbFormat != 0) { Marshal.FreeCoTaskMem(new IntPtr(_mediaType.cbFormat)); } _mediaType = new _AMMediaType(); // Release the media detector Marshal.ReleaseComObject(_mediaDetector); _mediaDetector = null; } }
/// <summary>Initialize the VideoFrameReader.</summary> /// <param name="path">The path to the video to load.</param> public VideoFrameReader(string path) { if (path == null) { throw new ArgumentNullException(path); } // Load the video, determine the size of a frame in the video, // determine the length of the video, and calculate the number of frames in it. _mediaDetector = LoadVideo(path, out _mediaType); _frameSize = GetFrameSize(_mediaType); _streamLength = _mediaDetector.StreamLength; _numberOfFrames = (int)(_streamLength * _mediaDetector.FrameRate); // Create an unmanaged buffer to use in the frame extraction process. // We need a buffer large enough to store three bytes per pixel (RGB) // plus the size of a BITMAPINFOHEADER structure. _headerSize = Marshal.SizeOf(typeof(BITMAPINFOHEADER)); _bufferSize = (_frameSize.Width * _frameSize.Height * 3) + _headerSize; _frameBuffer = SafeLocalAllocHandle.LocalAlloc(_bufferSize); }
private static Bitmap generateFFMpegSceneShotOnDisk(String ffmpegpath, MediaDetClass mediaDet, double position, int width, int height) { String filename = System.IO.Path.GetTempPath() + System.Guid.NewGuid().ToString(); String usingFilename = null; String format = "{0}:{1}:{2}.{3}"; TimeSpan tspan = TimeSpan.FromSeconds((double)position); format = string.Format(format, tspan.Hours, tspan.Minutes, tspan.Seconds, tspan.Milliseconds); String cmdArgs = " -an -ss " + format + " -r 1 -t 1 -i \"" + mediaDet.Filename + "\" -f image2 -s " + width + "x" + height + " \"" + filename + "\""; System.Diagnostics.Process n = new System.Diagnostics.Process(); n.StartInfo.FileName = ffmpegpath; n.StartInfo.Arguments = cmdArgs; n.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; n.Start(); n.WaitForExit(); n.Dispose(); n = null; //Drecks Filenamenbestimmung wegen DropFrames // if (System.IO.File.Exists(filename + "_2")) // { // usingFilename = filename + "_2"; // } // else // { // usingFilename = filename + "_1"; // } usingFilename = filename; Bitmap bmp = null; if (System.IO.File.Exists(usingFilename)) { bmp = new Bitmap(usingFilename); } //cleanup return(bmp); }
/// <summary> /// Private method to make proper form closing by release all the resource /// </summary> private void ConflictPreviewWindow_FormClosed(object sender, FormClosedEventArgs e) { if (this.sourcePicture.Image != null) { this.sourcePicture.Image.Dispose(); this.sourcePicture.Image = null; } if (this.targetPicture.Image != null) { this.targetPicture.Image.Dispose(); this.targetPicture.Image = null; } sourceMd = null; targetMd = null; GC.Collect(); GC.WaitForPendingFinalizers(); this.Hide(); conflict.Show(); }
/// <summary> /// Private action to proceed from Conflict Window /// </summary> private void confirmButton_Click(object sender, EventArgs e) { bool check = false; foreach (ListViewItem items in resolvedList.Items) { if (items.Text.Equals(star)) { warningLabel.Show(); check = true; break; } } if (check) return; successful = true; if (sourcePictureBox.Image != null) { sourcePictureBox.Image.Dispose(); sourcePictureBox.Image = null; } if (targetPictureBox.Image != null) { targetPictureBox.Image.Dispose(); targetPictureBox.Image = null; } for (int i = 0; i < resolvedList.Items.Count; i++) { if (sourceList.Items[i].Text.Equals(star))//Keep [2] from source move to [0] { controller.syncMoveToSource(MainWindow.syncError, resolvedList.Items[i].Text); } else if (targetList.Items[i].Text.Equals(star))//Keep [3] from target move to [1] { controller.syncMoveToTarget(MainWindow.syncError, resolvedList.Items[i].Text); } } targetPreviewer.deleteTmpBmpFiles(MainWindow.storagePath2); sourcePreviewer.deleteTmpBmpFiles(MainWindow.storagePath); targetMd = null; sourceMd = null; GC.Collect(); GC.WaitForPendingFinalizers(); this.Close(); }
/// <summary> /// Handles the Click event of the btnFileOpen_Click control. /// opens a video file /// </summary> private void btnFileOpen_Click(object sender, EventArgs e) { OpenFileDialog dialog = new OpenFileDialog(); if (dialog.ShowDialog() == DialogResult.OK) { try { _fileName = dialog.FileName; //create the MediaDetClass and set its properties md = new MediaDetClass(); md.Filename = _fileName; md.CurrentStream = 0; int streamLength = (int)md.StreamLength; //fix a few Gui stuff lblFileInfo.Text = Path.GetFileName(_fileName) + StaticClasses.NL + "Length: " + streamLength.ToString() + "s"; this.trackBarTime.Enabled = true; this.btnBackward.Enabled = true; this.btnForward.Enabled = true; trackBarTime.Minimum = 0; trackBarTime.Maximum = streamLength; trackBarTime.Value = 0; // loads first frame into the pictureBox _pictureBox.Image = CaptureFrame(trackBarTime.Value); } catch (Exception ex) { StaticClasses.ShowException(ex); } } }
/// <summary> /// Private action to show the conflict preview window based on target list index changed /// </summary> private void targetList_MouseDoubleClick(object sender, MouseEventArgs e) { string source = string.Empty; string target = string.Empty; int index = targetList.SelectedIndices[0]; if (targetList.Items[index].Text == star) { return; } else { target = targetList.Items[index].Text; if (Video.isVideoPreviewable(target)) { if (targetPictureBox.Image != null) { targetPictureBox.Image.Dispose(); targetPictureBox.Image = null; } targetMd = null; GC.Collect(); GC.WaitForPendingFinalizers(); targetMd = new MediaDetClass(); } } if (sourceList.Items[index].Text == star) { source = resolvedList.Items[index].Text; if (Video.isVideoPreviewable(source)) { if (sourcePictureBox.Image != null) { sourcePictureBox.Image.Dispose(); sourcePictureBox.Image = null; } sourceMd = null; GC.Collect(); GC.WaitForPendingFinalizers(); sourceMd = new MediaDetClass(); } } else { source = sourceList.Items[index].Text; if (Video.isVideoPreviewable(source)) { if (sourcePictureBox.Image != null) { sourcePictureBox.Image.Dispose(); sourcePictureBox.Image = null; } sourceMd = null; GC.Collect(); GC.WaitForPendingFinalizers(); sourceMd = new MediaDetClass(); } } ConflictPreviewWindow conflict = new ConflictPreviewWindow(source, target, this); this.Hide(); conflict.ShowDialog(); }
/// <summary> /// Private action to show the inView picture box based on source list index changed /// </summary> private void sourceList_SelectedIndexChanged(object sender, EventArgs e) { if (sourceList.SelectedItems.Count != 1) return; if (sourcePictureBox.Image != null) { sourcePictureBox.Image.Dispose(); sourcePictureBox.Image = null; sourceFileNameLabel.Text = ""; targetFileNameLabel.Text = sourceFileNameLabel.Text; } if (targetPictureBox.Image != null) { targetPictureBox.Image.Dispose(); targetPictureBox.Image = null; } targetMd = null; sourceMd = null; GC.Collect(); GC.WaitForPendingFinalizers(); targetMd = new MediaDetClass(); sourceMd = new MediaDetClass(); if (sourceList.SelectedItems.Count == 1 && !sourceList.SelectedItems[0].Text.Equals(star) && Photo.isPhoto(sourceList.SelectedItems[0].Text)) { int index = sourceList.SelectedIndices[0]; foreach (ListViewItem items in targetList.SelectedItems) { items.Selected = false; } targetList.Refresh(); foreach (ListViewItem items in resolvedList.SelectedItems) { items.Selected = false; } resolvedList.Refresh(); if (!targetList.Items[index].Text.Equals(star)) { try { targetPictureBox.Image = Image.FromFile(targetList.Items[index].Text); } catch (Exception pe) { targetPictureBox.Image = global::DoubleSnap.Properties.Resources.no_preview; } } else { try { targetPictureBox.Image = Image.FromFile(resolvedList.Items[index].Text); } catch (Exception pe) { targetPictureBox.Image = global::DoubleSnap.Properties.Resources.no_preview; } } try { sourcePictureBox.Image = Image.FromFile(sourceList.SelectedItems[0].Text); } catch (Exception pe) { sourcePictureBox.Image = global::DoubleSnap.Properties.Resources.no_preview; } string str = sourceList.SelectedItems[0].Text; int a = str.LastIndexOf(Comparator.PATH_DELIMITER); int b = str.Length; sourceFileNameLabel.Text = str.Substring(a + 1, b - a - 1); targetFileNameLabel.Text = sourceFileNameLabel.Text; } else if (sourceList.SelectedItems.Count == 1 && !sourceList.SelectedItems[0].Text.Equals(star) && Video.isVideoPreviewable(sourceList.SelectedItems[0].Text)) { int index = sourceList.SelectedIndices[0]; foreach (ListViewItem items in targetList.SelectedItems) { items.Selected = false; } targetList.Refresh(); foreach (ListViewItem items in resolvedList.SelectedItems) { items.Selected = false; } resolvedList.Refresh(); if (!targetList.Items[index].Text.Equals(star)) { try { targetPictureBox_MouseLeave(sender, e); targetPreviewer.deleteTmpBmpFiles(MainWindow.storagePath2); targetMd.Filename = targetList.Items[index].Text; targetMd.CurrentStream = 0; targetVideoLen = (int)targetMd.StreamLength; targetPictureBox.Image = global::DoubleSnap.Properties.Resources.hover_mouse; } catch (Exception pe) { targetPictureBox.Image = global::DoubleSnap.Properties.Resources.no_preview; } } else { try { targetPictureBox_MouseLeave(sender, e); targetPreviewer.deleteTmpBmpFiles(MainWindow.storagePath2); targetMd.Filename = resolvedList.Items[index].Text; targetMd.CurrentStream = 0; targetVideoLen = (int)targetMd.StreamLength; targetPictureBox.Image = global::DoubleSnap.Properties.Resources.hover_mouse; } catch (Exception pe) { targetPictureBox.Image = global::DoubleSnap.Properties.Resources.no_preview; } } try { sourcePictureBox_MouseLeave(sender, e); sourcePreviewer.deleteTmpBmpFiles(MainWindow.storagePath); sourceMd.Filename = sourceList.SelectedItems[0].Text; sourceMd.CurrentStream = 0; sourceVideoLen = (int)sourceMd.StreamLength; sourcePictureBox.Image = global::DoubleSnap.Properties.Resources.hover_mouse; } catch (Exception pe) { sourcePictureBox.Image = global::DoubleSnap.Properties.Resources.no_preview; } string str = sourceList.SelectedItems[0].Text; int a = str.LastIndexOf(Comparator.PATH_DELIMITER); int b = str.Length; sourceFileNameLabel.Text = str.Substring(a + 1, b - a - 1); targetFileNameLabel.Text = sourceFileNameLabel.Text; } else { sourcePictureBox.Image = global::DoubleSnap.Properties.Resources.no_preview; targetPictureBox.Image = global::DoubleSnap.Properties.Resources.no_preview; string str = sourceList.SelectedItems[0].Text; int a = str.LastIndexOf(Comparator.PATH_DELIMITER); int b = str.Length; sourceFileNameLabel.Text = str.Substring(a + 1, b - a - 1); targetFileNameLabel.Text = sourceFileNameLabel.Text; } }
/// <summary> /// Creates a bitmap file using MediaDetClass' method WriteBitMapBits /// </summary> /// <param name="md">MediaDetClass object for each video file found previewable </param> /// <param name="storagePath">folder name where bitmap files temporarily stored</param> /// <returns></returns> public string newBitmapPath(MediaDetClass md, string storagePath) { tmpBmpCount++; string fBitmapName = storagePath + tmpBmpName + tmpBmpCount.ToString() + ".bmp"; //fullpath of bitmap file that is to be generated md.WriteBitmapBits(frameNo, 650, 450, fBitmapName); //create the bitmap file return fBitmapName; // returns the newly created bitmap filename to the pictureBox }
/// <summary> /// Private method to make proper form closing by release all the resources /// </summary> private void PreviewWindow_FormClosed(object sender, FormClosedEventArgs e) { if (this.pictureBox.Image != null) { this.pictureBox.Image.Dispose(); this.pictureBox.Image = null; } md = null; GC.Collect(); GC.WaitForPendingFinalizers(); this.Hide(); preview.Show(); }
public double getFrameRate(string FileName) { double fr; MediaDetClass mD = new MediaDetClass(); mD.Filename=FileName; mD.CurrentStream=0; fr = mD.FrameRate; mD=null; return fr; }
/// <summary> /// Private method to make proper form closing by releasing all resources /// </summary> private void SmartGroupWindow_FormClosed(object sender, FormClosedEventArgs e) { if (pictureBox.Image != null) { pictureBox.Image.Dispose(); pictureBox.Image = null; } previewer.deleteTmpBmpFiles(MainWindow.storagePath); md = null; GC.Collect(); GC.WaitForPendingFinalizers(); Program.getMainWindow().Show(); }
/// <summary> /// Private method to show picture/video for target selection changed /// </summary> private void listView2_SelectedIndexChanged(object sender, EventArgs e) { if (pictureBox.Image != null) { pictureBox.Image.Dispose(); pictureBox.Image = null; } if (listView2.SelectedItems.Count != 1) return; md = null; GC.Collect(); GC.WaitForPendingFinalizers(); md = new MediaDetClass(); dummyToListBox.ClearSelected(); foreach (int i in listView2.SelectedIndices) { dummyToListBox.SetSelected(i, true); } dummyToListBox.Refresh(); if (listView2.SelectedItems.Count == 1 && Photo.isPhoto(dummyToListBox.SelectedItem.ToString())) { try { pictureBox.Image = Image.FromFile(dummyToListBox.SelectedItem.ToString()); } catch (Exception pe) { } } else if ((listView2.SelectedItems.Count == 1) && Video.isVideoPreviewable(dummyToListBox.SelectedItem.ToString())) { try { pictureBox_MouseLeave(sender, e); previewer.deleteTmpBmpFiles(MainWindow.storagePath); md.Filename = dummyToListBox.SelectedItem.ToString(); md.CurrentStream = 0; videoLen = (int)md.StreamLength; pictureBox.Image = global::DoubleSnap.Properties.Resources.hover_mouse; } catch (Exception pe) { pictureBox.Image = global::DoubleSnap.Properties.Resources.no_preview; } } if (pictureBox.Image == null && listView2.SelectedItems.Count == 1) pictureBox.Image = global::DoubleSnap.Properties.Resources.no_preview; }
/// <summary> /// Private method to show picture/video for photo preview target selection double-clicking /// </summary> private void listView2_MouseDoubleClick(object sender, MouseEventArgs e) { if (dummyToListBox.SelectedItems.Count == 1 && (Photo.isPhoto(dummyToListBox.SelectedItems[0].ToString()) || Video.isVideo(dummyToListBox.SelectedItems[0].ToString()))) { if (Video.isVideoPreviewable(dummyToListBox.SelectedItems[0].ToString())) { if (pictureBox.Image != null) { pictureBox.Image.Dispose(); pictureBox.Image = null; } md = null; GC.Collect(); GC.WaitForPendingFinalizers(); md = new MediaDetClass(); } PhotoPreviewWindow preview = new PhotoPreviewWindow(dummyToListBox.SelectedItems[0].ToString(), this); this.Hide(); preview.ShowDialog(); } }
/// <summary> /// Private method to react to cancel button click /// Release the resources /// </summary> private void cancelButton_Click(object sender, EventArgs e) { if (pictureBox.Image != null) { pictureBox.Image.Dispose(); pictureBox.Image = null; } previewer.deleteTmpBmpFiles(MainWindow.storagePath); md = null; GC.Collect(); GC.WaitForPendingFinalizers(); this.Close(); }
private static bool openVideoStream(string videoFile, out MediaDetClass mediaDetClass, out _AMMediaType aMMediaType) { MediaDetClass mediaDet = new MediaDetClass(); mediaDet.Filename = videoFile; int streamsNumber = mediaDet.OutputStreams; for (int i = 0; i < streamsNumber; i++) { mediaDet.CurrentStream = i; _AMMediaType mediaType = mediaDet.StreamMediaType; if (mediaType.majortype == JockerSoft.Media.MayorTypes.MEDIATYPE_Video) { mediaDetClass = mediaDet; aMMediaType = mediaType; return true; } } mediaDetClass = null; aMMediaType = new _AMMediaType(); return false; }
/// <summary> /// Private method to show the next the video frame /// </summary> /// <param name="box">picture box to show the video frame</param> /// <param name="mdex">mdex</param> /// <param name="previewer">previewer</param> /// <param name="len">length</param> /// <param name="str">string</param> private void showNextFrame(PictureBox box, MediaDetClass mde, VideoPreview previewer, int len, string str) { previewer.setNextFrame(len); if (box.Image != null) box.Image.Dispose(); // Console.WriteLine(box.ToString()); previewer.deleteTmpBmpFiles(str); // Console.WriteLine("hhkhkh"); try { box.Image = new Bitmap(previewer.newBitmapPath(mde, str)); } catch (Exception pe) { box.Image = global::DoubleSnap.Properties.Resources.no_preview; } }
/// <summary> /// Public Constructor: /// Initialize Component inside Conflict Preview Window /// Initialize video preview components /// Initialize various variables in Conflict Preview Window /// Load the picture/video accordingly /// </summary> /// <param name="source">source file full path</param> /// <param name="target">target file full path</param> /// <param name="confWin">Form from which this from is accessed</param> public ConflictPreviewWindow(string source, string target, Form confWin) { InitializeComponent(); sourceMd = new MediaDetClass(); targetMd = new MediaDetClass(); sourcePreviewer = new VideoPreview("tmp"); targetPreviewer = new VideoPreview("tmp"); this.WindowState = FormWindowState.Maximized; this.sourceTitle.Text = "Source: " + Path.GetFileNameWithoutExtension(source); this.targetTitle.Text = "Target: " + Path.GetFileNameWithoutExtension(target); this.sourcePathName=source; this.targetPathName=target; this.Text = "Conflicted: " + Path.GetFileNameWithoutExtension(source); conflict = confWin; if (Photo.isPhoto(source) && Photo.isPhoto(target)) { try { this.sourcePicture.Image = Image.FromFile(source); } catch (Exception pe) { this.sourcePicture.Image = global::DoubleSnap.Properties.Resources.no_preview; } try { this.targetPicture.Image = Image.FromFile(target); } catch (Exception pe) { this.targetPicture.Image = global::DoubleSnap.Properties.Resources.no_preview; } } else if (Video.isVideoPreviewable(source) && Video.isVideoPreviewable(target)) { try { sourcePreviewer.deleteTmpBmpFiles(MainWindow.storagePath); sourceMd.Filename = sourcePathName; sourceMd.CurrentStream = 0; sourceVideoLen = (int)sourceMd.StreamLength; sourcePicture.Image = global::DoubleSnap.Properties.Resources.hover_mouse; } catch (Exception pe) { sourcePicture.Image = global::DoubleSnap.Properties.Resources.no_preview; } try { targetPreviewer.deleteTmpBmpFiles(MainWindow.storagePath2); targetMd.Filename = targetPathName; targetMd.CurrentStream = 0; targetVideoLen = (int)targetMd.StreamLength; targetPicture.Image = global::DoubleSnap.Properties.Resources.hover_mouse; } catch (Exception pe) { targetPicture.Image = global::DoubleSnap.Properties.Resources.no_preview; } } else { sourcePicture.Image = global::DoubleSnap.Properties.Resources.no_preview; targetPicture.Image = global::DoubleSnap.Properties.Resources.no_preview; } }
/// <summary> /// Private method to show pictures/videos in big preview window /// </summary> /// /// <param name="lisview">The item to show is from lisview</param> /// <param name="sender">object sender</param> /// <param name="e">EventArgs e</param> private void bigPreview(ListView list, object sender, MouseEventArgs e) { if (list.SelectedItems.Count == 1 && (Photo.isPhoto(list.SelectedItems[0].Text) || Video.isVideo(list.SelectedItems[0].Text))) { if (Video.isVideoPreviewable(list.SelectedItems[0].Text)) { if (pictureBox.Image != null) { pictureBox.Image.Dispose(); pictureBox.Image = null; } md = null; GC.Collect(); GC.WaitForPendingFinalizers(); md = new MediaDetClass(); } PhotoPreviewWindow preview = new PhotoPreviewWindow(list.SelectedItems[0].Text, this); this.Hide(); preview.ShowDialog(); } }
/// <summary> /// tries to open a video file. If successful it makes available MediaDetClass and _AMMediaType instances of the current file /// </summary> /// <param name="videoFile">Path to the video file</param> /// <param name="mediaDetClass"></param> /// <param name="aMMediaType"></param> /// <returns>true for success, false for failure (no video stream, file not supported, ...)</returns> private static bool openVideoStream(string videoFile, out IMediaDet mediaDet, out _AMMediaType aMMediaType) { mediaDet = new MediaDetClass(); //loads file mediaDet.Filename = videoFile; //gets # of streams int streamsNumber = mediaDet.OutputStreams; //finds a video stream for (int i = 0; i < streamsNumber; i++) { mediaDet.CurrentStream = i; _AMMediaType mediaType = mediaDet.StreamMediaType; if (mediaType.majortype == JockerSoft.Media.MayorTypes.MEDIATYPE_Video) { //video stream found aMMediaType = mediaType; return true; } } //no video stream found Marshal.ReleaseComObject(mediaDet); mediaDet = null; aMMediaType = new _AMMediaType(); return false; }
/// <summary> /// Private method to show pictures/videos in picture Box /// </summary> /// /// <param name="lisview">The item to show is from lisview</param> /// <param name="sender">object sender</param> /// <param name="e">EventArgs e</param> private void showPictureOrVideo(ListView listView, object sender, EventArgs e) { if (pictureBox.Image != null) { pictureBox.Image.Dispose(); pictureBox.Image = null; } md = null; GC.Collect(); GC.WaitForPendingFinalizers(); md = new MediaDetClass(); if (listView.SelectedItems.Count == 1 && Photo.isPhoto(listView.SelectedItems[0].Text)) { int index = listView.SelectedIndices[0]; if (listView != sourceToTargetList) { foreach (ListViewItem items in sourceToTargetList.SelectedItems) items.Selected = false; } if (listView != targetToSourceList) { foreach (ListViewItem items in targetToSourceList.SelectedItems) items.Selected = false; } if (listView != sourceDeletedList) { foreach (ListViewItem items in sourceDeletedList.SelectedItems) items.Selected = false; } if (listView != targetDeletedList) { foreach (ListViewItem items in targetDeletedList.SelectedItems) items.Selected = false; } try { pictureBox.Image = Image.FromFile(listView.SelectedItems[0].Text); } catch (Exception pe) { pictureBox.Image = global::DoubleSnap.Properties.Resources.no_preview; } fileNameLabel.Text = listView.SelectedItems[0].Text; } else if ((listView.SelectedItems.Count == 1) && Video.isVideoPreviewable(listView.SelectedItems[0].Text)) { int index = listView.SelectedIndices[0]; if (listView != sourceToTargetList) { foreach (ListViewItem items in sourceToTargetList.SelectedItems) items.Selected = false; } if (listView != targetToSourceList) { foreach (ListViewItem items in targetToSourceList.SelectedItems) items.Selected = false; } if (listView != sourceDeletedList) { foreach (ListViewItem items in sourceDeletedList.SelectedItems) items.Selected = false; } if (listView != targetDeletedList) { foreach (ListViewItem items in targetDeletedList.SelectedItems) items.Selected = false; } try { pictureBox_MouseLeave(sender,e); previewer.deleteTmpBmpFiles(MainWindow.storagePath); md.Filename = listView.SelectedItems[0].Text; md.CurrentStream = 0; videoLen = (int)md.StreamLength; pictureBox.Image = global::DoubleSnap.Properties.Resources.hover_mouse; } catch (Exception pe) { pictureBox.Image = global::DoubleSnap.Properties.Resources.no_preview; } fileNameLabel.Text = listView.SelectedItems[0].Text; } else pictureBox.Image = global::DoubleSnap.Properties.Resources.no_preview; fileNameLabel.Text = listView.SelectedItems[0].Text; }