static void Main(string[] args)
        {
            String       input_path  = "F:\\work\\tmp\\capturedPCM_ffmpeg_stdout_converted_8000Hz_u8bit_1ch_120sec.raw";
            String       output_path = "F:\\work\\tmp\\capturedPCM_ffmpeg_stdout_converted_8000Hz_u8bit_1ch_120sec_encoded_my_DPCM_codec.raw";
            MemoryStream ms          = new MemoryStream();

            byte[] buf = new byte[1024];

            var reader = new FileStream(input_path, FileMode.Open);
            int readBytes;

            try
            {
                while ((readBytes = reader.Read(buf, 0, buf.Length)) > 0)
                {
                    ms.Write(buf, 0, readBytes);
                }
            }
            finally
            {
                ms.Flush();
                reader.Close();
            }

            var encoder = new MyDpcmCodec();
            var decoder = new MyDpcmCodec();

            //Utils.saveByteArrayToFile(decoder.Decode(encoder.Encode(ms.ToArray())), output_path);
            Utils.saveByteArrayToFile(decoder.Decode(encoder.Encode(ms.ToArray())), output_path);
        }
Пример #2
0
        // set ffmpegProc field
        private void kickFFMPEG()
        {
            ProcessStartInfo startInfo = new ProcessStartInfo();

            startInfo.UseShellExecute = false; //required to redirect standart input/output

            // redirects on your choice
            startInfo.RedirectStandardOutput = true;
            startInfo.RedirectStandardError  = true;
            startInfo.RedirectStandardInput  = true;
            startInfo.CreateNoWindow         = true;
            startInfo.FileName = ffmpegPath;

            if (GlobalConfiguration.isEncodeWithDpcmOrUseRawPCM)
            {
                startInfo.Arguments = ffmpegForPCMConvertArgs;
                if (GlobalConfiguration.isUseDPCM)
                {
                    dpcm_encoder = new MyDpcmCodec();
                }
            }
            else
            {
                startInfo.Arguments = ffmpegForAudioEncodeArgs;
            }

            //startInfo.Arguments = ffmpegForDirectStreamingArgs;

            ffmpegProc           = new Process();
            ffmpegProc.StartInfo = startInfo;
            // リダイレクトした標準出力・標準エラーの内容を受信するイベントハンドラを設定する
            //ffmpegProc.OutputDataReceived += useFFMPEGOutputData;
            ffmpegProc.ErrorDataReceived += PrintFFMPEGErrorData;

            ffmpegProc.Start();

            // ffmpegが確実に起動状態になるまで待つ
            Thread.Sleep(3000);

            // 標準出力・標準エラーの非同期読み込みを開始する
            //ffmpegProc.BeginOutputReadLine();
            ffmpegProc.BeginErrorReadLine();

            var task = Task.Run(() =>
            {
                byte[] ffmpegStdout_buf = new byte[2048];
                int readedBytes         = 0;
                while (!ffmpegProc.StandardOutput.EndOfStream)
                {
                    readedBytes = ffmpegProc.StandardOutput.BaseStream.Read(ffmpegStdout_buf, 0, ffmpegStdout_buf.Length);
                    //Console.WriteLine(Utils.getFormatedCurrentTime() + " DEBUG: read tabun one frames " + readedBytes.ToString() + " bytes");
                    //debug_ms.Write(ffmpegStdout_buf, 0, readedBytes);
                    //if (debug_ms.Length > 8000 * 120)
                    //{
                    //    Utils.saveByteArrayToFile(debug_ms.ToArray(), "F:\\work\\tmp\\capturedPCM_ffmpeg_stdout_converted_8000Hz_u8bit_1ch_120sec.raw");
                    //    Environment.Exit(0);
                    //}
                    //continue;
                    if (readedBytes > 0)
                    {
                        byte[] tmp_buf = new byte[readedBytes];

                        if (GlobalConfiguration.isUseDPCM)
                        {
                            Console.WriteLine("run dpcm encoding " + readedBytes.ToString() + " bytes");
                            tmp_buf = dpcm_encoder.Encode(tmp_buf);
                        }

                        if (GlobalConfiguration.isRunCapturedSoundDataHndlingWithoutConn == false)
                        {
                            this.cap_streamer._AudioOutputWriter.handleDataWithTCP(tmp_buf);
                        }
                    }
                }
            });
        }