概要
cscの作法、調べてみた。
練習問題、やってみた。
練習問題
動画ファイルの情報を取得する、ffmpegのフロントエンドを書け。
写真
サンプルコード
using System;
using System.Windows.Forms;
using System.Drawing;
using System.Diagnostics;
class form1: Form {
form1() {
Text = "ffmpeg";
ClientSize = new Size(200, 180);
Label label = new Label();
label.Location = new Point(20, 20);
label.Text = "ファイル情報";
label.Font = new Font("Geneva", 20, FontStyle.Regular);
label.BackColor = Color.Azure;
label.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
label.AutoSize = true;
Button btn1 = new Button();
btn1.Location = new Point(50, 100);
btn1.Text = "file";
btn1.Click += btn1_Click;
Controls.AddRange(new Control[] {
label,
btn1
});
}
void btn1_Click(object sender, System.EventArgs e) {
string fileContent = string.Empty;
string filePath = string.Empty;
using (OpenFileDialog openFileDialog = new OpenFileDialog())
{
openFileDialog.InitialDirectory = System.IO.Directory.GetCurrentDirectory();
openFileDialog.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
openFileDialog.FilterIndex = 2;
openFileDialog.RestoreDirectory = true;
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
filePath = openFileDialog.FileName;
//MessageBox.Show(filePath);
Console.WriteLine(filePath);
Process p = new Process();
p.StartInfo.FileName = "ffmpeg.exe";
p.StartInfo.Arguments = "-hide_banner -i " + filePath;
p.StartInfo.RedirectStandardInput = true;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.RedirectStandardError = true;
p.StartInfo.CreateNoWindow = true;
p.StartInfo.UseShellExecute = false;
p.Start();
string line;
line = p.StandardOutput.ReadToEnd();
line = p.StandardError.ReadToEnd();
Console.WriteLine(line);
line = line.Replace("At least one output file must be specified", "");
MessageBox.Show(line);
p.WaitForExit();
//Console.WriteLine("ok1");
}
}
}
[STAThread]
public static void Main() {
Application.Run(new form1());
}
}
以上。