public IAviAudioStream CreateAudioStream(AviWriter writer)
 {
     // Create encoding or simple stream based on settings
     if (EncodeAudio)
     {
         // LAME DLL path is set in App.OnStartup()
         return writer.AddMp3AudioStream(WaveFormat.Channels, WaveFormat.SampleRate, AudioBitRate);
     }
     else return writer.AddAudioStream(WaveFormat.Channels, WaveFormat.SampleRate, WaveFormat.BitsPerSample);
 }
Beispiel #2
0
 private IAviAudioStream CreateAudioStream(WaveFormat waveFormat, bool encode, int bitRate)
 {
     // Create encoding or simple stream based on settings
     if (encode)
     {
         // LAME DLL path is set in App.OnStartup()
         return(writer.AddMp3AudioStream(waveFormat.Channels, waveFormat.SampleRate, bitRate));
     }
     else
     {
         return(writer.AddAudioStream(
                    channelCount: waveFormat.Channels,
                    samplesPerSecond: waveFormat.SampleRate,
                    bitsPerSample: waveFormat.BitsPerSample));
     }
 }
Beispiel #3
0
        public void SaveAsAvi(string fileName)
        {
            var writer = new AviWriter(fileName)
            {
                FramesPerSecond = (1000000 + this.Header.FrameDelay / 2) / this.Header.FrameDelay,
                EmitIndex1      = true
            };

            try
            {
                IAviVideoStream videoStream = writer.AddMotionJpegVideoStream(this.Header.Width, this.Header.Height, 70);
                IAviAudioStream audioStream = writer.AddAudioStream(this.AudioHeader.NumChannels, this.AudioHeader.Frequency, 16);

                this.BeginPlay();

                try
                {
                    byte[] audio;
                    byte[] video;

                    while (this.RetrieveNextFrame(out audio, out video))
                    {
                        if (video != null)
                        {
                            byte[] buffer = SnmFile.Convert16BppTo32Bpp(video);
                            videoStream.WriteFrame(true, buffer, 0, buffer.Length);
                        }

                        if (audio != null)
                        {
                            audioStream.WriteBlock(audio, 0, audio.Length);
                        }
                    }
                }
                finally
                {
                    this.EndPlay();
                }
            }
            finally
            {
                writer.Close();
            }
        }
 public IAviAudioStream CreateAudioStream(AviWriter writer)
 {
     return writer.AddAudioStream(WaveFormat.Channels, WaveFormat.SampleRate, WaveFormat.BitsPerSample);
 }
