Beispiel #1
0
        /// <summary>Add a wave audio stream from another file to this file</summary>
        /// <param name="waveFileName">Name of the wave file to add</param>
        /// <param name="startAtFrameIndex">Index of the video frame at which the sound is going to start</param>
        public void AddAudioStream(String waveFileName, int startAtFrameIndex)
        {
            AviManager  audioManager = new AviManager(waveFileName, true);
            AudioStream newStream    = audioManager.GetWaveStream();

            AddAudioStream(newStream, startAtFrameIndex);
            audioManager.Close();
        }
Beispiel #2
0
        /// <summary>Add a wave audio stream from another file to this file</summary>
        /// <param name="waveFileName">Name of the wave file to add</param>
        public void AddAudioStream(String waveFileName)
        {
            AviManager  audioManager = new AviManager(waveFileName, true);
            AudioStream newStream    = audioManager.GetWaveStream();

            AddAudioStream(newStream);
            audioManager.Close();
        }
Beispiel #3
0
        private void btnBrowse_Click(object sender, EventArgs e)
        {
            OpenFileDialog oFD1 = new OpenFileDialog();
            oFD1.Multiselect = true;

            if (oFD1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                files = oFD1.SafeFileNames; //Save only the names
                paths = oFD1.FileNames; //Save the full paths
                for (int i = 0; i < files.Length; i++)
                {
                    //listBox1.Items.Add(files[i]); //Add songs to the listbox
                    ext = Path.GetExtension(oFD1.FileName);
                    if (ext == ".avi")
                    {
                        //Convert Avi to wav
                        AviManager aviManager = new AviManager(oFD1.FileName, true);
                        AudioStream audioStream = aviManager.GetWaveStream();
                        audioStream.ExportStream(oFD1.FileName + ".wav");
                        filepath = oFD1.FileName + ".wav";
                        aviManager.Close();
                        listBox1.Items.Add(files[i]); //Add songs to the listbox
                    }
                    else if (ext == ".wav")
                    {
                        filepath = oFD1.FileName;
                        listBox1.Items.Add(files[i]); //Add songs to the listbox
                    }
                }
            }

            NAudio.Wave.WaveChannel32 wave = new NAudio.Wave.WaveChannel32(new NAudio.Wave.WaveFileReader(filepath));
            WaveFileReader wavFile = new WaveFileReader(filepath);
            byte[] mainBuffer = new byte[wave.Length];

            float fileSize = (float)wavFile.Length / 1048576;
            if (fileSize < 2)
                window = 8;
            else if (fileSize > 2 && fileSize < 4)
                window = 16;
            else if (fileSize > 4 && fileSize < 8)
                window = 32;
            else if (fileSize > 8 && fileSize < 12)
                window = 128;
            else if (fileSize > 12 && fileSize < 20)
                window = 256;
            else if (fileSize > 20 && fileSize < 30)
                window = 512;
            else
                window = 2048;

            float[] fbuffer = new float[mainBuffer.Length / window];
            wave.Read(mainBuffer, 0, mainBuffer.Length);

            for (int i = 0; i < fbuffer.Length; i++)
            {
                fbuffer[i] = (BitConverter.ToSingle(mainBuffer, i * window));
            }

            double time = wave.TotalTime.TotalSeconds;
            GraphPane myPane1 = zedGraphControl2.GraphPane;
            PointPairList list1 = new PointPairList();
            PointPairList list2 = new PointPairList();
            for (int i = 0; i < fbuffer.Length; i++)
            {
                list1.Add(i, fbuffer[i]);
            }
            list2.Add(0, 0);
            list2.Add(time, 0);
            if (myCurve1 != null && myCurve2 != null)
            {
                myCurve1.Clear();
                myCurve2.Clear();
            }
            GraphPane myPane2 = zedGraphControl2.GraphPane;
            myPane2.Title.Text = "Audio Sound Wave";
            myPane2.XAxis.Title.Text = "Time, Seconds";
            myPane2.YAxis.Title.Text = "Sound Wave Graph";
            myCurve1 = myPane1.AddCurve(null, list1, System.Drawing.Color.Blue, SymbolType.None);
            myCurve1.IsX2Axis = true;
            myCurve2 = myPane1.AddCurve(null, list2, System.Drawing.Color.Black, SymbolType.None);
            myPane1.XAxis.Scale.MaxAuto = true;
            myPane1.XAxis.Scale.MinAuto = true;

            //Threshold Line
            double threshHoldY = -1.2;
            double threshHoldX = 1.2;
            LineObj threshHoldLine = new LineObj(System.Drawing.Color.Red, myPane2.XAxis.Scale.Min, threshHoldY, myPane2.XAxis.Scale.Max, threshHoldY);
            LineObj threshHoldLine2 = new LineObj(System.Drawing.Color.Red, myPane2.XAxis.Scale.Min, threshHoldX, myPane2.XAxis.Scale.Max, threshHoldX);
            myPane2.GraphObjList.Add(threshHoldLine);
            myPane2.GraphObjList.Add(threshHoldLine2);

            // Add a text box with instructions
            TextObj text = new TextObj(
                "Ratio Conversion: 1:100\nRed Lines: Threshold\nZoom: left mouse & drag\nContext Menu: right mouse",
                0.05f, 0.95f, CoordType.ChartFraction, AlignH.Left, AlignV.Bottom);
            text.FontSpec.StringAlignment = StringAlignment.Near;
            myPane2.GraphObjList.Add(text);

            // Show the x axis grid
            myPane2.XAxis.MajorGrid.IsVisible = true;
            myPane2.YAxis.MajorGrid.IsVisible = true;
            // Just manually control the X axis range so it scrolls continuously
            // instead of discrete step-sized jumps
            //myPane2.XAxis.Scale.Format = @"00:00:00";
            myPane2.XAxis.Scale.IsSkipCrossLabel = true;
            myPane2.XAxis.Scale.IsPreventLabelOverlap = true;
            myPane2.XAxis.Type = ZedGraph.AxisType.Linear;
            myPane2.XAxis.Scale.Min = 0;
            myPane2.XAxis.Scale.Max = 1.2;
            myPane2.AxisChange();

            // turn off the opposite tics so the Y tics don't show up on the Y2 axis
            myPane2.YAxis.MajorTic.IsOpposite = false;
            myPane2.YAxis.MinorTic.IsOpposite = false;
            // Don't display the Y zero line
            myPane2.YAxis.MajorGrid.IsZeroLine = false;
            // Align the Y axis labels so they are flush to the axis
            myPane2.YAxis.Scale.Align = AlignP.Inside;
            // Manually set the axis range
            myPane2.YAxis.Scale.Min = -1.5;
            myPane2.YAxis.Scale.Max = 1.5;

            zedGraphControl2.AxisChange();
            zedGraphControl2.Invalidate();
        }
		/// <summary>Add a wave audio stream from another file to this file</summary>
		/// <param name="waveFileName">Name of the wave file to add</param>
        /// <param name="startAtFrameIndex">Index of the video frame at which the sound is going to start</param>
        public void AddAudioStream(String waveFileName, int startAtFrameIndex) {
            AviManager audioManager = new AviManager(waveFileName, true);
			AudioStream newStream = audioManager.GetWaveStream();
            AddAudioStream(newStream, startAtFrameIndex);
            audioManager.Close();
		}
        private void btnRead_Click(object sender, System.EventArgs e)
        {
            AviManager aviManager = new AviManager(txtAviFileName.Text, true);
            VideoStream stream = aviManager.GetVideoStream();
            txtReportRead.Text = "Width: " + stream.Width;
            txtReportRead.Text += "\r\nHeight: " + stream.Height;
            txtReportRead.Text += "\r\nCount of Frames: " + stream.CountFrames;
            txtReportRead.Text += "\r\nFrame Rate: " + stream.FrameRate;

            txtReportRead.Text += "\r\nWave Sound:";

            try {
                AudioStream waveStream = aviManager.GetWaveStream();
                txtReportRead.Text += "\r\nSamples per Second: " + waveStream.CountSamplesPerSecond.ToString();
                txtReportRead.Text += "\r\nBits per Sample: " + waveStream.CountBitsPerSample.ToString();
                txtReportRead.Text += "\r\nChannels: " + waveStream.CountChannels.ToString();
            } catch {
                txtReportRead.Text += " None";
            }
        }
 private void btnExtractWave_Click(object sender, System.EventArgs e)
 {
     txtReportSound.Text = "Extracting " + txtAviFileName.Text + " to sound.wav...\r\n";
     AviManager aviManager = new AviManager(txtAviFileName.Text, true);
     try {
         AudioStream audioStream = aviManager.GetWaveStream();
         audioStream.ExportStream(@"..\..\testdata\sound.wav");
         aviManager.Close();
         txtReportSound.Text += "...finished.";
     } catch (Exception ex) {
         MessageBox.Show(this, "The file does not contain a wave audio stream, or it cannot be opened.\r\n" + ex.ToString(), "No Stream Found");
     }
 }
