private void processMovie() { if (videoReader.IsOpen) { Bitmap videoFrame; processor.Background = videoReader.ReadVideoFrame(); int i = 0; while ((videoFrame = videoReader.ReadVideoFrame()) != null) { Bitmap preprocess = processor.preprocessImage(videoFrame); this.Dispatcher.Invoke(new Action(() => frameCountLabel.Content = Properties.Resources.FPS_LABEL_BEGIN + (int)(++i / videoReader.FrameRate) + "s")); this.Dispatcher.Invoke(new Action(() => preprocessedImage.Source = VideoProcessor.convertBitmap(preprocess))); Bitmap diff = processor.findDifference(preprocess); preprocess.Dispose(); this.Dispatcher.Invoke(new Action(() => differenceImage.Source = VideoProcessor.convertBitmap(diff))); Bitmap final = processor.showMotion(videoFrame, diff); diff.Dispose(); this.Dispatcher.Invoke(new Action(() => finalImage.Source = VideoProcessor.convertBitmap(final))); final.Dispose(); videoFrame.Dispose(); } i = 0; videoReader.Dispose(); videoReader.Close(); restart(); } }
public void ReadFromVideo(string path) { pathToFile = new Uri(AnaglyphParameters.VideoPath.LocalPath); AnaglyphParameters.PathToRead = pathToFile.LocalPath; AnaglyphParameters.PathToWrite = path.Split('.')[0] + "1.mp4"; reader.Open(pathToFile.LocalPath); SetWriter(reader, writer); for (int i = 0; i < reader.FrameCount; i++) { OnOnFrameDone(i, (int)reader.FrameCount); try { using (Bitmap videoFrame = reader.ReadVideoFrame(i)) { using (Bitmap videoFrameChanged = new Fitler().Calc(videoFrame)) { writer.WriteVideoFrame(videoFrameChanged, (uint)i); } } } catch (Exception e) { Console.WriteLine(e.StackTrace); } } reader.Close(); writer.Close(); VideoToFrames.AddAudioToVideo(path); OnOnProcessDone(); }
public Task <Bitmap> GetFrame(long frame) { if (!_reader.IsOpen) { _reader.Open(Path); CurrentFrame = 0; } if (frame < CurrentFrame) { _reader.Close(); _reader.Open(Path); CurrentFrame = 0; } return(Task.Run(() => { while (CurrentFrame < frame) { _reader.ReadVideoFrame().Dispose(); CurrentFrame++; } CurrentFrame = frame; return _reader.ReadVideoFrame(); })); }
//public Clinet_multi client; public void flush() { if (current_type == "wmv") { video_wmv.Close(); } else if (current_type == "avi") { //video_avi.Close(); } bitmap_stream = new List <BitmapStream>(); finish = 0; current_type = ""; streamCount = 0; }
/// <summary> /// Checks the video for matches. /// </summary> /// <param name="videoPath">The video path.</param> /// <param name="desiredTag">The desired tag to look for in the video.</param> /// <param name="startingPoint">The starting point of the search (in seconds).</param> /// <returns> Image data object </returns> public static async Task <FrameDto> CheckVideoForMatches (string videoPath, string desiredTag, double startingPoint = 0) { VideoFileReader reader = new VideoFileReader(); reader.Open(videoPath); double rate = reader.FrameRate.ToDouble(); for (int i = 0; i < reader.FrameCount; i++) { try { byte[] frame = ImageManager.ToBytes(reader.ReadVideoFrame()); double current_seconds = i * 1.0 / rate; if (i % rate != 0 || startingPoint > current_seconds) // for efficiency: only do analysis every 1 second (or every N=rate frames) { continue; } JToken analysis = await ComputerVisionManager.AnalyzeImage(frame); if (ImageManager.CheckMatch(desiredTag, analysis)) { reader.Close(); return(new FrameDto() { Analysis = analysis, OccurenceTime = TimeSpan.FromSeconds(current_seconds), DesiredTag = desiredTag }); } } catch (Exception) { continue; } } reader.Close(); return(null); }
public void Dispose() { wallpaperPath = null; if (wallpaper != null) { wallpaper.Dispose(); } if (gif != null) { foreach (Bitmap b in gif) { if (b != null) { b.Dispose(); } } } if (loadStream != null) { loadStream.Dispose(); } frameRateCounter.Stop(); if (mp4 != null) { mp4.Close(); mp4.Dispose(); mp4frame = 0; } }
private static void VideoProcessing(string videoPath, string outputFolder) { VideoFileReader videoFileReader = new VideoFileReader(); videoFileReader.Open(videoPath); Console.WriteLine("Video loaded (" + videoFileReader.FrameCount + " frames)"); Size scaledSize = new Size((int)Math.Round(videoFileReader.Width * scalingFactor), (int)Math.Round(videoFileReader.Height * scalingFactor)); Console.WriteLine("Analyzing frames"); for (int i = 0; i < videoFileReader.FrameCount; i++) { DrawTextProgressBar(i + 1, (int)videoFileReader.FrameCount); using (Bitmap frame = videoFileReader.ReadVideoFrame()) { using (Bitmap scaled = new Bitmap(frame, scaledSize)) { float brightness = scaled.BrightnessOfBrightestPixels(0.02); if (brightness > 0.09f) { frame.Save(outputFolder + @"\" + i.ToString().PadLeft(5, '0') + ".bmp"); } } } } videoFileReader.Close(); Console.WriteLine("Done"); }
/* --------------------------------------------------------------------- * readVideo * --------------------------------------------------------------------- * Reads the video, saving all its frames and creating the intensity * matrix for each one. * Preconditions: * -video of specified name exists */ private void readVideo() { String VideoPath = Directory.GetParent(Directory.GetCurrentDirectory()).Parent.FullName; VideoPath = VideoPath + "\\Resources\\20020924_juve_dk_02a.avi"; bool intensityExists = readIntensityFile(); using (var vFReader = new VideoFileReader()) { vFReader.Open(VideoPath); // get video info to remake video when done this.vWidth = vFReader.Width; this.vHeight = vFReader.Height; this.vFramerate = vFReader.FrameRate; // store each image and intensities into the arrays for (int i = 1000; i < 5000; i++) { System.Drawing.Bitmap bmpBaseOriginal = vFReader.ReadVideoFrame(); FrameMatrix[i] = bmpBaseOriginal; } vFReader.Close(); if (!intensityExists) { getIntensity(); writeIntensityFile(); } } }
private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { OpenFileDialog dialog = new OpenFileDialog(); dialog.Multiselect = false; // dialog.Filter = "Media Files|*.mpg;*.avi;*.wma;*.mov;*.wav;*.mp2;*.mp3|All Files|*.*"; if (dialog.ShowDialog() == DialogResult.OK) { System.IO.File.Copy(dialog.FileName, dialog.FileName + "temp"); textBox2.Text = dialog.FileName; } VideoFileReader reader = new VideoFileReader(); // open video file reader.Open(textBox2.Text); // check some of its attributes richTextBox1.Text += "width: " + reader.Width + "\n"; richTextBox1.Text += "height: " + reader.Height + "\n"; richTextBox1.Text += "fps: " + reader.FrameRate + "\n"; richTextBox1.Text += "codec: " + reader.CodecName + "\n"; //for (int i = 0; i < reader.FrameCount; i++) //{ // Bitmap videoFrame = reader.ReadVideoFrame(); // // process the frame somehow // // ... // OldBitmaps.Add(videoFrame); // // dispose the frame when it is no longer required // // videoFrame.Dispose(); //} reader.Close(); }
//Méthode permettant de de créer un apercu d'une image à partir d'une vidéo et la situe à l'endroit de la vidéo public static string createPreviewFromVideo(string pathVideo, string cameraName) { //Path de l'image qui sera créé par la suite string pathImage = ""; if (!String.IsNullOrEmpty(pathVideo)) { VideoFileReader reader = new VideoFileReader(); //Ouvre la video reader.Open(pathVideo); //Lit la première image Bitmap videoFrame = reader.ReadVideoFrame(); if (String.IsNullOrEmpty(cameraName)) { pathImage = Path.GetDirectoryName(pathVideo) + @"\" + Path.GetFileNameWithoutExtension(pathVideo) + "image.png"; } else { pathImage = Path.GetDirectoryName(pathVideo) + @"\" + cameraName + "image.png"; } //Ecrase l'image si le nom est déjà pris if (File.Exists(pathImage)) { File.Delete(pathImage); } videoFrame.Save(pathImage); //On libère les ressources videoFrame.Dispose(); reader.Close(); } return(pathImage); }
private void convert() { try { VideoFileReader reader = new VideoFileReader(); reader.Open(m_mp4File); Bitmap videoFrame = null; int frame = 0; int scratchfile = 0; while ((videoFrame = reader.ReadVideoFrame()) != null) { if (frame % reader.FrameRate == 0) { Console.WriteLine("Frame: " + frame); byte[] buffer = imageToByteArray(videoFrame); m_dictionary.Add(scratchfile, getMd5Hash(buffer)); videoFrame.Save("C:/temp/" + scratchfile.ToString() + ".png", ImageFormat.Png); videoFrame.Dispose(); videoFrame = null; ++scratchfile; } ++frame; } reader.Close(); } catch (Exception ex) { Console.WriteLine(ex.Message); } }
/// <summary> /// 截取视频缩略图 /// </summary> /// <param name="videoPath">视频路径</param> /// <param name="thumbImagePath">缩略图文件路径</param> /// <param name="thubWidth">缩略图指定的边长(正方形)</param> /// <param name="thubQuality">缩略图质量</param> public static void VideoSnapshots(string videoPath, string thumbImagePath, int thubWidth, int thubQuality) { VideoFileReader reader = new VideoFileReader(); try { lock (lockData) { reader.Open(videoPath); } Bitmap bitMap = reader.ReadVideoFrame(); //创建目录 string dirPath = Path.GetDirectoryName(thumbImagePath); if (!Directory.Exists(dirPath)) { Directory.CreateDirectory(dirPath); } ImageHelper.CutForSquare(bitMap, thumbImagePath, thubWidth, thubQuality); } finally { reader.Dispose(); reader.Close(); } }
private static void Main() { var reader = new VideoFileReader(); reader.Open(@"your video here"); // video attributes Console.WriteLine("width: " + reader.Width); Console.WriteLine("height: " + reader.Height); Console.WriteLine("fps: " + reader.FrameRate); Console.WriteLine("codec: " + reader.CodecName); // read video frames while (true) { using (var videoFrame = reader.ReadVideoFrame()) { if (videoFrame == null) { break; } // process the frame here } } reader.Close(); }
}//void public void parcala() { VideoFileReader reader = new VideoFileReader(); IWMPMedia saniye = axWindowsMediaPlayer1.newMedia(ofdVideoYukle.FileName); videoFrameList.Clear(); reader.Open(ofdVideoYukle.FileName); this._TotalFrameCount = (int)saniye.duration * reader.FrameRate; this._VideoFPS = reader.FrameRate; progressBar1.Maximum = this._TotalFrameCount; FrameSayisi = _TotalFrameCount; for (int i = 0; i < this._TotalFrameCount; i++) { Bitmap videoFrame = reader.ReadVideoFrame(); string yol = "C://Users//BegovicTeam//Desktop//video sıkıştırma//frameparcalanmis//" + "image" + i + ".mpeg"; convertMpeg(videoFrame, yol); progressBar1.Value += 1; } reader.Close(); reader.Dispose(); birlestir(); frameParcala.Abort(); }
public void ClearResource() { writer.Close(); videoFrame.Dispose(); reader.Close(); reader2.Close(); }
//Call following function only once... public void ReadVideoFile() { VideoFileReader reader = new VideoFileReader(); List <Bitmap> frameCapture = new List <Bitmap>(); reader.Open(Environment.CurrentDirectory + @"\20020924_juve_dk_02a_1.avi"); // check some of its attributes Console.WriteLine("width: " + reader.Width); Console.WriteLine("height: " + reader.Height); Console.WriteLine("fps: " + reader.FrameRate); Console.WriteLine("codec: " + reader.CodecName); // read 100 video frames out of it for (int i = 0; i < 5000; i++) { Bitmap videoFrame = reader.ReadVideoFrame(); if (i < 1000) { continue; } videoFrame.Save(Environment.CurrentDirectory + @"/images/VideoFrameImageDetails" + i + ".bmp"); videoFrame.Dispose(); } reader.Close(); }
static void Main(string[] args) { Stopwatch stopwatch = new Stopwatch(); stopwatch.Start(); VideoFileReader reader = new VideoFileReader(); reader.Open(fileName); for (int i = 0; i < reader.FrameCount; i++) { read.Add(reader.ReadVideoFrame()); write.Add(NegativGeneralas(read[i])); } VideoFileWriter writer = new VideoFileWriter(); writer.Open("eredmeny_" + fileName, reader.Width, reader.Height, reader.FrameRate, VideoCodec.MPEG4, reader.BitRate); for (int i = 0; i < write.Count; i++) { writer.WriteVideoFrame(write[i]); } reader.Close(); writer.Close(); stopwatch.Stop(); Console.WriteLine(stopwatch.Elapsed); Console.ReadLine(); }
public static Vector3[,] Medium(string path, int steps = 100) { VideoFileReader reader = new VideoFileReader(); reader.Open(path); Vector3[,] data = new Vector3[reader.Width, reader.Height]; var temp = new Image <Rgb, float>(reader.Width, reader.Height); for (int i = 0; i < steps; i++) { using (Bitmap img = reader.ReadVideoFrame(i * (int)reader.FrameCount / steps)) { var arr = new Image <Rgb, float>(img); temp.Accumulate(arr); //temp.WriteRGB(img); //data.ForEach(temp, (m, v) => m.Add(v)); } } for (int x = 0; x < reader.Width; x++) { for (int y = 0; y < reader.Height; y++) { Rgb rgb = temp[y, x]; data[x, y] = new Vector3((float)rgb.Red / steps / 255, (float)rgb.Green / steps / 255, (float)rgb.Blue / steps / 255); } } reader.Close(); return(data); }
private void pictureBox10_Click(object sender, EventArgs e) { if (textBox1.Text != "") { i = 0; k = 0; val = Convert.ToInt32(textBox1.Text); timer2.Enabled = false; timer1.Interval = val; timer1.Enabled = true; reader.Close(); } else { MessageBox.Show("Nu ati introdus timpul de tranzitie!"); } }
public void release() { if (_reader != null) { _reader.Close(); _reader = null; } }
protected override void DoDispose() { if (reader != null) { reader.Close(); reader = null; } }
private async void btnEnter_Click(object sender, EventArgs e) { ResetAlertBox(); txtOutput.Text = "Detect faces: "; //string imageFilePath = "./a.jpg"; string imageFilePath = txtRef.Text; if (File.Exists(imageFilePath)) { // Execute the REST API call. try { string fileExtension = Path.GetExtension(imageFilePath); if (fileExtension == ".mp4") { btnEnter.Enabled = false; int i = 0; int frameNum = 0; VideoFileReader reader = new VideoFileReader(); reader.Open(imageFilePath); while (safe) { Bitmap videoFrame = reader.ReadVideoFrame(frameNum); if (File.Exists("./input" + i + ".jpg")) { File.Delete("./input" + i + ".jpg"); } videoFrame.Save("./input" + i + ".jpg", System.Drawing.Imaging.ImageFormat.Jpeg); await MakeAnalysisRequest("./input" + i + ".jpg"); i++; frameNum += (/*5 * */ (int)reader.FrameRate); if (frameNum > reader.FrameCount) { safe = false; } System.Threading.Thread.Sleep(1000); } reader.Close(); btnEnter.Enabled = true; } else if (fileExtension == ".jpg") { await MakeAnalysisRequest(imageFilePath); } } catch (Exception ex) { txtOutput.AppendText("\n" + ex.Message); } } else { txtOutput.AppendText("\nInvalid file path.\n"); } }
private void timer1_Tick(object sender, EventArgs e) { pictureBox1.Image = func(reader.ReadVideoFrame(pos)); GC.Collect(); pos++; if (pos >= reader.FrameCount) { reader.Close(); } }
//TODO readType public static Bitmap GetVideoFrame(string filepath) { VideoFileReader reader = new VideoFileReader(); reader.Open(filepath); Bitmap videoFrame = reader.ReadVideoFrame(); reader.Close(); return(videoFrame); }
public static void Decoder(Stegonography s) { var reader = new VideoFileReader(); reader.Open("test.avi"); Console.WriteLine("\nVideo title: " + "test.avi"); Console.WriteLine("width: " + reader.Width); Console.WriteLine("height: " + reader.Height); Console.WriteLine("fps: " + reader.FrameRate); Console.WriteLine("codec: " + reader.CodecName); Console.WriteLine("frames: " + reader.FrameCount); string decoded = ""; int frame = 0; int rgb = 0; for (int i = 0; i < reader.FrameCount; i++) { Bitmap videoFrame = reader.ReadVideoFrame(); if (s.FramesToStoreCordinates[frame] == i) { for (int cord = 0; cord < s.DataCordinates.Count(); cord++) { int x = (int)s.DataCordinates.ElementAt(cord).X; int y = (int)s.DataCordinates.ElementAt(cord).Y; var color = videoFrame.GetPixel(x, y); var data = ""; if (rgb == 0) { data = Convert.ToChar(color.B).ToString(); } else if (rgb == 1) { data = Convert.ToChar(color.G).ToString(); } else { data = Convert.ToChar(color.R).ToString(); } rgb = (rgb + 1) % 3; decoded += data; } frame++; } videoFrame.Dispose(); } Console.WriteLine("\n" + decoded); reader.Close(); Console.ReadKey(); }
private void pictureBox10_Click(object sender, EventArgs e) { if (textBox2.Text != "" && textBox3.Text != "" && textBox4.Text != "" && textBox5.Text != "") { Array.Clear(vbm, 0, vbm.Length); // create instance of video reader reader = new VideoFileReader(); // open video file OpenFileDialog open = new OpenFileDialog(); if (open.ShowDialog() == DialogResult.OK) { path = open.FileName; reader.Open(path); sir1 = textBox5.Text; vecu1 = sir1.Split(':'); dur = dur + Convert.ToInt32(vecu1[0]) * 60; dur = dur + Convert.ToInt32(vecu1[1]); sec = reader.FrameCount / dur; sir2 = textBox2.Text; vecu1 = sir2.Split(':'); frm = frm + Convert.ToInt32(vecu1[0]) * 60; frm = frm + Convert.ToInt32(vecu1[1]); sir3 = textBox4.Text; vecu1 = sir3.Split(':'); frm2 = frm2 + Convert.ToInt32(vecu1[0]) * 60; frm2 = frm2 + Convert.ToInt32(vecu1[1]); st = frm * sec; stop = frm2 * sec; // read 100 video frames out of it Image cont; for (int i = 0; i < reader.FrameCount; i++) { if (i > stop) { break; } if (i >= st && i <= stop) { t3++; vbm[t3] = reader.ReadVideoFrame(); } if (i < st) { cont = reader.ReadVideoFrame(); cont.Dispose(); } } reader.Close(); } } else { MessageBox.Show("Inainte de a incarca video-ul e nevoie sa completati specificatiile!"); } }
private static void OnMediaClosed(object sender, RoutedEventArgs e) { CommandManager.InvalidateRequerySuggested(); InvalidateDif(); videoReader.Close(); videoReader.Dispose(); videoReader = null; samples = new short[0]; sampleRate = 1; UpdateWindowTitle(); }
public void VideoFileReaderTest() { var fileName = @"C:\Datos Lab\videos\480x360Videos\subject01.avi"; var videoFile = new VideoFileReader(); videoFile.Open(fileName); var bitmap = videoFile.ReadVideoFrame(); var height = bitmap.Height; var width = bitmap.Width; videoFile.Close(); Assert.IsTrue(height > 0 && width > 0); }
private void _LoadingVideoBackgroundWorker_DoWork(object sender, DoWorkEventArgs e) { Unload(); if (!_Settings.HasPathRecordedVideo()) { _Logger.InformUser(Strings.PasDePathRecordVideo); return; } bool error = false; try { _VideoFileReader.Open(_Settings.PathNameVideoFile); } catch { error = true; } if (error || _VideoFileReader.IsOpen == false) { _Logger.InformUser(Strings.ImpossibleOpenRecordedVideo); return; } _CurrentFrameRate = _VideoFileReader.FrameRate; // long to int passe sans verification car avec 1 heure de video max (30 ou 25 img/s) on atteint pas le max de Int. int numberFrames = (int)_VideoFileReader.FrameCount; _CompressedImageStreams = new MemoryStream[numberFrames]; for (int i = 0; i < numberFrames; i++) { MemoryStream stream = new MemoryStream(); Bitmap bitmap = _VideoFileReader.ReadVideoFrame(); bitmap.Save(stream, ImageFormat.Jpeg); bitmap.Dispose(); _CompressedImageStreams[i] = stream; } _VideoFileReader.Close(); }
private void MoveToNextFrame() { var bmp = _reader.ReadVideoFrame(); if (bmp == null) { _reader.Close(); _reader.Open(VideoPath); bmp = _reader.ReadVideoFrame(); } _currentBitMap = bmp; _msSpentInCurrentFrame = 0; }
protected override void CleanUpRender() { _fp?.Dispose(); _fp = null; if (_reader != null) { _reader.Close(); _reader.Dispose(); _reader = null; } _processVideo = true; }
public void test_read() { // create instance of video reader VideoFileReader reader = new VideoFileReader(); // open video file reader.Open("test.avi"); // check some of its attributes Console.WriteLine("width: " + reader.Width); Console.WriteLine("height: " + reader.Height); Console.WriteLine("fps: " + reader.FrameRate); Console.WriteLine("codec: " + reader.CodecName); // read 100 video frames out of it for (int i = 0; i < 100; i++) { Bitmap videoFrame = reader.ReadVideoFrame(); // process the frame somehow // ... // dispose the frame when it is no longer required videoFrame.Dispose(); } reader.Close(); }
// Function to process the file public int doProcess(ProgressStorage progressStorage) { currentFrame = 0; reader = new VideoFileReader(); try { reader.Open(file); } catch { return 1; } int frameCount = (int)reader.FrameCount; tracker = new Tracker(movementWindow); int nrofiterations = frameCount / 200; int i = 0; int nrofframes = 0; while (i < nrofiterations) { nrofframes = 200; loadinPart(nrofframes, area); if(i == 0) // store first frame as background frame { backgroundFrame = imageStack[0].Clone(new Rectangle(0, 0, imageStack[0].Width, imageStack[0].Height), imageStack[0].PixelFormat); } processFilePart(); progressStorage.incrementProgress(currentFrame); i++; } nrofframes = frameCount - currentFrame; loadinPart(nrofframes, area); if (nrofiterations == 0) // store first frame as background frame if nrofiterations is 0 { backgroundFrame = imageStack[0].Clone(new Rectangle(0, 0, imageStack[0].Width, imageStack[0].Height), imageStack[0].PixelFormat); } processFilePart(); progressStorage.incrementProgress(currentFrame); tracker.closeList(currentFrame); reader.Close(); // close the file return 0; }
private void button2_Click(object sender, EventArgs e) { FileStream dosyamiz; StreamReader okuma; string yol = "C:\\manual_Jogging1.txt"; dosyamiz = new FileStream(yol, FileMode.Open, FileAccess.Read); okuma = new StreamReader(dosyamiz); int n, a, b, c, d; int x1, x2, x3, x4; double xgec; System.Drawing.Graphics graphicsObj; graphicsObj = this.CreateGraphics(); Pen myPen = new Pen(System.Drawing.Color.Red, 1); VideoFileReader reader = new VideoFileReader(); IWMPMedia saniye = axWindowsMediaPlayer1.newMedia(ofVideoYukle.FileName); if (fbdFramePath.ShowDialog() != System.Windows.Forms.DialogResult.OK) { MessageBox.Show("Klasör seçilmedi"); } string str_FramePath = fbdFramePath.SelectedPath + @"\"; reader.Open(ofVideoYukle.FileName); this.TotalFrame = (int)saniye.duration * reader.FrameRate; this.Videofps = reader.FrameRate; for (int i = 0; i < 307; i++) { textBox1.Text = okuma.ReadLine(); textBox2.Text = textBox1.Text.Replace(" ", ""); n = Convert.ToInt32(textBox2.Text.Substring(0, 1)); a = Convert.ToInt32(textBox2.Text.Substring(1, 3)); b = Convert.ToInt32(textBox2.Text.Substring(4, 3)); c = Convert.ToInt32(textBox2.Text.Substring(7, 2)); d = Convert.ToInt32(textBox2.Text.Substring(9, 2)); if (i > 9) { if (i == 48 || i == 49 || i == 50 || i == 51 || i == 52 || i == 53 || i == 54 || i == 55) { n = Convert.ToInt32(textBox2.Text.Substring(0, 2)); a = Convert.ToInt32(textBox2.Text.Substring(2, 2)); b = Convert.ToInt32(textBox2.Text.Substring(4, 3)); c = Convert.ToInt32(textBox2.Text.Substring(7, 2)); d = Convert.ToInt32(textBox2.Text.Substring(9, 2)); } else { n = Convert.ToInt32(textBox2.Text.Substring(0, 2)); a = Convert.ToInt32(textBox2.Text.Substring(2, 3)); b = Convert.ToInt32(textBox2.Text.Substring(5, 3)); c = Convert.ToInt32(textBox2.Text.Substring(8, 2)); d = Convert.ToInt32(textBox2.Text.Substring(10, 2)); } } if (i > 99) { n = Convert.ToInt32(textBox2.Text.Substring(0, 3)); a = Convert.ToInt32(textBox2.Text.Substring(3, 3)); b = Convert.ToInt32(textBox2.Text.Substring(6, 3)); c = Convert.ToInt32(textBox2.Text.Substring(9, 2)); d = Convert.ToInt32(textBox2.Text.Substring(11, 2)); } x1 = a - c; x2 = b - ((3 * d) / 2); x3 = 2 * c; xgec = (Math.Sqrt(Math.Pow(c, 2) + Math.Pow(d, 2))) * 3; x4 = Convert.ToInt32(xgec); Rectangle myRectangle = new Rectangle(x1, x2, x3, x4); Bitmap videoFrame = reader.ReadVideoFrame(); using (Graphics grafik = Graphics.FromImage(videoFrame as Image)) { grafik.DrawEllipse(myPen, myRectangle); } videoFrame.Save(str_FramePath + "Image" + i + ".jpg"); videoFrame.Dispose(); } reader.Close(); reader.Dispose(); MessageBox.Show("Video Frame lere ayrildi"); button4.Enabled = true; }
private void keyFrame() { VideoFileReader reader = new VideoFileReader(); reader.Open(textBox1.Text); int Fcon = int.Parse(reader.FrameCount.ToString()); int Fcount = Fcon / 2; for (int i = 0; i < reader.FrameCount; i++) { Bitmap videoFrame = reader.ReadVideoFrame(); if (i == Fcount) { hisVec(videoFrame); break; } } reader.Close(); }
private void btn_encode_Click(object sender, EventArgs e) { if (oform != null && File.Exists(oform.FileName)) { //has a filestream been opened? hScrollBar1.Enabled = false; checkBox1.Enabled = false; btn_encode.Enabled = false; // create instance of video reader VideoFileReader reader = new VideoFileReader(); VideoFileWriter writer = new VideoFileWriter(); reader.Open(oform.FileName); if (checkBox1.Checked) { //Is the user requesting a AVI? writer.Open(apath + "output.wmv", 320, 200, reader.FrameRate, VideoCodec.WMV2); } // print some of its attributes logbox.Text += "Width: " + reader.Width + "px" + Environment.NewLine; logbox.Text += ("Height: " + reader.Height + "px" + Environment.NewLine); logbox.Text += ("Fps: " + reader.FrameRate + "fps"+ Environment.NewLine); logbox.Text += ("Codec: " + reader.CodecName + Environment.NewLine); logbox.Text += ("Frames: " + reader.FrameCount + Environment.NewLine); //start encoding classes TMVVideo tvid = new TMVVideo(); TMVEncoder tmv = new TMVEncoder(); //tmvframe.Threshold = hScrollBar1.Value; Bitmap videoFrame = new Bitmap(320,200); logbox.Text += "Conversion started @ " + DateTime.Now.ToString(); string logtxt = logbox.Text; logbox.Text += "Current Frame: 0"; TMVFont renderfont = new TMVFont(apath + "font.bin"); TMVFrame tframe; for (int i = 0; i < reader.FrameCount; i++) { videoFrame = resize_image(reader.ReadVideoFrame()); tframe = tmv.encode(videoFrame); tvid.addFrame(tframe); obox.Image = tframe.renderFrame(renderfont); pbar.Value = (int)((i * 100) / (reader.FrameCount-1)); logbox.Text = logtxt + Environment.NewLine + "Current Frame: " + i + "/" + (reader.FrameCount-1); if (checkBox1.Checked) { //Is the user requesting a AVI? writer.WriteVideoFrame((Bitmap)obox.Image); } if (closing) { return; } fbox.Image = videoFrame; Application.DoEvents(); } logbox.Text += Environment.NewLine + "All frames converted, attempting to interleave audio."; if (File.Exists(apath + "temp.wav")) { //remove any previous streams File.Delete(apath + "temp.wav"); } AviManager aviManager = new AviManager(oform.FileName, true); try { //try to read the stream AudioStream waveStream = aviManager.GetWaveStream(); logbox.Text += Environment.NewLine + "Audio stream found:"; logbox.Text += Environment.NewLine + "Sample Rate: " + waveStream.CountSamplesPerSecond.ToString(); logbox.Text += Environment.NewLine + "Bits:" + waveStream.CountBitsPerSample.ToString(); logbox.Text += Environment.NewLine + "Number of Channels: " + waveStream.CountChannels.ToString(); File.Delete(apath + "temp.wav"); waveStream.ExportStream(apath+"temp.wav"); waveStream.Close(); aviManager.Close(); byte[] audio_data = readWav(apath + "temp.wav"); if (reader.FrameRate > 99) { //sometimes frame rate is stored fixed point CRUDE tvid.setFPS((decimal)(reader.FrameRate / 10.0)); tvid.loadAudio(audio_data); tvid.save(); } else { tvid.setFPS(reader.FrameRate); tvid.loadAudio(audio_data); tvid.save(); } } catch { //error somewhere here, continue silent. logbox.Text += Environment.NewLine+"Error, source video does not have WAV audio, video will be silent."; if (reader.FrameRate > 99) { //sometimes frame rate is stored fixed point CRUDE tvid.setFPS((decimal)(reader.FrameRate / 10.0)); tvid.loadAudio(new Byte[reader.FrameCount]); tvid.save(); } else { tvid.setFPS(reader.FrameRate); tvid.loadAudio(new Byte[reader.FrameCount]); tvid.save(); } } logbox.Text += Environment.NewLine + "Conversion finished @ " + DateTime.Now.ToString(); writer.Close(); reader.Close(); hScrollBar1.Enabled = true; checkBox1.Enabled = true; btn_encode.Enabled = true; } else { logbox.Text += Environment.NewLine + "Error: Select a file (Using File -> Open) before attempting to encode."; } }
private void keyFrame() { VideoFileReader readerShort= new VideoFileReader(); readerShort.Open(name); // set many frame int Fcon = int.Parse(readerShort.FrameCount.ToString()); // set frame/2 int Fcount = Fcon / 2; for (int i = 0; i < readerShort.FrameCount; i++) { Bitmap videoFrame = readerShort.ReadVideoFrame(); if (i == Fcount) { hisVec(videoFrame); keyF = ("..\\..\\..\\Keyframe\\" + Url2 + "_" + i + ".jpeg"); videoFrame.Save(keyF, ImageFormat.Jpeg); break; } videoFrame.Dispose(); } // close short video readerShort.Close(); }
private void saveshot() { string str = Url; string[] sAry = str.Split('.'); Url2 = sAry[0]; VideoFileReader reader = new VideoFileReader(); reader.Open(textBox1.Text); int co = 0; int end = int.Parse(reader.FrameCount.ToString()); int countFrameCut = 0; VideoFileWriter writerShort = new VideoFileWriter(); name = "..\\..\\..\\VideoName\\" + Url2 + "_" + Convert.ToString(countFrameCut) + ".avi"; videoname = Url2 + "_" + countFrameCut + ".avi"; writerShort.Open(name, reader.Width, reader.Height, reader.FrameRate, VideoCodec.MPEG4, 1000000); for (int i = 0; i < end; i++) { Bitmap videoFrame = reader.ReadVideoFrame(); writerShort.WriteVideoFrame(videoFrame); videoFrame.Dispose(); if (i == Savei[countFrameCut]) { // cut short writerShort.Close(); keyFrame(); if (countCutFrame != countFrameCut) { name = "..\\..\\..\\VideoName\\" + Url2 + "_" + Convert.ToString(countFrameCut) + ".avi"; videoname = Url2 + "_" + countFrameCut + ".avi"; writerShort.Open(name, reader.Width, reader.Height, reader.FrameRate, VideoCodec.MPEG4, 1000000); } countFrameCut++; } } writerShort.Close(); reader.Close(); /* for (int i = 0; i < Savei.Length; i++) { if (Savei[i] == 0) { if (co == 0) { Savei[i] = end; co = 1; } else { break; } } VideoFileWriter writer = new VideoFileWriter(); try { name = "..\\..\\..\\VideoName\\" + Url2 + "_" + Convert.ToString(i) + ".avi"; videoname = Url2 + "_" + i + ".avi"; writer.Open(name, reader.Width, reader.Height, reader.FrameRate, VideoCodec.MPEG4, 1000000); for (int j = 0; j < end; j++) { if (Savei[i] == j) { writer.Close(); break; } Bitmap videoFrame = reader.ReadVideoFrame(); writer.WriteVideoFrame(videoFrame); videoFrame.Dispose(); } } catch (Exception exception) { writer.Close(); } if (i == 0) { end = end - Savei[i]; } else { end = end - Math.Abs(Savei[i] - Savei[i - 1]); } keyFrame(); //string constr = ConfigurationManager.ConnectionStrings["Db"].ConnectionString; //SqlConnection con = new SqlConnection(constr); //con.Open(); //SqlCommand cmd = new SqlCommand("INSERT into CollectionShot (No,VideoName,PathVideoName,KeyFrame,HistrogrameVecter) " + // " VALUES ( (Select count(*) from CollectionShot ),'" + videoname + "','" + name + "' , '" + keyF + "','" + Vechist + "')", con); //cmd.ExecuteNonQuery(); //con.Close(); } reader.Close(); */ }
private void Run_Click(object sender, EventArgs e) { VideoFileReader reader = new VideoFileReader(); // open video file reader.Open(textBox1.Text); // check some of its attributes //Console.WriteLine("width: " + reader.Width); //Console.WriteLine("height: " + reader.Height); //Console.WriteLine("fps: " + reader.FrameRate); //Console.WriteLine("codec: " + reader.CodecName); int[][] frameRGB = new int[reader.FrameCount][]; // read 100 video frames out of it for (int i = 0; i < reader.FrameCount; i++) { //int disRed = 0; //int disGreen = 0; //int disBlue = 0; Bitmap videoFrame = reader.ReadVideoFrame(); // process the frame somehow ImageStatistics rgbStatistics = new ImageStatistics(videoFrame); int[] redValues = rgbStatistics.Red.Values; int[] greenValues = rgbStatistics.Green.Values; int[] blueValues = rgbStatistics.Blue.Values; int[] his = new int[256]; for (int j = 0; j < 256; j++) { his[j] = (redValues[j] + greenValues[j] + blueValues[j]) / 3; } frameRGB[i] = his; //Bitmap videoFrame2 = reader.ReadVideoFrame(); //// process the frame somehow //ImageStatistics rgbStatistics2 = new ImageStatistics(videoFrame2); //int[] redValues2 = rgbStatistics2.Red.Values; //int[] greenValues2 = rgbStatistics2.Green.Values; //int[] blueValues2 = rgbStatistics2.Blue.Values; //for (int j = 0; j < 256; j++) //{ // disRed = disRed + Math.Abs(redValues[j] - redValues2[j]); // disGreen = disGreen + Math.Abs(greenValues[j] - greenValues2[j]); // disBlue = disBlue + Math.Abs(blueValues[j] - blueValues2[j]); //} //int sumdis = disRed + disGreen + disBlue; //สร้างตัวแปรเก็บr+G+B เอาไว้หาค่าthredshold;กำหนดเอง // dispose the frame when it is no longer required videoFrame.Dispose(); } reader.Close(); Sdis = new int[frameRGB.Length - 1]; for (int g = 0; g < frameRGB.Length - 1; g++) { int dis = 0; for (int k = 0; k < 256; k++) { dis += Math.Abs(frameRGB[g][k] - frameRGB[g + 1][k]); } Sdis[g] = dis; } this.chart1.Titles.Add("Distance"); Series series = this.chart1.Series.Add("Distance"); for (int ss = 0; ss < frameRGB.Length - 1; ss++) { series.Points.AddXY(ss, Sdis[ss]); } }
/// <summary> /// Reason : To read video and read frames from it /// </summary> public void VideoProcessing() { VideoFileReader reader = new VideoFileReader(); string path = @"C:\Users\Cuelogic\Desktop\sample images\videos\drop.avi"; reader.Open(path); for (int i = 0; i < 100; i++) { Bitmap videoFrame = reader.ReadVideoFrame(); videoFrame.Dispose(); } reader.Close(); }