Beispiel #5
0
        public Recorder(string filePath,
                        int quality, int x, int y, int width, int height, bool captureCursor,
                        int inputSourceIndex, bool separateAudio)
        {
            this.x             = x;
            this.y             = y;
            this.width         = width;
            this.height        = height;
            this.captureCursor = captureCursor;

            writer = new AviWriter(filePath)
            {
                FramesPerSecond = 15,
                EmitIndex1      = true,
            };

            if (quality == 0)
            {
                videoStream      = writer.AddUncompressedVideoStream(width, height);
                videoStream.Name = "Quick Screen Recorder - Motion JPEG video stream";
            }
            else
            {
                videoStream      = writer.AddMotionJpegVideoStream(width, height, quality);
                videoStream.Name = "Quick Screen Recorder - Motion JPEG video stream";
            }

            if (inputSourceIndex >= 0)
            {
                var waveFormat = new WaveFormat(44100, 16, 1);

                audioStream = writer.AddAudioStream(
                    channelCount: waveFormat.Channels,
                    samplesPerSecond: waveFormat.SampleRate,
                    bitsPerSample: waveFormat.BitsPerSample
                    );
                audioStream.Name = "Quick Screen Recorder - Input audio stream";

                audioSource = new WaveInEvent()
                {
                    DeviceNumber       = inputSourceIndex,
                    WaveFormat         = waveFormat,
                    BufferMilliseconds = (int)Math.Ceiling(1000 / writer.FramesPerSecond),
                    NumberOfBuffers    = 3,
                };
                audioSource.DataAvailable += audioSource_DataAvailable;

                if (separateAudio)
                {
                    waveFile = new WaveFileWriter(filePath + " (Input audio).wav", audioSource.WaveFormat);
                }
            }
            else if (inputSourceIndex == -1)
            {
                audioSource = new WasapiLoopbackCapture();

                audioStream = writer.AddAudioStream(
                    channelCount: 1,
                    samplesPerSecond: audioSource.WaveFormat.SampleRate,
                    bitsPerSample: audioSource.WaveFormat.BitsPerSample
                    );
                audioStream.Name = "Quick Screen Recorder - System sounds audio stream";

                audioSource.DataAvailable += audioSource_DataAvailable;

                if (separateAudio)
                {
                    waveFile = new WaveFileWriter(filePath + " (System sounds).wav", audioSource.WaveFormat);
                }
            }

            screenThread = new Thread(RecordScreen)
            {
                Name         = typeof(Recorder).Name + ".RecordScreen",
                IsBackground = true
            };

            if (audioSource != null)
            {
                videoFrameWritten.Set();
                audioBlockWritten.Reset();
                audioSource.StartRecording();
            }

            tf.compat.v1.disable_eager_execution();

            //var tfSession = tf.Session();

            detectorGraph = tf.Graph().as_default();

            detectorGraph.Import(Path.Combine(modelDir, pbDetectorFile));

            emotionGraph = tf.Graph().as_default();
            emotionGraph.Import(Path.Combine(modelDir, pbEmotionFile));

            Console.WriteLine(Environment.OSVersion, Color.Yellow);
            Console.WriteLine($"64Bit Operating System: {Environment.Is64BitOperatingSystem}", Color.Yellow);
            Console.WriteLine($"TensorFlow.NET v{Assembly.GetAssembly(typeof(TF_DataType)).GetName().Version}", Color.Yellow);
            Console.WriteLine($"TensorFlow Binary v{tf.VERSION}", Color.Yellow);
            Console.WriteLine($".NET CLR: {Environment.Version}", Color.Yellow);
            Console.WriteLine(Environment.CurrentDirectory, Color.Yellow);

            //writerCSV = new StreamWriter("output.csv");
            //csv = new CsvWriter(writerCSV, CultureInfo.InvariantCulture);
            using (var writer = new StreamWriter("output.csv"))
                using (var csv = new CsvWriter(writer, CultureInfo.InvariantCulture))
                {
                    csv.WriteHeader <CSVRecord>();
                    csv.NextRecord();
                }

            screenThread.Start();
        }
Beispiel #6
0
 public IAviAudioStream CreateAudioStream(AviWriter writer)
 {
     // Create encoding or simple stream based on settings
     if (IsLoopback) return writer.AddAudioStream(WaveFormat.Channels, WaveFormat.SampleRate, WaveFormat.BitsPerSample, AudioFormats.Float);
     else if (EncodeAudio)
     {
         // LAME DLL path is set in App.OnStartup()
         return writer.AddMp3AudioStream(WaveFormat.Channels, WaveFormat.SampleRate, AudioBitRate);
     }
     else return writer.AddAudioStream(WaveFormat.Channels, WaveFormat.SampleRate, WaveFormat.BitsPerSample);
 }