Beispiel #7
0
        protected void upload_Click(object sender, EventArgs e)
        {
            string filepath = txt_fileUpLoad.Text;
            title = tbTitle.Text.ToString();
            desc = tbDescription.Text.ToString();

            if (fileUpLoad.HasFile)
            {
                string fileType = Path.GetExtension(filepath);
                if (fileType == ".avi")
                {
                    //Get the address
                    address = tbLocation.Text.ToString();
                    //double lng = Double.Parse(tbX.Text.ToString());
                    //double lat = Double.Parse(tbY.Text.ToString());
                    //string convert = CoordinatesConverter.CoordinatesConvertor(lng, lat, 4326, 3414);
                    //string[] converting = convert.Split(',');
                    //x = Double.Parse(converting[0]);
                    //y = Double.Parse(converting[1]);

                    //Get the video filename for analysis
                    type = "Video";
                    strVideoPath = fileUpLoad.PostedFile.FileName.ToString();
                    savePath = Server.MapPath("~\\video\\");
                    fileUpLoad.PostedFile.SaveAs(savePath + strVideoPath);
                    path = savePath + strVideoPath;
                    FileInfo oFileInfo = new FileInfo(path);
                    if (oFileInfo != null || oFileInfo.Length == 0)
                    {
                        date = oFileInfo.CreationTime;
                    }
                    AviManager aviManager = new AviManager(path, true);
                    AudioStream audioStream = aviManager.GetWaveStream();
                    audioStream.ExportStream(path + ".wav");
                    vfilepath = path + ".wav";
                    aviManager.Close();
                    soundAnalysis();
                    grabVideo(path);
                    //videoAnalysis();
                    //insertIntoDatabase();
                }
                else if (fileType == ".jpg")
                {
                    type = "Image";
                    txt_fileUpLoad.Text = "";
                    strVideoPath = fileUpLoad.PostedFile.FileName.ToString();
                    savePath = Server.MapPath("~\\image\\");
                    fileUpLoad.PostedFile.SaveAs(savePath + strVideoPath);
                    Bitmap pic = new Bitmap(savePath + strVideoPath);
                    property_ids = pic.PropertyIdList;

                    foreach (int scan_property in property_ids)
                    {
                        byte_property_id = pic.GetPropertyItem(scan_property).Value;
                        prop_type = pic.GetPropertyItem(scan_property).Type.ToString();

                        if (scan_property == 2)
                        {
                            //Latitude degrees minutes and seconds (rational)
                            degrees = System.BitConverter.ToInt32(byte_property_id, 0) / System.BitConverter.ToInt32(byte_property_id, 4);
                            minutes = System.BitConverter.ToInt32(byte_property_id, 8) / System.BitConverter.ToInt32(byte_property_id, 12);
                            seconds = System.BitConverter.ToInt32(byte_property_id, 16) / System.BitConverter.ToInt32(byte_property_id, 20);

                            lat_dd = degrees + (minutes / 60) + (seconds / 3600); //->Latitude
                        }
                        else if (scan_property == 4)
                        {
                            //Longitude degrees minutes and seconds (rational)
                            degrees = System.BitConverter.ToInt32(byte_property_id, 0) / System.BitConverter.ToInt32(byte_property_id, 4);
                            minutes = System.BitConverter.ToInt32(byte_property_id, 8) / System.BitConverter.ToInt32(byte_property_id, 12);
                            seconds = System.BitConverter.ToInt32(byte_property_id, 16) / System.BitConverter.ToInt32(byte_property_id, 20);
                            long_dd = degrees + (minutes / 60) + (seconds / 3600); //-->longtitude
                        }
                        else
                        {
                            //Do nothing...
                            /**
                            if (scan_property == 24)
                            {
                                //Magnetic bearing of subject to photographer (rational)
                                //do nothing
                            }
                            //scan_property ++;
                             * **/
                        }
                    }
                }
                if ((lat_dd > 0) && (long_dd > 0))
                {
                    //Reverse Geocoding
                    XmlDocument doc = new XmlDocument();
                    doc.Load("http://maps.googleapis.com/maps/api/geocode/xml?latlng=" + lat_dd + "," + long_dd + "&sensor=false");
                    XmlNode element = doc.SelectSingleNode("//GeocodeResponse/status");
                    if (element.InnerText == "ZERO_RESULTS")
                    {
                        lb_msg.Text = "No result found";
                    }
                    else
                    {
                        element = doc.SelectSingleNode("//GeocodeResponse/result/formatted_address");
                        address = element.InnerText;
                    }

                    string convert = CoordinatesConverter.CoordinatesConvertor(long_dd, lat_dd, 4326, 3414);
                    string[] converting = convert.Split(',');
                    x = Double.Parse(converting[0]);
                    y = Double.Parse(converting[1]);
                }
                else
                {
                    address = tbLocation.Text.ToString();
                    double lng = Double.Parse(tbX.Text.ToString());
                    double lat = Double.Parse(tbY.Text.ToString());
                    string convert = CoordinatesConverter.CoordinatesConvertor(lng, lat, 4326, 3414);
                    string[] converting = convert.Split(',');
                    x = Double.Parse(converting[0]);
                    y = Double.Parse(converting[1]);
                }
            }
        }