using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
using System.Windows.Forms;
using WMPLib;
namespace Mp4BoxSplitter
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void BOpen_Click(object sender, EventArgs e)
{
if (openFileDialog1.ShowDialog() == System.Windows.Forms.DialogResult.OK)
{
tFileName.Text = openFileDialog1.FileName;
this.axWindowsMediaPlayer1.URL = tFileName.Text;
}
}
private void BStartTime_Click(object sender, EventArgs e)
{
tStartTime.Text = axWindowsMediaPlayer1.Ctlcontrols.currentPosition.ToString("0.##");
}
private void BEndTime_Click(object sender, EventArgs e)
{
tEndTime.Text = axWindowsMediaPlayer1.Ctlcontrols.currentPosition.ToString("0.##");
}
private void BCutSave_Click(object sender2, EventArgs e)
{
axWindowsMediaPlayer1.Ctlcontrols.stop();
//pokličem mp4box.exe s parametri
Process p = new Process();
p.StartInfo.FileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "mp4box", @"mp4box.exe");
string sStartTime = decimal.Parse(tStartTime.Text).ToString("0.##").Replace(",", ".");
string sEndTime = decimal.Parse(tEndTime.Text).ToString("0.##").Replace(",", ".");
string inFileName = tFileName.Text;
string outFileName = inFileName.Substring(0, inFileName.LastIndexOf(".")) + "_" + sStartTime + "-" + sEndTime + inFileName.Substring(inFileName.LastIndexOf("."));
string @params = "-splitx " + sStartTime + ":" + sEndTime + " " + inFileName + " -out " + outFileName;
Debug.WriteLine(p.StartInfo.FileName + " " + @params);
p.StartInfo.Arguments = @params;
var sb = new StringBuilder();
sb.AppendLine("mp4box.exe results:");
// redirect the output
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
// hookup the eventhandlers to capture the data that is received
p.OutputDataReceived += (sender, args) =>
{
if (args.Data != null && !args.Data.StartsWith("Splitting:") && !args.Data.StartsWith("ISO File Writing:"))
{
sb.AppendLine(args.Data);
}
};
p.ErrorDataReceived += (sender, args) =>
{
if (args.Data != null && !args.Data.StartsWith("Splitting:") && !args.Data.StartsWith("ISO File Writing:"))
{
sb.AppendLine(args.Data);
}
};
// direct start
p.StartInfo.UseShellExecute = false;
p.Start();
// start our event pumps
p.BeginOutputReadLine();
p.BeginErrorReadLine();
// until we are done
p.WaitForExit();
tResult.Text = sb.ToString();
}
private void TFileName_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Enter)
{
this.axWindowsMediaPlayer1.URL = tFileName.Text;
}
}
private void TFileName_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
private void TFileName_DragDrop(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
tFileName.Text = files[0];
this.axWindowsMediaPlayer1.URL = tFileName.Text;
}
}
private void BMinus1Sec_Click(object sender, EventArgs e)
{
axWindowsMediaPlayer1.Ctlcontrols.currentPosition -= 1;
axWindowsMediaPlayer1.Refresh();
}
private void BMinus5Sec_Click(object sender, EventArgs e)
{
axWindowsMediaPlayer1.Ctlcontrols.currentPosition -= 5;
axWindowsMediaPlayer1.Refresh();
}
private void BMinus10s_Click(object sender, EventArgs e)
{
axWindowsMediaPlayer1.Ctlcontrols.currentPosition -= 10;
axWindowsMediaPlayer1.Refresh();
}
private void BToStart_Click(object sender, EventArgs e)
{
axWindowsMediaPlayer1.Ctlcontrols.currentPosition = 0;
axWindowsMediaPlayer1.Refresh();
}
private void BPlus1Sec_Click(object sender, EventArgs e)
{
axWindowsMediaPlayer1.Ctlcontrols.currentPosition += 1;
axWindowsMediaPlayer1.Refresh();
}
private void BPlus5Sec_Click(object sender, EventArgs e)
{
axWindowsMediaPlayer1.Ctlcontrols.currentPosition += 5;
axWindowsMediaPlayer1.Refresh();
}
private void BPlus10Sec_Click(object sender, EventArgs e)
{
axWindowsMediaPlayer1.Ctlcontrols.currentPosition += 10;
axWindowsMediaPlayer1.Refresh();
}
private void BToEnd_Click(object sender, EventArgs e)
{
axWindowsMediaPlayer1.Ctlcontrols.currentPosition = axWindowsMediaPlayer1.currentMedia.duration;
axWindowsMediaPlayer1.Refresh();
}
private void BMinusDot5_Click(object sender, EventArgs e)
{
axWindowsMediaPlayer1.Ctlcontrols.currentPosition -= 0.5;
axWindowsMediaPlayer1.Refresh();
}
private void BMinusDot2_Click(object sender, EventArgs e)
{
axWindowsMediaPlayer1.Ctlcontrols.currentPosition -= 0.2;
axWindowsMediaPlayer1.Refresh();
}
private void BPlusDot5_Click(object sender, EventArgs e)
{
axWindowsMediaPlayer1.Ctlcontrols.currentPosition += 0.5;
axWindowsMediaPlayer1.Refresh();
}
private void BPlusDot2_Click(object sender, EventArgs e)
{
axWindowsMediaPlayer1.Ctlcontrols.currentPosition += 0.2;
axWindowsMediaPlayer1.Refresh();
}
private void BPlusFrame_Click(object sender, EventArgs e)
{
((IWMPControls2)axWindowsMediaPlayer1.Ctlcontrols).step(1);
axWindowsMediaPlayer1.Refresh();
}
private void Button1_Click(object sender, EventArgs e)
{
axWindowsMediaPlayer1.Ctlcontrols.pause();
}
private void BPlayPart_Click(object sender, EventArgs e)
{
axWindowsMediaPlayer1.Ctlcontrols.currentPosition = double.Parse(tStartTime.Text);
double dInterval = (double.Parse(tEndTime.Text) - double.Parse(tStartTime.Text)) * 1000;
System.Timers.Timer aTimer = new System.Timers.Timer();
aTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
aTimer.Interval = dInterval;
axWindowsMediaPlayer1.Ctlcontrols.play();
aTimer.Enabled = true;
}
private void OnTimedEvent(object sender, ElapsedEventArgs e)
{
axWindowsMediaPlayer1.Ctlcontrols.pause();
var timer = (System.Timers.Timer)sender;
timer.Dispose();
}
private void BExplore_Click(object sender, EventArgs e)
{
string sFolderPath = Path.GetDirectoryName(tFileName.Text);
ProcessStartInfo startInfo = new ProcessStartInfo
{
Arguments = sFolderPath,
FileName = "explorer.exe"
};
Process.Start(startInfo);
}
}
}
mp4 파일을로드하고 시작 및 종료 시간을 선택한 후 Cut + Save 버튼을 클릭하면 오류가 발생합니다.
private void BCutSave_Click(object sender2, EventArgs e)
{
axWindowsMediaPlayer1.Ctlcontrols.stop();
//pokličem mp4box.exe s parametri
Process p = new Process();
p.StartInfo.FileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "mp4box", @"mp4box.exe");
string sStartTime = decimal.Parse(tStartTime.Text).ToString("0.##").Replace(",", ".");
string sEndTime = decimal.Parse(tEndTime.Text).ToString("0.##").Replace(",", ".");
string inFileName = tFileName.Text;
string outFileName = inFileName.Substring(0, inFileName.LastIndexOf(".")) + "_" + sStartTime + "-" + sEndTime + inFileName.Substring(inFileName.LastIndexOf("."));
string @params = "-splitx " + sStartTime + ":" + sEndTime + " " + inFileName + " -out " + outFileName;
Debug.WriteLine(p.StartInfo.FileName + " " + @params);
p.StartInfo.Arguments = @params;
var sb = new StringBuilder();
sb.AppendLine("mp4box.exe results:");
// redirect the output
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
// hookup the eventhandlers to capture the data that is received
p.OutputDataReceived += (sender, args) =>
{
if (args.Data != null && !args.Data.StartsWith("Splitting:") && !args.Data.StartsWith("ISO File Writing:"))
{
sb.AppendLine(args.Data);
}
};
p.ErrorDataReceived += (sender, args) =>
{
if (args.Data != null && !args.Data.StartsWith("Splitting:") && !args.Data.StartsWith("ISO File Writing:"))
{
sb.AppendLine(args.Data);
}
};
// direct start
p.StartInfo.UseShellExecute = false;
p.Start();
// start our event pumps
p.BeginOutputReadLine();
p.BeginErrorReadLine();
// until we are done
p.WaitForExit();
tResult.Text = sb.ToString();
}
라인에 들어 가지 않습니다.
sb.AppendLine(args.Data);
그러나 줄로 점프합니다.
p.ErrorDataReceived += (sender, args) =>
{
if (args.Data != null && !args.Data.StartsWith("Splitting:") && !args.Data.StartsWith("ISO File Writing:"))
{
sb.AppendLine(args.Data);
}
};
오류는 다음과 같습니다.
mp4box.exe 결과 : 오류-2 개의 입력 이름이 지정되었습니다. 사용법을 확인하십시오.
아마도 당신 tFileName.Text;
은 그 안에 공백이 있고 당신은 같은 명령 줄을 만들고 mp4box.exe -splitx 1:2 C:\program files\some\file.ext -out blah.mp4
mp4box는 당신의 두 입력 파일이 c:\program
및 files\some\file.ext
.
C #에서 다른 명령을 실행할 때 발생하는 문제를 해결하기위한 프로세스는 일반적으로 다음과 같습니다.
var sb = new StringBuilder();
에서의 값을 확인합니다 p.StartInfo.Arguments
."
mp4box가 명령 프롬프트에서 성공적으로 실행되도록 문제를 수정 (예 : 공백이있는 경로 주변에 추가 ) 한 다음 명령 줄에서 수정 한 내용을 코드로 전송합니다. 예 : string @params = $"-splitx {sStartTime}:{sEndTime} \"{inFileName}\" -out \"{outFileName}\"";
추신; 문자열 보간을 사용하십시오. 이런 종류의 연결보다 훨씬 더 읽기 쉽습니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다