Example #1
0
    protected void Click_Handler(object sender, EventArgs e)
    {
        Gtk.FileChooserDialog dialog = new FileChooserDialog("Choose a file",
                                                             this,
                                                             FileChooserAction.Open,
                                                             new object[] {
            Gtk.Stock.Open,
            Gtk.ResponseType.Ok
        });
        dialog.Run();

        string file = dialog.Filename;

        dialog.Destroy();
        //writer.Seek(44, SeekOrigin.Begin);
        workingThread = new Thread(new ThreadStart(() =>
        {
            var stream     = FFMpegBase.Instance.GetAVStream(file);
            IAVFrame frame = null;
            while (((frame = stream.GetNext()) != null) && (!closing))
            {
                if (frame.FrameType == AVFrameType.Video)
                {
                    SharpFFmpeg.VideoFrame video = (SharpFFmpeg.VideoFrame)frame;
                    if (frame.Decode())
                    {
                        var data = video.ImgData;
                        DrawImage(data);
                    }
                }
                else if (frame.FrameType == AVFrameType.Audio)
                {
                    SharpFFmpeg.AudioFrame audio = (SharpFFmpeg.AudioFrame)frame;
                    if (audio.Decode())
                    {
                        var data = audio.WaveDate;
                        audioPlayer.PutSample(data);
                    }
                }
                frame.Close();
            }
            audioPlayer.Stop();
            stream.Close();
        }));
        workingThread.Start();
    }
Example #2
0
        //private void WriteWaveHeader(BinaryWriter writer, WaveDataType format)
        //{
        //    WAVE_Header wav_Header = new WAVE_Header();
        //    wav_Header.RIFF_ID[0] = 'R';
        //    wav_Header.RIFF_ID[1] = 'I';
        //    wav_Header.RIFF_ID[2] = 'F';
        //    wav_Header.RIFF_ID[3] = 'F';
        //    wav_Header.File_Size = waveDataSize + 36;
        //    wav_Header.RIFF_Type[0] = 'W';
        //    wav_Header.RIFF_Type[1] = 'A';
        //    wav_Header.RIFF_Type[2] = 'V';
        //    wav_Header.RIFF_Type[3] = 'E';

        //    wav_Header.FMT_ID[0] = 'f';
        //    wav_Header.FMT_ID[1] = 'm';
        //    wav_Header.FMT_ID[2] = 't';
        //    wav_Header.FMT_ID[3] = ' ';
        //    wav_Header.FMT_Size = 16;
        //    wav_Header.FMT_Tag = 0x0001;
        //    wav_Header.FMT_Channel = (ushort)format.channel;
        //    wav_Header.FMT_SamplesPerSec = format.sample_rate;

        //    var nBlockAlign = (short)(format.channel * (format.bit_per_sample / 8));
        //    var nAvgBytesPerSec = format.sample_rate * nBlockAlign;

        //    wav_Header.AvgBytesPerSec = nAvgBytesPerSec;
        //    wav_Header.BlockAlign = (ushort)nBlockAlign;
        //    wav_Header.BitsPerSample = (ushort)format.bit_per_sample;

        //    wav_Header.DATA_ID[0] = 'd';
        //    wav_Header.DATA_ID[1] = 'a';
        //    wav_Header.DATA_ID[2] = 't';
        //    wav_Header.DATA_ID[3] = 'a';
        //    wav_Header.DATA_Size = waveDataSize;


        //    int waveHdrSize = Marshal.SizeOf(wav_Header);
        //    var ptr = Marshal.AllocHGlobal(waveHdrSize);
        //    byte[] data = new byte[waveHdrSize];
        //    Marshal.StructureToPtr(wav_Header, ptr, false);
        //    Marshal.Copy(ptr, data, 0, waveHdrSize);
        //    writer.Seek(0, SeekOrigin.Begin);
        //    writer.Write(data);
        //    writer.Flush();
        //    Marshal.FreeHGlobal(ptr);
        //}


        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog dialog = new OpenFileDialog();

            dialog.ShowDialog();
            string file = dialog.FileName;
            //writer.Seek(44, SeekOrigin.Begin);
            WaveDataType first = null;

            workingThread = new Thread(new ThreadStart(() =>
            {
                var stream     = FFMpegBase.Instance.GetAVStream(file);
                IAVFrame frame = null;
                while (((frame = stream.GetNext()) != null) && (!closing))
                {
                    if (frame.FrameType == AVFrameType.Video)
                    {
                        SharpFFmpeg.VideoFrame video = (SharpFFmpeg.VideoFrame)frame;
                        if (frame.Decode())
                        {
                            var data = video.ImgData;
                            DrawImage(data);
                        }
                    }
                    else if (frame.FrameType == AVFrameType.Audio)
                    {
                        SharpFFmpeg.AudioFrame audio = (SharpFFmpeg.AudioFrame)frame;
                        if (audio.Decode())
                        {
                            var data = audio.WaveDate;
                            audioPlayer.PutSample(data);
                        }
                    }
                    frame.Close();
                }
                stream.Close();
                audioPlayer.Stop();
            }));
            workingThread.Start();
        }