Beispiel #7
0
        public static void Decode(string filename, Stream fs, bool swapped, long framePosition)
        {
            char progress = ' ';

            var aviWriter = new AviWriter(filename + ".avi")
            {
                EmitIndex1 = true, FramesPerSecond = 18
            };

            IAviVideoStream videoStream = aviWriter.AddVideoStream(144, 80, BitsPerPixel.Bpp24);

            videoStream.Codec = KnownFourCCs.Codecs.Uncompressed;
            IAviAudioStream audioStream = aviWriter.AddAudioStream(2, 17784, 8);

            fs.Position = framePosition;
            byte[] frameBuffer = new byte[19760];
            fs.Read(frameBuffer, 0, frameBuffer.Length);

            int audioStart = swapped ? 9 : 8;

            byte[] frameMarkerToUse = swapped ? SwappedFrameMarker : FrameMarker;
            byte[] frameMaskToUse   = swapped ? SwappedFrameMask : FrameMask;

            if (swapped)
            {
                frameBuffer = Swapping.SwapBuffer(frameBuffer);
            }

            var outFs = new MemoryStream();

            for (int i = 9; i <= frameBuffer.Length; i += 10)
            {
                switch ((i / 10) % 4)
                {
                case 0:
                    progress = '-';

                    break;

                case 1:
                    progress = '\\';

                    break;

                case 2:
                    progress = '|';

                    break;

                case 3:
                    progress = '/';

                    break;
                }

                Console.Write($"\r{Localization.ExtractingAudio}", progress);
                outFs.WriteByte(frameBuffer[i]);
            }

            byte[] videoFrame = Color.DecodeFrame(frameBuffer);
            videoStream.WriteFrame(true, videoFrame, 0, videoFrame.Length);
            audioStream.WriteBlock(outFs.ToArray(), 0, (int)outFs.Length);

            int totalFrames = 1;

            framePosition += 19760;
            byte[] buffer = new byte[frameMarkerToUse.Length];

            while (framePosition + 19760 < fs.Length)
            {
                switch (totalFrames % 4)
                {
                case 0:
                    progress = '-';

                    break;

                case 1:
                    progress = '\\';

                    break;

                case 2:
                    progress = '|';

                    break;

                case 3:
                    progress = '/';

                    break;
                }

                Console.Write($"\r{Localization.LookingForMoreFrames}", progress);

                for (int i = 0; i < buffer.Length; i++)
                {
                    buffer[i] &= frameMaskToUse[i];
                }

                if (!buffer.SequenceEqual(frameMarkerToUse))
                {
                    Console.Write("\r                                      \r");
                    Console.WriteLine(Localization.FrameAndNextAreNotAligned, totalFrames);
                    long expectedFramePosition = framePosition;

                    while (framePosition < fs.Length)
                    {
                        fs.Position = framePosition;
                        fs.Read(buffer, 0, buffer.Length);

                        for (int i = 0; i < buffer.Length; i++)
                        {
                            buffer[i] &= frameMaskToUse[i];
                        }

                        if (buffer.SequenceEqual(frameMarkerToUse))
                        {
                            Console.Write("\r                                      \r");

                            fs.Position = framePosition;
                            frameBuffer = new byte[19760];
                            fs.Read(frameBuffer, 0, frameBuffer.Length);

                            if (swapped)
                            {
                                frameBuffer = Swapping.SwapBuffer(frameBuffer);
                            }

                            outFs = new MemoryStream();

                            for (int i = 9; i <= frameBuffer.Length; i += 10)
                            {
                                switch ((i / 10) % 4)
                                {
                                case 0:
                                    progress = '-';

                                    break;

                                case 1:
                                    progress = '\\';

                                    break;

                                case 2:
                                    progress = '|';

                                    break;

                                case 3:
                                    progress = '/';

                                    break;
                                }

                                Console.Write($"\r{Localization.ExtractingAudio}", progress);
                                outFs.WriteByte(frameBuffer[i]);
                            }

                            videoFrame = Color.DecodeFrame(frameBuffer);
                            videoStream.WriteFrame(true, videoFrame, 0, videoFrame.Length);
                            audioStream.WriteBlock(outFs.ToArray(), 0, (int)outFs.Length);

                            totalFrames++;
                            Console.Write("\r                                      \r");

                            Console.WriteLine(Localization.FrameFoundAtPosition, framePosition, totalFrames,
                                              framePosition - expectedFramePosition);

                            Console.
                            WriteLine(framePosition % 2352 == 0 ? Localization.FrameIsAtSectorBoundary : Localization.FrameIsNotAtSectorBoundary,
                                      totalFrames);

                            framePosition += 19760;

                            break;
                        }

                        framePosition++;
                    }

                    continue;
                }

                if (framePosition % 2352 == 0)
                {
                    Console.Write("\r                                      \r");
                    Console.WriteLine(Localization.FrameIsAtSectorBoundary, totalFrames);
                }

                Console.Write("\r                                      \r");
                fs.Position = framePosition;
                frameBuffer = new byte[19760];
                fs.Read(frameBuffer, 0, frameBuffer.Length);

                if (swapped)
                {
                    frameBuffer = Swapping.SwapBuffer(frameBuffer);
                }

                outFs = new MemoryStream();

                for (int i = 9; i <= frameBuffer.Length; i += 10)
                {
                    switch ((i / 10) % 4)
                    {
                    case 0:
                        progress = '-';

                        break;

                    case 1:
                        progress = '\\';

                        break;

                    case 2:
                        progress = '|';

                        break;

                    case 3:
                        progress = '/';

                        break;
                    }

                    Console.Write($"\r{Localization.ExtractingAudio}", progress);
                    outFs.WriteByte(frameBuffer[i]);
                }

                videoFrame = Color.DecodeFrame(frameBuffer);
                videoStream.WriteFrame(true, videoFrame, 0, videoFrame.Length);
                audioStream.WriteBlock(outFs.ToArray(), 0, (int)outFs.Length);

                totalFrames++;
                fs.Position = framePosition;
                fs.Read(buffer, 0, buffer.Length);
                framePosition += 19760;
            }

            Console.Write("\r                                      \r");
            Console.WriteLine(Localization.FramesFound, totalFrames);

            outFs.Close();
            aviWriter.Close();
        }
