Ejemplo n.º 1
0
 private void SetupCurrentStatusProgressBar(FinishedRecord record)
 {
     Application.Current.Dispatcher.Invoke(() =>
     {
         CurrentStatusProgressBar.Minimum = 0;
         CurrentStatusProgressBar.Value   = 0;
         CurrentStatusProgressBar.Maximum = record.TotalChunkCount;
     });
 }
Ejemplo n.º 2
0
        public async Task ConvertProcessWithRecord(FinishedRecord record)
        {
            InsertLog($"{record.ToSimpleString()}의 변환이 시작되었습니다");
            int recordCurrent = 0;

            var basePath = Path.Combine(GlobalStore.RECORD_OUTPUT_FOLDER, record.NickName);

            for (int pulse = 0; pulse < record.PulseCount; pulse++)
            {
                InsertLog($"{record.ToSimpleString()}의 {pulse} 페이즈 변환이 시작되었습니다");
                var pulseCurrent = 0;
                var pulseTotal   = record.GetChunkCountForPulse(pulse);
                UpdateCurrentProcess(pulse, pulseCurrent, pulseTotal, recordCurrent, record.TotalChunkCount);

                var path = Path.Combine(basePath, $"{record.Created}-{pulse}.ts.mp4");

                var ffmpeg = new Process();
                ffmpeg.StartInfo.CreateNoWindow         = true;
                ffmpeg.StartInfo.UseShellExecute        = false;
                ffmpeg.StartInfo.RedirectStandardInput  = true;
                ffmpeg.StartInfo.RedirectStandardError  = true;
                ffmpeg.StartInfo.RedirectStandardOutput = true;
                ffmpeg.StartInfo.FileName  = "ffmpeg";
                ffmpeg.StartInfo.Arguments = $"-y -analyzeduration {1024 * 1024 * 300} -probesize {1024 * 1024 * 300} -i pipe: -c copy \"{path}\"";
                ffmpeg.OutputDataReceived += Ffmpeg_DataReceived;
                ffmpeg.ErrorDataReceived  += Ffmpeg_DataReceived;
                ffmpeg.Start();
                ffmpeg.BeginErrorReadLine();
                ffmpeg.BeginOutputReadLine();

                for (int i = 0; i < pulseTotal; i++)
                {
                    var stream = File.Open(record.GetPathWithPulseAndChunk(pulse, i), FileMode.Open);

                    var buffer = new byte[1024 * 16];
                    while (true)
                    {
                        if (InterceptFlag)
                        {
                            InsertLog("변환 작업의 중단이 감지되었습니다. 현재 작업을 중단하고 있습니다");
                            try
                            {
                                ffmpeg.Kill();
                                ffmpeg.Close();
                                InsertLog("ffmpeg가 강제 중단됨!");
                            }
                            catch (Exception e)
                            {
                                Debug.WriteLine(e.ToString());
                            }
                            try
                            {
                                stream.Close();
                            }
                            catch (Exception e)
                            {
                                Debug.WriteLine(e.ToString());
                            }

                            try
                            {
                                File.Delete(path);
                                InsertLog("변환중이던 파일이 삭제되었습니다!");
                            }
                            catch (Exception e)
                            {
                                Debug.WriteLine(e.ToString());
                            }
                            return;
                        }

                        var readed = await stream.ReadAsync(buffer, 0, buffer.Length);

                        if (readed == 0)
                        {
                            break;
                        }
                        await ffmpeg.StandardInput.BaseStream.WriteAsync(buffer, 0, readed);
                    }
                    pulseCurrent++;
                    recordCurrent++;
                    UpdateCurrentProcess(pulse, pulseCurrent, pulseTotal, recordCurrent, record.TotalChunkCount);
                    OneChunkSent();
                    stream.Close();
                }
                await ffmpeg.StandardInput.BaseStream.FlushAsync();

                ffmpeg.StandardInput.Close();

                ffmpeg.WaitForExit();

                Application.Current.Dispatcher.Invoke(() =>
                {
                    FFMpegResultView.Text = "";
                });

                if (ffmpeg.ExitCode != 0)
                {
                    InsertLog($"{record.ToSimpleString()}의 {pulse}페이즈 변환중 ffmpeg가 ${ffmpeg.ExitCode}를 반환했습니다. 결과물을 확인해주세요! 필요하다면 구글 드라이브에서 복원해야 합니다");
                }
                InsertLog($"{record.ToSimpleString()}의 {pulse}페이즈 변환이 완료되었습니다");
            }

            if (!GlobalStore.READONLY_MODE)
            {
                InsertLog($"{record.ToSimpleString()}의 원본 폴더가 삭제되었습니다");
                var dir = new DirectoryInfo(record.RecordPath);
                dir.Delete(true);
            }
            InsertLog($"{record.ToSimpleString()}의 변환이 종료되었습니다");
        }