티스토리 뷰
반응형
[1분해결] c#에서 ffmpeg 동적으로 사용하기
[설명]
runCommand - process를 활용하여 ffmpeg 스크립트 실행
BackgroundWorker - 비동기화 구현
private void Initialize()
{
bgworker = new BackgroundWorker();
bgworker.DoWork += Bgworker_DoWork;
bgworker.RunWorkerAsync();
bgworker.RunWorkerCompleted += Bgworker_RunWorkerCompleted;
lb.Items.Add("start");
}
private void Bgworker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
process.Close();
if(result != string.Empty)
{
lb.Items.Add("complete");
}else
{
lb.Items.Add("error");
}
}
private void Bgworker_DoWork(object sender, DoWorkEventArgs e)
{
runCommand();
}
void runCommand()
{
Debug.WriteLine("start");
//* Create your Process
process = new Process();
process.StartInfo.FileName = "ffmpeg.exe";
process.StartInfo.Arguments = "-i 2.mp4 -c:a aac -b:a 160k -c:v libx264 -crf 22 -preset veryfast 2-6.mp4";
process.StartInfo.UseShellExecute = false;
process.StartInfo.RedirectStandardOutput = true;
process.StartInfo.RedirectStandardError = true;
//* Set your output and error (asynchronous) handlers
process.OutputDataReceived += new DataReceivedEventHandler(OutputHandler);
process.ErrorDataReceived += new DataReceivedEventHandler(OutputHandler);
//* Start process and handlers
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.WaitForExit();
}
void OutputHandler(object sendingProcess, DataReceivedEventArgs outLine)
{
if (outLine.Data!= null)
{
if (outLine.Data.Contains("Qavg")){
result = outLine.Data;
}
}
}
[tag]
#C# #ffmpeg #process #wpf #동영상 #디코딩 #비동기 #비동기화 #영화 #인코딩
반응형
'c#' 카테고리의 다른 글
[wpf/c#/unity/winform] 변수 이름 가져오기 (0) | 2021.11.25 |
---|---|
[c#/wpf/unity/winform] 고유한(유니크) 아이디 생성 함수 구현 (0) | 2021.11.24 |
[c#/unity/winform/wpf] 문자열 변수 간단히 출력($ 활용) (0) | 2021.11.18 |
[c#/unity/winform/wpf] generic 타입 list인지 확인하기 (0) | 2021.11.17 |
[c#/wpf/unity/winform]byte를 object(class 객체)로 object를 byte로 변환하기 (0) | 2021.11.17 |
댓글
반응형