Beispiel #8
0
        private bool StartRecording()
        {
            int captureWidth = (int)(m_Capture.CaptureBounds.Width * m_Capture.Scale),
                captureHeight = (int)(m_Capture.CaptureBounds.Height * m_Capture.Scale),
                codecSelectedIndex = comboBox_videoCodec.SelectedIndex,
                codecQuality = Convert.ToInt32(textBox_recordQuality.Text);

            try
            {
                m_AviWriter = new AviWriter(m_AviFilePath)
                {
                    FramesPerSecond = m_Capture.FramesPerSecond,
                    EmitIndex1 = true,
                };

                if (codecSelectedIndex == 0)
                {
                    m_AviVideoStream = m_AviWriter.AddVideoStream(captureWidth, captureHeight);
                }
                else if (codecSelectedIndex == 1)
                {
                    m_AviVideoStream = m_AviWriter.AddMotionJpegVideoStream(captureWidth, captureHeight, codecQuality);
                }
                else
                {
                    var codecs = Mpeg4VideoEncoderVcm.GetAvailableCodecs();
                    var encoder = new Mpeg4VideoEncoderVcm(captureWidth, captureHeight, m_Capture.FramesPerSecond, 0, codecQuality, codecs[codecSelectedIndex - 2].Codec);
                    m_AviVideoStream = m_AviWriter.AddEncodingVideoStream(encoder);
                }


                if (checkBox_recordAudio.Checked)
                {
                    m_AviAudioStream = m_AviWriter.AddAudioStream(m_Recorder.WaveFormat.Channels, m_Recorder.WaveFormat.SampleRate, m_Recorder.WaveFormat.BitsPerSample);
                }
            }
            catch
            {
                Debug.Log("Failed to Start Recording.");
                return false;
            }

            return true;
        }
        public Recorder(string filePath,
                        int quality, int x, int y, int width, int height, bool captureCursor,
                        int inputSourceIndex, bool separateAudio)
        {
            this.x             = x;
            this.y             = y;
            this.width         = width;
            this.height        = height;
            this.captureCursor = captureCursor;

            writer = new AviWriter(filePath)
            {
                FramesPerSecond = 15,
                EmitIndex1      = true,
            };

            if (quality == 0)
            {
                videoStream      = writer.AddUncompressedVideoStream(width, height);
                videoStream.Name = "Quick Screen Recorder - Motion JPEG video stream";
            }
            else
            {
                videoStream      = writer.AddMotionJpegVideoStream(width, height, quality);
                videoStream.Name = "Quick Screen Recorder - Motion JPEG video stream";
            }

            if (inputSourceIndex >= 0)
            {
                var waveFormat = new WaveFormat(44100, 16, 1);

                audioStream = writer.AddAudioStream(
                    channelCount: waveFormat.Channels,
                    samplesPerSecond: waveFormat.SampleRate,
                    bitsPerSample: waveFormat.BitsPerSample
                    );
                audioStream.Name = "Quick Screen Recorder - Input audio stream";

                audioSource = new WaveInEvent()
                {
                    DeviceNumber       = inputSourceIndex,
                    WaveFormat         = waveFormat,
                    BufferMilliseconds = (int)Math.Ceiling(1000 / writer.FramesPerSecond),
                    NumberOfBuffers    = 3,
                };
                audioSource.DataAvailable += audioSource_DataAvailable;

                if (separateAudio)
                {
                    waveFile = new WaveFileWriter(filePath + " (Input audio).wav", audioSource.WaveFormat);
                }
            }
            else if (inputSourceIndex == -1)
            {
                audioSource = new WasapiLoopbackCapture();

                audioStream = writer.AddAudioStream(
                    channelCount: 1,
                    samplesPerSecond: audioSource.WaveFormat.SampleRate,
                    bitsPerSample: audioSource.WaveFormat.BitsPerSample
                    );
                audioStream.Name = "Quick Screen Recorder - System sounds audio stream";

                audioSource.DataAvailable += audioSource_DataAvailable;

                if (separateAudio)
                {
                    waveFile = new WaveFileWriter(filePath + " (System sounds).wav", audioSource.WaveFormat);
                }
            }

            screenThread = new Thread(RecordScreen)
            {
                Name         = typeof(Recorder).Name + ".RecordScreen",
                IsBackground = true
            };

            if (audioSource != null)
            {
                videoFrameWritten.Set();
                audioBlockWritten.Reset();
                audioSource.StartRecording();
            }

            screenThread.Start();
        }